Skip to content

feat: strong-type type and object_type names #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
470 changes: 236 additions & 234 deletions source/__snapshots__/default-highway-test.snap

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions source/__snapshots__/schema-has-array-type.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
// Generated on 2023-02-01T00: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 TypedContextForSubtype<K extends TypedContextSubtype> {
__entity_type__?: K;
__permissions?: Record<string, any>;
}
export interface SomeInterfaceName {
arrayProperty?: ArrayItem[];
mappedArrayProperty?: ArrayItem[];
__entity_type__?: "SomeInterfaceName";
__permissions?: Record<string, any>;
arrayProperty?: ArrayItem[];
mappedArrayProperty?: ArrayItem[];
}
export interface ArrayItem {
__entity_type__?: "ArrayItem";
Expand Down Expand Up @@ -77,13 +76,22 @@ export function getTypes() {
export type RuntimeType = ReturnType<typeof getTypes>[number];
export type RuntimeTypeName = RuntimeType["name"];

interface TypeFor<T extends TypedContextSubtype> extends Omit<Type, "name"> {
name: T;
}

export function getObjectTypes() {
return [] as const;
}

export type RuntimeObjectType = ReturnType<typeof getObjectTypes>[number];
export type RuntimeObjectTypeName = RuntimeObjectType["name"];

interface ObjectTypeFor<T extends TypedContextSubtype>
extends Omit<ObjectType, "name"> {
name: T;
}

export function getProjectSchemas() {
return [] as const;
}
Expand Down
10 changes: 9 additions & 1 deletion source/__snapshots__/schema-has-base-schema.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Generated on 2023-02-01T00: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 TypedContextForSubtype<K extends TypedContextSubtype> {
__entity_type__?: K;
__permissions?: Record<string, any>;
Expand Down Expand Up @@ -76,13 +75,22 @@ export function getTypes() {
export type RuntimeType = ReturnType<typeof getTypes>[number];
export type RuntimeTypeName = RuntimeType["name"];

interface TypeFor<T extends TypedContextSubtype> extends Omit<Type, "name"> {
name: T;
}

export function getObjectTypes() {
return [] as const;
}

export type RuntimeObjectType = ReturnType<typeof getObjectTypes>[number];
export type RuntimeObjectTypeName = RuntimeObjectType["name"];

interface ObjectTypeFor<T extends TypedContextSubtype>
extends Omit<ObjectType, "name"> {
name: T;
}

export function getProjectSchemas() {
return [] as const;
}
Expand Down
12 changes: 10 additions & 2 deletions source/__snapshots__/schema-has-immutable-property.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
// Generated on 2023-02-01T00: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 TypedContextForSubtype<K extends TypedContextSubtype> {
__entity_type__?: K;
__permissions?: Record<string, any>;
}
export interface SomeInterfaceName {
readonly immutableProperty?: string | number | boolean | string[];
__entity_type__?: "SomeInterfaceName";
__permissions?: Record<string, any>;
readonly immutableProperty?: string | number | boolean | string[];
}
export interface BasicLink {
id: string;
Expand Down Expand Up @@ -70,13 +69,22 @@ export function getTypes() {
export type RuntimeType = ReturnType<typeof getTypes>[number];
export type RuntimeTypeName = RuntimeType["name"];

interface TypeFor<T extends TypedContextSubtype> extends Omit<Type, "name"> {
name: T;
}

export function getObjectTypes() {
return [] as const;
}

export type RuntimeObjectType = ReturnType<typeof getObjectTypes>[number];
export type RuntimeObjectTypeName = RuntimeObjectType["name"];

interface ObjectTypeFor<T extends TypedContextSubtype>
extends Omit<ObjectType, "name"> {
name: T;
}

export function getProjectSchemas() {
return [] as const;
}
Expand Down
12 changes: 10 additions & 2 deletions source/__snapshots__/schema-has-integer-type.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
// Generated on 2023-02-01T00: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 TypedContextForSubtype<K extends TypedContextSubtype> {
__entity_type__?: K;
__permissions?: Record<string, any>;
}
export interface SomeInterfaceName {
integerProperty?: number;
__entity_type__?: "SomeInterfaceName";
__permissions?: Record<string, any>;
integerProperty?: number;
}
export interface BasicLink {
id: string;
Expand Down Expand Up @@ -70,13 +69,22 @@ export function getTypes() {
export type RuntimeType = ReturnType<typeof getTypes>[number];
export type RuntimeTypeName = RuntimeType["name"];

interface TypeFor<T extends TypedContextSubtype> extends Omit<Type, "name"> {
name: T;
}

export function getObjectTypes() {
return [] as const;
}

export type RuntimeObjectType = ReturnType<typeof getObjectTypes>[number];
export type RuntimeObjectTypeName = RuntimeObjectType["name"];

interface ObjectTypeFor<T extends TypedContextSubtype>
extends Omit<ObjectType, "name"> {
name: T;
}

export function getProjectSchemas() {
return [] as const;
}
Expand Down
12 changes: 10 additions & 2 deletions source/__snapshots__/schema-has-variable-type.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
// Generated on 2023-02-01T00: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 TypedContextForSubtype<K extends TypedContextSubtype> {
__entity_type__?: K;
__permissions?: Record<string, any>;
}
export interface SomeInterfaceName {
integerProperty?: string | number | boolean | string[];
__entity_type__?: "SomeInterfaceName";
__permissions?: Record<string, any>;
integerProperty?: string | number | boolean | string[];
}
export interface BasicLink {
id: string;
Expand Down Expand Up @@ -70,13 +69,22 @@ export function getTypes() {
export type RuntimeType = ReturnType<typeof getTypes>[number];
export type RuntimeTypeName = RuntimeType["name"];

interface TypeFor<T extends TypedContextSubtype> extends Omit<Type, "name"> {
name: T;
}

export function getObjectTypes() {
return [] as const;
}

export type RuntimeObjectType = ReturnType<typeof getObjectTypes>[number];
export type RuntimeObjectTypeName = RuntimeObjectType["name"];

interface ObjectTypeFor<T extends TypedContextSubtype>
extends Omit<ObjectType, "name"> {
name: T;
}

export function getProjectSchemas() {
return [] as const;
}
Expand Down
10 changes: 9 additions & 1 deletion source/__snapshots__/schema-subtype-of-TypedContext.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Generated on 2023-02-01T00: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 TypedContextForSubtype<K extends TypedContextSubtype> {
__entity_type__?: K;
__permissions?: Record<string, any>;
Expand Down Expand Up @@ -69,13 +68,22 @@ export function getTypes() {
export type RuntimeType = ReturnType<typeof getTypes>[number];
export type RuntimeTypeName = RuntimeType["name"];

interface TypeFor<T extends TypedContextSubtype> extends Omit<Type, "name"> {
name: T;
}

export function getObjectTypes() {
return [] as const;
}

export type RuntimeObjectType = ReturnType<typeof getObjectTypes>[number];
export type RuntimeObjectTypeName = RuntimeObjectType["name"];

interface ObjectTypeFor<T extends TypedContextSubtype>
extends Omit<ObjectType, "name"> {
name: T;
}

export function getProjectSchemas() {
return [] as const;
}
Expand Down
26 changes: 17 additions & 9 deletions source/emit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export async function emitToString(
}

const emitter = new TypeScriptEmitter();
emitter.appendCode(`
emitter.appendBlock(`
// :copyright: Copyright (c) ${new Date().getFullYear()} ftrack
// Generated on ${new Date().toISOString()} using schema
// from an instance running version ${serverVersion} using server on ${serverUrl}
Expand All @@ -148,7 +148,7 @@ export async function emitToString(
BasicLink needs to be added explicitly, as it is not returned by the API.
Task: 95e02be2-c7ec-11ed-ae64-46416ff77027
*/
emitter.appendCode(`
emitter.appendBlock(`
export interface BasicLink {
id: string;
type: string;
Expand All @@ -157,7 +157,7 @@ export async function emitToString(
`);

// Add a map of entity types and type for EntityType and a type for EntityData
emitter.appendCode(`
emitter.appendBlock(`
export interface EntityTypeMap {
${schemas
.map((s) => s.id)
Expand All @@ -174,7 +174,7 @@ export async function emitToString(

emitCustomAttributes(emitter, schemas, customAttributes);

emitter.appendCode(`
emitter.appendBlock(`
export function getTypes() {
return [
${types.map(
Expand All @@ -188,9 +188,13 @@ export async function emitToString(

export type RuntimeType = ReturnType<typeof getTypes>[number];
export type RuntimeTypeName = RuntimeType["name"];

interface TypeFor<T extends TypedContextSubtype> extends Omit<Type, "name"> {
name: T;
};
`);

emitter.appendCode(`
emitter.appendBlock(`
export function getObjectTypes() {
return [
${objectTypes.map(
Expand All @@ -210,9 +214,13 @@ export async function emitToString(

export type RuntimeObjectType = ReturnType<typeof getObjectTypes>[number];
export type RuntimeObjectTypeName = RuntimeObjectType["name"];

interface ObjectTypeFor<T extends TypedContextSubtype> extends Omit<ObjectType, "name"> {
name: T;
};
`);

emitter.appendCode(`
emitter.appendBlock(`
export function getProjectSchemas() {
return [
${projectSchemas.map(
Expand All @@ -233,7 +241,7 @@ export async function emitToString(
export type RuntimeProjectSchemaName = RuntimeProjectSchema["name"];
`);

emitter.appendCode(`
emitter.appendBlock(`
export function getPriorities() {
return [
${priorities.map(
Expand All @@ -251,7 +259,7 @@ export async function emitToString(
export type RuntimePriorityName = RuntimePriority["name"];
`);

emitter.appendCode(`
emitter.appendBlock(`
export function getStatuses() {
return [
${statuses.map(
Expand Down Expand Up @@ -331,7 +339,7 @@ function emitTypedContextTypes(
builder: TypeScriptEmitter,
schemas: QuerySchemasResponse
) {
builder.appendCode(`
builder.appendBlock(`
export interface TypedContextSubtypeMap {
${schemas
.filter(
Expand Down
2 changes: 1 addition & 1 deletion source/emitCustomAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function emitCustomAttributes(
schemas: QuerySchemasResponse,
customAttributes: CustomAttributeConfiguration[]
) {
typescriptEmitter.appendCode(`
typescriptEmitter.appendBlock(`
export function getAttributeConfigurations() {
return [
${customAttributes.map(
Expand Down
Loading