type-graphql built-in Date scalar - nestjs

Tech: Nestjs, graphql (schema first)
When I make custom scalar named with 'Datetime' and change it to typescript using auto generation, 'export type DateTime = any' is created.
When I make custom scalar named with 'Json' and change it to typescript using auto generation, 'export type Json = any' is created.
But, when I make custom scalar named with 'Date' and change it to typescript using auto generation, there is no 'export type Date = any'.
It acts javascript built-in 'Date' object.
'https://typegraphql.com/docs/scalars.html' <== Docs says they provide built-in Date scalar type, and is this exactly equals with javascript Date object?

Related

create dynamic object in GO operator controller

I am following the below blog which explains how to create operator and import another CR into existing one.
http://heidloff.net/article/accessing-third-party-custom-resources-go-operators/
here https://github.com/nheidloff/operator-sample-go/blob/aa9fd15605a54f712e1233423236bd152940f238/operator-application/controllers/application_controller.go#L276 , spec is created with hardcoded properties.
I want to import the spark operator types in my operator.
https://github.com/GoogleCloudPlatform/spark-on-k8s-operator/blob/master/pkg/apis/sparkoperator.k8s.io/v1beta2/types.go
This spark operator is having say - 100+ types/properties. By following the above blog , i could create the Go object but it would be hardcoded. I want to create the dynamic object based on user provided values in CR YAML. e.g. - customer can provided 25 attributes , sometimes 50 for spark app. I need to have dynamic object created based on user YAML. Can anybody please help me out ?
If you set the spec type to be a json object, you can have the Spec contain arbitrary json/yaml. You don't have to have a strongly typed Spec object, your operator can then decode it and do whatever you want with it during your reconcile operation as long as its you as you can serialize and deserialize it from json. Should be able to set it to json.RawMesage I think?
What do you mean by hardcoded properties?
If I understood it correctly, you want to define an API for a resource which uses both types from an external operator and your customs. You can extend your API using the types from specific properties such as ScheduledSparkApplicationSpec from this. Here is an example API definition in Go:
type MyKindSpec struct {
// using external third party api (you need to import it)
SparkAppTemplate v1beta2.ScheduledSparkApplicationSpec `json:"sparkAppTemplate,omitempty"`
// using kubernetes core api (you need to import it)
Container v1.Container `json:"container,omitempty"`
// using custom types
MyCustomType MyCustomType `json:"myCustomType,omitempty"`
}
type MyCustomType struct {
FirstField string `json:"firstField,omitempty"`
SecondField []int `json:"secondField,omitempty"`
}

Custom data type in Prisma

How to create my own data type in Prisma?
I want to create data type to store TIME WITH TIMEZONE in PostgreSQL.
You can use DateTime data type and in an attribute can define to use native PostgreSQL time with timezone type.
Here's how you can define it in schema file
model Time {
time DateTime #db.Timetz(6)
}
Here's a reference for using native database types in docs.

Is there way to create TRUE custom type in Godot?

I'm trying to create a custom type for my Player Controller.
First I went with "script classes":
extends Node
class_name PlayerController
export var max_speed = 32
export var id = 1
export(NodePath) var node_path
onready var node = get_node(node_path)
...
But then I realized, and was not quite satisfied with the way that properties are displayed:
I'd expected it to be in the "PlayerController" dedicated section as it with node, so it will be possible to inherit and see the nice stack of properties there.
I thought that it is due to the "script classes" being a simplified comparing to regular extensions. So I created one.
tool
extends EditorPlugin
func _enter_tree():
add_custom_type("PlayerController", "Node", preload("PlayerController.gd"),preload("PlayerController.svg"))
func _exit_tree():
pass
The result was literally the same.
What I figured out is that "custom type" created in this way is not a "custom type" but just a Parent type with script attached to it. It can be confirmed in the docs:
void add_custom_type(type: String, base: String, script: Script, icon: Texture)
Adds a custom type, which will appear in the list of nodes or resources. An icon can be optionally passed.
When given node or resource is selected, the base type will be instanced (ie, "Spatial", "Control", "Resource"), then the script will be loaded and set to this object.
You can use the virtual method handles() to check if your custom object is being edited by checking the script or using the is keyword.
During run-time, this will be a simple object with a script so this function does not need to be called then.
My question is:
It is possible to create a true custom type?
Adding a category in the inspector panel
First of all, if what you want is a dedicated section in the inspector panel, you can do that with a tool (see Running code in the editor) script and _get_property_list.
This is an example based on another answer:
tool
extends Node
export var something_else:String
var custom_position:Vector2
var custom_rotation_degrees:float
var custom_scale:Vector2
func _get_property_list():
return [
{
name = "Custom",
type = TYPE_NIL,
hint_string = "custom_",
usage = PROPERTY_USAGE_CATEGORY
},
{
name = "custom_position",
type = TYPE_VECTOR2
},
{
name = "custom_rotation_degrees",
type = TYPE_REAL
},
{
name = "custom_scale",
type = TYPE_VECTOR2
}
]
There I'm creating a category called "Custom". Notice that type is TYPE_NIL and usage is PROPERTY_USAGE_CATEGORY. Which is how the documentation does it. See Adding script categories.
Using PROPERTY_USAGE_CATEGORY will produce a named header, similar to the one that says "Node" on the picture on the question. Use PROPERTY_USAGE_GROUP to make a collapsible group.
The value of hint_string will be used as a prefix. Any property with that prefix will be in that category. Such as the ones you see in the code, each with their respective types. These are all declared with var in my code. However, not with export because then they would appear twice.
And it looks as follows:
Adding a custom type
When we create a a class in a script, it is a type. A GDScript type. For evidence that they are GDScript types. Notice that when using class_name you can declare variables of that type, check if a value is of the type with the is operator. And that you can use extends with them.
There are also core types. Which are also GDScript types. So you can also use declare variable of the type, use extend with them and check for them with is.
However, the classes we create in a script are not core types. We cannot really create a core type from GDScript or any other script language. All we can do is add a script to an existing core type.
If you want to create actual core types, you need to use C++ and create a Godot Module.
You may also be interested in GDExtension in the upcoming Godot 4.0.

