Skip to content

Commit 1901cdf

Browse files
authored
chore(deps): upgrade @ftrack/api + make it runnable without esbuild (#51)
1 parent 6f21de9 commit 1901cdf

File tree

9 files changed

+115
-97
lines changed

9 files changed

+115
-97
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"prepublish": "yarn test"
1717
},
1818
"dependencies": {
19-
"@ftrack/api": "^1.4.5",
19+
"@ftrack/api": "^1.11.3-rc.1",
2020
"prettier": "^3.5.3"
2121
},
2222
"files": [
@@ -33,7 +33,6 @@
3333
"devDependencies": {
3434
"@eslint/js": "^9.22.0",
3535
"@types/node": "^22.13.10",
36-
"@types/ws": "^8.18.0",
3736
"@typescript-eslint/utils": "^8.26.1",
3837
"@vitest/eslint-plugin": "^1.1.37",
3938
"esbuild": "^0.25.1",

source/emit.test.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ import {
66
type Status,
77
type Type,
88
emitToString,
9-
} from "./emit";
10-
import type { QuerySchemasResponse, Schema } from "@ftrack/api";
9+
} from "./emit.ts";
10+
import type { Schema as ApiSchema } from "./session.ts";
11+
import { type QuerySchemasResponse, type Schema } from "@ftrack/api";
1112
import { readFile } from "fs/promises";
1213
import { join } from "path";
13-
import type { CustomAttributeConfiguration } from "./emitCustomAttributes";
14+
import type { CustomAttributeConfiguration } from "./emitCustomAttributes.ts";
15+
16+
vi.mock("@ftrack/api", (importOriginal) => {
17+
return {
18+
...importOriginal,
19+
Session: class Session {},
20+
};
21+
});
1422

1523
beforeEach(() => {
1624
vi.setSystemTime(new Date(2023, 1, 1, 0, 0, 0));
@@ -50,7 +58,7 @@ test("schema subtype of TypedContext", async () => {
5058
const emitResult = await emitToString(
5159
"4.13.8",
5260
"https://ftrack.example.com",
53-
schemas as QuerySchemasResponse,
61+
schemas as QuerySchemasResponse<ApiSchema>,
5462
[],
5563
[],
5664
[],
@@ -84,7 +92,7 @@ test("schema has base schema", async () => {
8492
const emitResult = await emitToString(
8593
"4.13.8",
8694
"https://ftrack.example.com",
87-
schemas as QuerySchemasResponse,
95+
schemas as QuerySchemasResponse<ApiSchema>,
8896
[],
8997
[],
9098
[],
@@ -119,7 +127,7 @@ test("schema has immutable property", async () => {
119127
const emitResult = await emitToString(
120128
"4.13.8",
121129
"https://ftrack.example.com",
122-
schemas as QuerySchemasResponse,
130+
schemas as QuerySchemasResponse<ApiSchema>,
123131
[],
124132
[],
125133
[],
@@ -153,7 +161,7 @@ test("schema has integer type", async () => {
153161
const emitResult = await emitToString(
154162
"4.13.8",
155163
"https://ftrack.example.com",
156-
schemas as QuerySchemasResponse,
164+
schemas as QuerySchemasResponse<ApiSchema>,
157165
[],
158166
[],
159167
[],
@@ -187,7 +195,7 @@ test("schema has variable type", async () => {
187195
const emitResult = await emitToString(
188196
"4.13.8",
189197
"https://ftrack.example.com",
190-
schemas as QuerySchemasResponse,
198+
schemas as QuerySchemasResponse<ApiSchema>,
191199
[],
192200
[],
193201
[],
@@ -234,7 +242,7 @@ test("schema has array type", async () => {
234242
const emitResult = await emitToString(
235243
"4.13.8",
236244
"https://ftrack.example.com",
237-
schemas as QuerySchemasResponse,
245+
schemas as QuerySchemasResponse<ApiSchema>,
238246
[],
239247
[],
240248
[],
@@ -262,7 +270,7 @@ test("default highway test (all values specified)", async () => {
262270
),
263271
);
264272

265-
const schemas = await parseJsonFromFile<Schema[]>(
273+
const schemas = await parseJsonFromFile<QuerySchemasResponse<ApiSchema>>(
266274
join(".", "source", "__snapshots__", "responses", "query_schemas.json"),
267275
);
268276

source/emit.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import type { QuerySchemasResponse, Session } from "@ftrack/api";
1+
import type { QuerySchemasResponse } from "@ftrack/api";
22
import * as fs from "fs";
33
import * as path from "path";
44
import {
55
type CustomAttributeConfiguration,
66
emitCustomAttributes,
7-
} from "./emitCustomAttributes.js";
8-
import { emitSchemaInterface } from "./emitSchema.js";
9-
import { TypeScriptEmitter } from "./typescriptEmitter.js";
10-
import { isSchemaTypedContext } from "./utils.js";
7+
} from "./emitCustomAttributes.ts";
8+
import { emitSchemaInterface } from "./emitSchema.ts";
9+
import { TypeScriptEmitter } from "./typescriptEmitter.ts";
10+
import { isSchemaTypedContext } from "./utils.ts";
11+
import { session, type Schema } from "./session.ts";
1112

1213
const legacySchemas = ["Conversation", "Message", "Participant"];
1314
export async function emitToFile(
14-
session: Session,
1515
outputPath = "__generated__",
1616
outputFilename = "schema.ts",
1717
) {
1818
// Get the schemas from the server and sort by id in alphabetical order
19-
const schemas = await getSchemas(session);
20-
const customAttributes = await getCustomAttributes(session);
21-
const types = await getTypes(session);
22-
const objectTypes = await getObjectTypes(session);
23-
const projectSchemas = await getProjectSchemas(session);
24-
const statuses = await getStatuses(session);
25-
const priorities = await getPriorities(session);
19+
const schemas = await getSchemas();
20+
const customAttributes = await getCustomAttributes();
21+
const types = await getTypes();
22+
const objectTypes = await getObjectTypes();
23+
const projectSchemas = await getProjectSchemas();
24+
const statuses = await getStatuses();
25+
const priorities = await getPriorities();
2626

2727
const { prettifiedContent, errors } = await emitToString(
2828
session.serverVersion,
@@ -109,7 +109,7 @@ export type Status = {
109109
export async function emitToString(
110110
serverVersion: string | undefined,
111111
serverUrl: string | undefined,
112-
schemas: QuerySchemasResponse,
112+
schemas: QuerySchemasResponse<Schema>,
113113
customAttributes: CustomAttributeConfiguration[],
114114
types: Type[],
115115
objectTypes: ObjectType[],
@@ -275,15 +275,15 @@ export async function emitToString(
275275
};
276276
}
277277

278-
async function getCustomAttributes(session: Session) {
279-
const customAttributes = await session.query<CustomAttributeConfiguration>(
278+
async function getCustomAttributes() {
279+
const customAttributes = await session.query<"CustomAttributeConfiguration">(
280280
"select default, label, key, project_id, entity_type, is_hierarchical, object_type.name, type.name from CustomAttributeConfiguration order by sort",
281281
);
282282
return customAttributes.data;
283283
}
284284

285-
async function getSchemas(session: Session) {
286-
const schemas = await session.call<QuerySchemasResponse>([
285+
async function getSchemas() {
286+
const schemas = await session.call<QuerySchemasResponse<Schema>>([
287287
{
288288
action: "query_schemas",
289289
},
@@ -292,44 +292,44 @@ async function getSchemas(session: Session) {
292292
return schemas[0];
293293
}
294294

295-
async function getTypes(session: Session) {
296-
const types = await session.query<Type>(
295+
async function getTypes() {
296+
const types = await session.query<"Type">(
297297
"select is_billable, name, task_type_schemas from Type order by sort",
298298
);
299299
return types.data;
300300
}
301301

302-
async function getPriorities(session: Session) {
303-
const priorities = await session.query<Priority>(
302+
async function getPriorities() {
303+
const priorities = await session.query<"Priority">(
304304
"select id, color, name, sort, value from Priority order by sort",
305305
);
306306
return priorities.data;
307307
}
308308

309-
async function getStatuses(session: Session) {
310-
const priorities = await session.query<Status>(
309+
async function getStatuses() {
310+
const priorities = await session.query<"Status">(
311311
"select id, color, is_active, name, sort, state from Status order by sort",
312312
);
313313
return priorities.data;
314314
}
315315

316-
async function getObjectTypes(session: Session) {
317-
const objectTypes = await session.query<ObjectType>(
316+
async function getObjectTypes() {
317+
const objectTypes = await session.query<"ObjectType">(
318318
"select id, is_leaf, is_prioritizable, is_schedulable, is_statusable, is_taskable, is_time_reportable, is_typeable, name, project_schemas from ObjectType order by sort",
319319
);
320320
return objectTypes.data;
321321
}
322322

323-
async function getProjectSchemas(session: Session) {
324-
const projectSchemas = await session.query<ProjectSchema>(
323+
async function getProjectSchemas() {
324+
const projectSchemas = await session.query<"ProjectSchema">(
325325
"select name, asset_version_workflow_schema, name, object_type_schemas, object_types, task_templates, task_type_schema, task_workflow_schema, task_workflow_schema_overrides from ProjectSchema",
326326
);
327327
return projectSchemas.data;
328328
}
329329

330330
function emitTypedContextTypes(
331331
builder: TypeScriptEmitter,
332-
schemas: QuerySchemasResponse,
332+
schemas: QuerySchemasResponse<Schema>,
333333
) {
334334
builder.appendCode(`
335335
export interface TypedContextSubtypeMap {

source/emitCustomAttributes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { QuerySchemasResponse } from "@ftrack/api";
2-
import { TypeScriptEmitter } from "./typescriptEmitter";
2+
import { TypeScriptEmitter } from "./typescriptEmitter.ts";
3+
import type { Schema } from "./session.ts";
34

45
const uniq = <T>(array: T[]): T[] => {
56
return Array.from(new Set(array));
@@ -21,7 +22,7 @@ const groupBy = <T, K extends string>(list: T[], getKey: (item: T) => K) => {
2122

2223
export function emitCustomAttributes(
2324
typescriptEmitter: TypeScriptEmitter,
24-
schemas: QuerySchemasResponse,
25+
schemas: QuerySchemasResponse<Schema>,
2526
customAttributes: CustomAttributeConfiguration[],
2627
) {
2728
typescriptEmitter.appendCode(`

source/emitSchema.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
// :copyright: Copyright (c) 2023 ftrack
22
import type {
33
QuerySchemasResponse,
4-
Schema,
54
SchemaProperties,
65
TypedSchemaProperty,
6+
Schema,
77
} from "@ftrack/api";
8-
import { type TypeScriptEmitter } from "./typescriptEmitter";
9-
import { isSchemaTypedContext } from "./utils";
8+
import { type TypeScriptEmitter } from "./typescriptEmitter.ts";
9+
import { isSchemaTypedContext } from "./utils.ts";
10+
import type { Schema as ApiSchema } from "./session.ts";
1011

1112
// Add schemas from the schemas folder, to be used for finding extended schemas
1213
export async function emitSchemaInterface(
1314
typescriptEmitter: TypeScriptEmitter,
1415
schema: Schema,
15-
allSchemas: QuerySchemasResponse,
16+
allSchemas: QuerySchemasResponse<ApiSchema>,
1617
) {
1718
const interfaceName = getTypeScriptInterfaceNameForInterface(schema);
1819

source/index.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
11
#!/usr/bin/env node
22
// :copyright: Copyright (c) 2023 ftrack
3-
// A node.js script to convert our query_schema to TypeScript types
4-
// TODO: Change type to module in API
5-
import { Session } from "@ftrack/api";
6-
import { emitToFile } from "./emit";
7-
8-
const session = new Session(
9-
process.env.FTRACK_SERVER ?? "",
10-
process.env.FTRACK_API_USER ?? "",
11-
process.env.FTRACK_API_KEY ?? "",
12-
);
3+
import { emitToFile } from "./emit.ts";
134

145
const outputPath = process.argv[2] || "__generated__";
156
const outputFilename = process.argv[3] || "schema.ts";
16-
const { errors, schemas } = await emitToFile(
17-
session,
18-
outputPath,
19-
outputFilename,
20-
);
7+
const { errors, schemas } = await emitToFile(outputPath, outputFilename);
218

229
console.info(`${schemas.length} schema(s) found`);
2310

source/session.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Session } from "@ftrack/api";
2+
import type {
3+
ObjectType,
4+
Type,
5+
Priority,
6+
ProjectSchema,
7+
Status,
8+
} from "./emit.ts";
9+
import type { CustomAttributeConfiguration } from "./emitCustomAttributes.ts";
10+
11+
export interface Schema {
12+
ObjectType: ObjectType;
13+
CustomAttributeConfiguration: CustomAttributeConfiguration;
14+
Type: Type;
15+
Priority: Priority;
16+
ProjectSchema: ProjectSchema;
17+
Status: Status;
18+
}
19+
20+
export const session = new Session<Schema>(
21+
process.env.FTRACK_SERVER ?? "",
22+
process.env.FTRACK_API_USER ?? "",
23+
process.env.FTRACK_API_KEY ?? "",
24+
{
25+
autoConnectEventHub: false,
26+
},
27+
);

tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"forceConsistentCasingInFileNames": true,
66
"incremental": true,
77
"isolatedModules": true,
8-
"module": "ESNext",
9-
"moduleResolution": "Node",
8+
"module": "NodeNext",
109
"lib": ["DOM", "DOM.Iterable", "ESNext"],
1110
"noEmit": true,
1211
"resolveJsonModule": true,
@@ -15,7 +14,8 @@
1514
"target": "ESNext",
1615
"useDefineForClassFields": true,
1716
"verbatimModuleSyntax": true,
18-
"erasableSyntaxOnly": true
17+
"erasableSyntaxOnly": true,
18+
"allowImportingTsExtensions": true
1919
},
2020
"include": ["source/**/*.ts"]
2121
}

0 commit comments

Comments
 (0)