Skip to content

Commit

Permalink
feat: add support for custom attribute types (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffMathy authored Nov 24, 2023
1 parent 32b2217 commit 5a168d2
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 12 deletions.
90 changes: 90 additions & 0 deletions source/__snapshots__/default-custom-attributes.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// :copyright: Copyright (c) 2023 ftrack

// Generated on 2023-01-31T23:00:00.000Z using schema
// from an instance running version 4.13.8 using server on https://ftrack.example.com
// Not intended to modify manually

export interface TypedContext<
K extends TypedContextSubtype = TypedContextSubtype
> {
__entity_type__?: K;
__permissions?: Record<string, any>;
}
export interface BasicLink {
id: string;
type: string;
name: string;
}
export interface EntityTypeMap {
TypedContext: TypedContext;
}
export type EntityType = keyof EntityTypeMap;
export type EntityData<TEntityType extends EntityType = EntityType> =
EntityTypeMap[TEntityType];
export interface TypedContextSubtypeMap {
TypedContext: TypedContext;
}
export type TypedContextSubtype = keyof TypedContextSubtypeMap;
export function getAttributeConfigurations() {
return [
{
name: "fend",
label: "Frame end",
entityType: "task",
objectType: "Shot",
isHierarchical: false,
},
{
name: "handles",
label: "Frame handles",
entityType: "task",
objectType: "Shot",
isHierarchical: false,
},
{
name: "duration",
label: "Frame duration",
entityType: "task",
objectType: "Shot",
isHierarchical: false,
},
{
name: "fstart",
label: "Frame start",
entityType: "task",
objectType: "Shot",
isHierarchical: false,
},
{
name: "fps",
label: "fps",
entityType: "show",
objectType: undefined,
isHierarchical: false,
},
{
name: "fps",
label: "fps",
entityType: "task",
objectType: "Sequence",
isHierarchical: false,
},
{
name: "fps",
label: "fps",
entityType: "task",
objectType: "Shot",
isHierarchical: false,
},
] as const;
}

export type CustomAttributeConfiguration = ReturnType<
typeof getAttributeConfigurations
>[number];
export type CustomAttributeConfigurationName =
CustomAttributeConfiguration["name"];
export type CustomAttributeConfigurationLabel =
CustomAttributeConfiguration["label"];

// Errors:
13 changes: 12 additions & 1 deletion source/__snapshots__/default-ftrack-schema.snap
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ export interface UserView {
name?: string;
shared_with?: Resource[];
user?: User;
user_id?: undefined;
user_id?: string;
__entity_type__?: "UserView";
__permissions?: Record<string, any>;
}
Expand Down Expand Up @@ -1422,5 +1422,16 @@ export interface TypedContextSubtypeMap {
Information: Information;
}
export type TypedContextSubtype = keyof TypedContextSubtypeMap;
export function getAttributeConfigurations() {
return [] as const;
}

export type CustomAttributeConfiguration = ReturnType<
typeof getAttributeConfigurations
>[number];
export type CustomAttributeConfigurationName =
CustomAttributeConfiguration["name"];
export type CustomAttributeConfigurationLabel =
CustomAttributeConfiguration["label"];

// Errors:
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
[
{
"__entity_type__": "CustomAttributeConfiguration",
"id": "432bc746-4087-11e2-8250-0019bb4983d8",
"object_type": {
"__entity_type__": "ObjectType",
"id": "bad911de-3bd6-47b9-8b46-3476e237cb36",
"name": "Shot"
},
"key": "fend",
"entity_type": "task",
"label": "Frame end",
"project_id": null,
"default": 1,
"is_hierarchical": false,
"values": []
},
{
"__entity_type__": "CustomAttributeConfiguration",
"id": "432bdfa6-4087-11e2-8250-0019bb4983d8",
"object_type": {
"__entity_type__": "ObjectType",
"id": "bad911de-3bd6-47b9-8b46-3476e237cb36",
"name": "Shot"
},
"key": "handles",
"entity_type": "task",
"label": "Frame handles",
"project_id": null,
"default": 0,
"is_hierarchical": false,
"values": []
},
{
"__entity_type__": "CustomAttributeConfiguration",
"id": "928887a8-645f-4909-a7d0-d1661cacd178",
"object_type": {
"__entity_type__": "ObjectType",
"id": "bad911de-3bd6-47b9-8b46-3476e237cb36",
"name": "Shot"
},
"key": "duration",
"entity_type": "task",
"label": "Frame duration",
"project_id": null,
"default": "{self.fend - self.fstart + 1}",
"is_hierarchical": false,
"values": []
},
{
"__entity_type__": "CustomAttributeConfiguration",
"id": "acd86546-4082-11e2-95b1-0019bb4983d8",
"object_type": {
"__entity_type__": "ObjectType",
"id": "bad911de-3bd6-47b9-8b46-3476e237cb36",
"name": "Shot"
},
"key": "fstart",
"entity_type": "task",
"label": "Frame start",
"project_id": null,
"default": 1,
"is_hierarchical": false,
"values": []
},
{
"__entity_type__": "CustomAttributeConfiguration",
"id": "d25219d6-acb5-11e1-8668-f23c91df1211",
"object_type": null,
"key": "fps",
"entity_type": "show",
"label": "fps",
"project_id": null,
"default": 24,
"is_hierarchical": false,
"values": []
},
{
"__entity_type__": "CustomAttributeConfiguration",
"id": "d25532e2-acb5-11e1-8668-f23c91df1211",
"object_type": {
"__entity_type__": "ObjectType",
"id": "e5139355-61da-4c8f-9db4-3abc870166bc",
"name": "Sequence"
},
"key": "fps",
"entity_type": "task",
"label": "fps",
"project_id": null,
"default": 25,
"is_hierarchical": false,
"values": []
},
{
"__entity_type__": "CustomAttributeConfiguration",
"id": "d25907a0-acb5-11e1-8668-f23c91df1211",
"object_type": {
"__entity_type__": "ObjectType",
"id": "bad911de-3bd6-47b9-8b46-3476e237cb36",
"name": "Shot"
},
"key": "fps",
"entity_type": "task",
"label": "fps",
"project_id": null,
"default": 25,
"is_hierarchical": false,
"values": []
}
]
11 changes: 11 additions & 0 deletions source/__snapshots__/schema-has-array-type.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,16 @@ export interface TypedContextSubtypeMap {
TypedContext: TypedContext;
}
export type TypedContextSubtype = keyof TypedContextSubtypeMap;
export function getAttributeConfigurations() {
return [] as const;
}

export type CustomAttributeConfiguration = ReturnType<
typeof getAttributeConfigurations
>[number];
export type CustomAttributeConfigurationName =
CustomAttributeConfiguration["name"];
export type CustomAttributeConfigurationLabel =
CustomAttributeConfiguration["label"];

// Errors:
11 changes: 11 additions & 0 deletions source/__snapshots__/schema-has-base-schema.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,16 @@ export interface TypedContextSubtypeMap {
TypedContext: TypedContext;
}
export type TypedContextSubtype = keyof TypedContextSubtypeMap;
export function getAttributeConfigurations() {
return [] as const;
}

export type CustomAttributeConfiguration = ReturnType<
typeof getAttributeConfigurations
>[number];
export type CustomAttributeConfigurationName =
CustomAttributeConfiguration["name"];
export type CustomAttributeConfigurationLabel =
CustomAttributeConfiguration["label"];

// Errors:
11 changes: 11 additions & 0 deletions source/__snapshots__/schema-has-immutable-property.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,16 @@ export interface TypedContextSubtypeMap {
TypedContext: TypedContext;
}
export type TypedContextSubtype = keyof TypedContextSubtypeMap;
export function getAttributeConfigurations() {
return [] as const;
}

export type CustomAttributeConfiguration = ReturnType<
typeof getAttributeConfigurations
>[number];
export type CustomAttributeConfigurationName =
CustomAttributeConfiguration["name"];
export type CustomAttributeConfigurationLabel =
CustomAttributeConfiguration["label"];

// Errors:
11 changes: 11 additions & 0 deletions source/__snapshots__/schema-has-integer-type.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,16 @@ export interface TypedContextSubtypeMap {
TypedContext: TypedContext;
}
export type TypedContextSubtype = keyof TypedContextSubtypeMap;
export function getAttributeConfigurations() {
return [] as const;
}

export type CustomAttributeConfiguration = ReturnType<
typeof getAttributeConfigurations
>[number];
export type CustomAttributeConfigurationName =
CustomAttributeConfiguration["name"];
export type CustomAttributeConfigurationLabel =
CustomAttributeConfiguration["label"];

// Errors:
11 changes: 11 additions & 0 deletions source/__snapshots__/schema-has-variable-type.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,16 @@ export interface TypedContextSubtypeMap {
TypedContext: TypedContext;
}
export type TypedContextSubtype = keyof TypedContextSubtypeMap;
export function getAttributeConfigurations() {
return [] as const;
}

export type CustomAttributeConfiguration = ReturnType<
typeof getAttributeConfigurations
>[number];
export type CustomAttributeConfigurationName =
CustomAttributeConfiguration["name"];
export type CustomAttributeConfigurationLabel =
CustomAttributeConfiguration["label"];

// Errors:
11 changes: 11 additions & 0 deletions source/__snapshots__/schema-subtype-of-TypedContext.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,16 @@ export interface TypedContextSubtypeMap {
SomeInterfaceName: SomeInterfaceName;
}
export type TypedContextSubtype = keyof TypedContextSubtypeMap;
export function getAttributeConfigurations() {
return [] as const;
}

export type CustomAttributeConfiguration = ReturnType<
typeof getAttributeConfigurations
>[number];
export type CustomAttributeConfigurationName =
CustomAttributeConfiguration["name"];
export type CustomAttributeConfigurationLabel =
CustomAttributeConfiguration["label"];

// Errors:
2 changes: 1 addition & 1 deletion source/convertSchemaToInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function convertPropertiesToTypes(
// If neither type or $ref is defined, we can't generate a type. Log an error
if (!("type" in value) && !("$ref" in value)) {
errors.push(
`No type or $ref defined for property ${key} in schema ${schema.id}`,
`No type or $ref defined for property ${key} in schema ${schema.id}`
);
}

Expand Down
Loading

0 comments on commit 5a168d2

Please sign in to comment.