how to check if a variable is Firestore Document Data type?

I am using Typescript and NodeJS for my Google Cloud Function
if I get a document from firestore like this
const result = await db.doc(`events/${eventID}`).get();
const myData = result.data();
then the type of myData is FirebaseFirestore.DocumentData like this
in other part of my code,
I need to check, if a variable has the type of FirebaseFirestore.DocumentData or not using the code below
if ( myVariable instanceof FirebaseFirestore.DocumentData ) {
// do something
}
but I have an error like this
Property 'DocumentData' does not exist on type 'typeof
FirebaseFirestore'
so how to check if my variable is a type of Firestore Document Data?
I see this answer , and it needs to import something so I can access it. how to do something like that for FirebaseFirestore.DocumentData ?
As with your other question you are mixing up Typescript types and JavaScript objects.
FirebaseFirestore.DocumentData refers to a type that is used by the TypeScript compiler as a compile time check. TypeScript compiles down to JavaScript and JavaScript doesn't know about those types during runtime. So the only way to check if the returned data is the Document Data you have to check for the existence of fields or check for undefined.

How to auto-generate early bound properties for Entity specific (ie Local) Option Set text values?

After spending a year working with the Microsoft.Xrm.Sdk namespace, I just discovered yesterday the Entity.FormattedValues property contains the text value for Entity specific (ie Local) Option Set texts.
The reason I didn't discover it before, is there is no early bound method of getting the value. i.e. entity.new_myOptionSet is of type OptionSetValue which only contains the int value. You have to call entity.FormattedValues["new_myoptionset"] to get the string text value of the OptionSetValue.
Therefore, I'd like to get the crmsrvcutil to auto-generate a text property for local option sets. i.e. Along with Entity.new_myOptionSet being generated as it currently does, Entity.new_myOptionSetText would be generated as well.
I've looked into the Microsoft.Crm.Services.Utility.ICodeGenerationService, but that looks like it is mostly for specifying what CodeGenerationType something should be...
Is there a way supported way using CrmServiceUtil to add these properties, or am I better off writing a custom app that I can run that can generate these properties as a partial class to the auto-generated ones?
Edit - Example of the code that I would like to be generated
Currently, whenever I need to access the text value of a OptionSetValue, I use this code:
var textValue = OptionSetCache.GetText(service, entity, e => e.New_MyOptionSet);
The option set cache will use the entity.LogicalName, and the property expression to determine the name of the option set that I'm asking for. It will then query the SDK using the RetrieveAttriubteRequest, to get a list of the option set int and text values, which it then caches so it doesn't have to hit CRM again. It then looks up the int value of the New_MyOptionSet of the entity and cross references it with the cached list, to get the text value of the OptionSet.
Instead of doing all of that, I can just do this (assuming that the entity has been retrieved from the server, and not just populated client side):
var textValue = entity.FormattedValues["new_myoptionset"];
but the "new_myoptionset" is no longer early bound. I would like the early bound entity classes that gets generated to also generate an extra "Text" property for OptionSetValue properties that calls the above line, so my entity would have this added to it:
public string New_MyOptionSetText {
return this.GetFormattedAttributeValue("new_myoptionset"); // this is a protected method on the Entity class itself...
}
Could you utilize the CrmServiceUtil extension that will generate enums for your OptionSets and then add your new_myOptionSetText property to a partial class that compares the int value to the enums and returns the enum string
Again, I think specifically for this case, getting CrmSvcUtil.exe to generate the code you want is a great idea, but more generally, you can access the property name via reflection using an approach similar to the accepted answer # workarounds for nameof() operator in C#: typesafe databinding.
var textValue = entity.FormattedValues["new_myoptionset"];
// becomes
var textValue = entity.FormattedValues
[
// renamed the class from Nameof to NameOf
NameOf(Xrm.MyEntity).Property(x => x.new_MyOptionSet).ToLower()
];
The latest version of the CRM Early Bound Generator includes a Fields struct that that contains the field names. This allows accessing the FormattedValues to be as simple as this:
var textValue = entity.FormattedValues[MyEntity.Fields.new_MyOptionSet];
You could create a new property via an interface for the CrmSvcUtil, but that's a lot of work for a fairly simple call, and I don't think it justifies creating additional properties.

Resources