true-pg 0.5.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,18 +10,19 @@ import extractFunction, {} from "./kinds/function.js";
10
10
  import extractDomain, {} from "./kinds/domain.js";
11
11
  import extractRange, {} from "./kinds/range.js";
12
12
  import fetchTypes from "./fetchTypes.js";
13
- import { canonicalise, Canonical } from "./canonicalise.js";
13
+ export { pgTypeKinds } from "./pgtype.js";
14
+ import { canonicalise, Canonical, canonicaliseFromOids } from "./canonicalise.js";
14
15
  export { Canonical };
15
16
  export { FunctionReturnTypeKind } from "./kinds/function.js";
16
17
  const emptySchema = {
17
- tables: [],
18
- views: [],
19
- materializedViews: [],
20
- enums: [],
21
- composites: [],
22
- functions: [],
23
- domains: [],
24
- ranges: [],
18
+ table: [],
19
+ view: [],
20
+ materializedView: [],
21
+ enum: [],
22
+ composite: [],
23
+ function: [],
24
+ domain: [],
25
+ range: [],
25
26
  };
26
27
  const populatorMap = {
27
28
  table: extractTable,
@@ -62,9 +63,6 @@ export class Extractor {
62
63
  }
63
64
  this.db = new DbAdapter(pg, opts.pg ? true : false);
64
65
  }
65
- async canonicalise(types) {
66
- return canonicalise(this.db, types);
67
- }
68
66
  async getBuiltinTypes() {
69
67
  await this.db.connect();
70
68
  const db = this.db;
@@ -133,10 +131,7 @@ export class Extractor {
133
131
  ...emptySchema,
134
132
  };
135
133
  }
136
- schemas[p.schemaName][`${p.kind}s`] = [
137
- ...schemas[p.schemaName][`${p.kind}s`],
138
- p,
139
- ];
134
+ schemas[p.schemaName][p.kind] = [...schemas[p.schemaName][p.kind], p];
140
135
  }
141
136
  const result =
142
137
  // options?.resolveViews
@@ -1,6 +1,6 @@
1
1
  import type { DbAdapter } from "../adapter.ts";
2
2
  import type { PgType } from "../pgtype.ts";
3
- import { Canonical } from "../canonicalise.ts";
3
+ import type { Canonical } from "../canonicalise.ts";
4
4
  /**
5
5
  * Composite type in a schema with details.
6
6
  */
@@ -1,9 +1,8 @@
1
- import { Canonical, canonicalise } from "../canonicalise.js";
2
1
  const extractComposite = async (db, composite) => {
3
2
  // Form the fully qualified type name
4
3
  const fullTypeName = `"${composite.schemaName}"."${composite.name}"`;
5
4
  // Get canonical type information with all the metadata
6
- const [canonical] = await canonicalise(db, [fullTypeName]);
5
+ const [canonical] = await db.canonicalise([fullTypeName]);
7
6
  // Return the composite type with its canonical representation
8
7
  return {
9
8
  ...composite,
@@ -1,6 +1,6 @@
1
1
  import type { DbAdapter } from "../adapter.ts";
2
2
  import type { PgType } from "../pgtype.ts";
3
- import { Canonical } from "../canonicalise.ts";
3
+ import type { Canonical } from "../canonicalise.ts";
4
4
  /**
5
5
  * Domain type in a schema with details.
6
6
  */
@@ -1,9 +1,8 @@
1
- import { Canonical, canonicalise } from "../canonicalise.js";
2
1
  const extractDomain = async (db, domain) => {
3
2
  // Form the fully qualified type name
4
3
  const fullTypeName = `"${domain.schemaName}"."${domain.name}"`;
5
4
  // Get canonical type information with all the metadata
6
- const [canonical] = await canonicalise(db, [fullTypeName]);
5
+ const [canonical] = await db.canonicalise([fullTypeName]);
7
6
  // Return the composite type with its canonical representation
8
7
  return {
9
8
  ...domain,
@@ -1,6 +1,6 @@
1
1
  import type { DbAdapter } from "../adapter.ts";
2
2
  import type { PgType } from "../pgtype.ts";
3
- import { Canonical } from "../canonicalise.ts";
3
+ import type { Canonical } from "../canonicalise.ts";
4
4
  declare const parameterModeMap: {
5
5
  readonly i: "IN";
6
6
  readonly o: "OUT";
@@ -1,4 +1,3 @@
1
- import { canonicalise, Canonical } from "../canonicalise.js";
2
1
  import { parsePostgresTableDefinition } from "./util/parseInlineTable.js";
3
2
  const parameterModeMap = {
4
3
  i: "IN",
@@ -75,13 +74,13 @@ async function extractFunction(db, pgType) {
75
74
  if (row.arg_names && !row.arg_modes)
76
75
  row.arg_modes = row.arg_names.map(() => "i");
77
76
  const argModes = row.arg_modes?.map(mode => parameterModeMap[mode]) ?? [];
78
- const canonical_arg_types = row.arg_types ? await canonicalise(db, row.arg_types) : [];
77
+ const canonical_arg_types = row.arg_types ? await db.canonicalise(row.arg_types) : [];
79
78
  let returnType;
80
79
  const tableMatch = row.declared_return_type.match(/^TABLE\((.*)\)$/i);
81
80
  if (tableMatch) {
82
81
  const columnDefs = parsePostgresTableDefinition(row.declared_return_type);
83
82
  const columnTypes = columnDefs.map(col => col.type);
84
- const canonicalColumnTypes = await canonicalise(db, columnTypes);
83
+ const canonicalColumnTypes = await db.canonicalise(columnTypes);
85
84
  returnType = {
86
85
  kind: FunctionReturnTypeKind.InlineTable,
87
86
  columns: columnDefs.map((col, i) => ({
@@ -111,7 +110,7 @@ async function extractFunction(db, pgType) {
111
110
  else if (
112
111
  // "c" = composite type
113
112
  row.return_type_relation_kind === "c") {
114
- const canonicalReturnType = (await canonicalise(db, [row.return_type_string]))[0];
113
+ const canonicalReturnType = (await db.canonicalise([row.return_type_string]))[0];
115
114
  returnType = {
116
115
  kind: FunctionReturnTypeKind.Regular,
117
116
  type: canonicalReturnType,
@@ -120,7 +119,7 @@ async function extractFunction(db, pgType) {
120
119
  }
121
120
  else {
122
121
  console.warn(`Composite return type '${row.return_type_string}' has unexpected relkind '${row.return_type_relation_kind}' for function ${pgType.schemaName}.${row.name}`);
123
- const canonicalReturnType = (await canonicalise(db, [row.return_type_string]))[0];
122
+ const canonicalReturnType = (await db.canonicalise([row.return_type_string]))[0];
124
123
  returnType = {
125
124
  kind: FunctionReturnTypeKind.Regular,
126
125
  type: canonicalReturnType,
@@ -129,7 +128,7 @@ async function extractFunction(db, pgType) {
129
128
  }
130
129
  }
131
130
  else {
132
- const canonicalReturnType = (await canonicalise(db, [row.return_type_string]))[0];
131
+ const canonicalReturnType = (await db.canonicalise([row.return_type_string]))[0];
133
132
  returnType = {
134
133
  kind: FunctionReturnTypeKind.Regular,
135
134
  type: canonicalReturnType,
@@ -1,6 +1,6 @@
1
1
  import type { DbAdapter } from "../adapter.ts";
2
2
  import type { PgType } from "../pgtype.ts";
3
- import { Canonical } from "../canonicalise.ts";
3
+ import type { Canonical } from "../canonicalise.ts";
4
4
  export interface MaterializedViewColumn {
5
5
  name: string;
6
6
  type: Canonical;
@@ -1,4 +1,3 @@
1
- import { Canonical, canonicalise } from "../canonicalise.js";
2
1
  const extractMaterializedView = async (db, mview) => {
3
2
  // 1. Query for columns (using pg_attribute for potentially more accurate nullability)
4
3
  const columnQuery = await db.query(`
@@ -26,7 +25,7 @@ const extractMaterializedView = async (db, mview) => {
26
25
  `, [mview.name, mview.schemaName]);
27
26
  // 2. Get canonical types
28
27
  const definedTypes = columnQuery.map(row => row.definedType);
29
- const canonicalTypes = await canonicalise(db, definedTypes);
28
+ const canonicalTypes = await db.canonicalise(definedTypes);
30
29
  const columns = columnQuery.map((row, index) => ({
31
30
  name: row.name,
32
31
  type: canonicalTypes[index],
@@ -1,6 +1,6 @@
1
1
  import type { DbAdapter } from "../adapter.ts";
2
2
  import type { PgType } from "../pgtype.ts";
3
- import { Canonical } from "../canonicalise.ts";
3
+ import type { Canonical } from "../canonicalise.ts";
4
4
  /**
5
5
  * Range type in a schema with details.
6
6
  */
@@ -1,9 +1,8 @@
1
- import { Canonical, canonicalise } from "../canonicalise.js";
2
1
  const extractRange = async (db, range) => {
3
2
  // Form the fully qualified type name
4
3
  const fullTypeName = `"${range.schemaName}"."${range.name}"`;
5
4
  // Get canonical type information with all the metadata
6
- const [canonical] = await canonicalise(db, [fullTypeName]);
5
+ const [canonical] = await db.canonicalise([fullTypeName]);
7
6
  // Return the composite type with its canonical representation
8
7
  return {
9
8
  ...range,
@@ -1,6 +1,6 @@
1
1
  import { DbAdapter } from "../adapter.ts";
2
2
  import type { PgType } from "../pgtype.ts";
3
- import { Canonical } from "../canonicalise.ts";
3
+ import type { Canonical } from "../canonicalise.ts";
4
4
  export declare const updateActionMap: {
5
5
  readonly a: "NO ACTION";
6
6
  readonly r: "RESTRICT";
@@ -1,7 +1,6 @@
1
1
  import { DbAdapter } from "../adapter.js";
2
2
  import commentMapQueryPart from "./parts/commentMapQueryPart.js";
3
3
  import indexMapQueryPart from "./parts/indexMapQueryPart.js";
4
- import { Canonical, canonicalise } from "../canonicalise.js";
5
4
  export const updateActionMap = {
6
5
  a: "NO ACTION",
7
6
  r: "RESTRICT",
@@ -109,7 +108,7 @@ const extractTable = async (db, table) => {
109
108
  // Get the expanded type names from the query result
110
109
  const definedTypes = columnsQuery.map(row => row.definedType);
111
110
  // Use canonicaliseTypes to get detailed type information
112
- const canonicalTypes = await canonicalise(db, definedTypes);
111
+ const canonicalTypes = await db.canonicalise(definedTypes);
113
112
  // Combine the column information with the canonical type information
114
113
  const columns = columnsQuery.map((row, index) => ({
115
114
  name: row.name,
@@ -1,6 +1,6 @@
1
1
  import type { DbAdapter } from "../adapter.ts";
2
2
  import type { PgType } from "../pgtype.ts";
3
- import { Canonical } from "../canonicalise.ts";
3
+ import type { Canonical } from "../canonicalise.ts";
4
4
  export interface ViewColumn {
5
5
  name: string;
6
6
  type: Canonical;
@@ -1,4 +1,3 @@
1
- import { Canonical, canonicalise } from "../canonicalise.js";
2
1
  const extractView = async (db, view) => {
3
2
  // 1. Query for columns (information_schema.columns + pg_attribute)
4
3
  const columnQuery = await db.query(`
@@ -25,7 +24,7 @@ const extractView = async (db, view) => {
25
24
  `, [view.name, view.schemaName]);
26
25
  // 2. Get canonical types
27
26
  const definedTypes = columnQuery.map(row => row.definedType);
28
- const canonicalTypes = await canonicalise(db, definedTypes);
27
+ const canonicalTypes = await db.canonicalise(definedTypes);
29
28
  const columns = columnQuery.map((row, index) => ({
30
29
  name: row.name,
31
30
  type: canonicalTypes[index],
@@ -1,9 +1,9 @@
1
1
  export declare const typeKindMap: {
2
- readonly d: "domain";
3
2
  readonly e: "enum";
3
+ readonly d: "domain";
4
4
  readonly r: "range";
5
5
  };
6
- type TypeKind = (typeof typeKindMap)[keyof typeof typeKindMap];
6
+ export type TypeKind = (typeof typeKindMap)[keyof typeof typeKindMap];
7
7
  export declare const classKindMap: {
8
8
  readonly r: "table";
9
9
  readonly p: "table";
@@ -11,12 +11,13 @@ export declare const classKindMap: {
11
11
  readonly m: "materializedView";
12
12
  readonly c: "composite";
13
13
  };
14
- type ClassKind = (typeof classKindMap)[keyof typeof classKindMap];
14
+ export type ClassKind = (typeof classKindMap)[keyof typeof classKindMap];
15
15
  export declare const routineKindMap: {
16
16
  readonly f: "function";
17
17
  };
18
- type RoutineKind = (typeof routineKindMap)[keyof typeof routineKindMap];
19
- export type Kind = TypeKind | ClassKind | RoutineKind;
18
+ export type RoutineKind = (typeof routineKindMap)[keyof typeof routineKindMap];
19
+ export declare const pgTypeKinds: ("function" | "composite" | "domain" | "enum" | "range" | "table" | "view" | "materializedView")[];
20
+ export type Kind = (typeof pgTypeKinds)[number];
20
21
  /**
21
22
  * Base type for Postgres objects.
22
23
  */
@@ -38,4 +39,3 @@ export type PgType<K extends Kind = Kind> = {
38
39
  */
39
40
  comment: string | null;
40
41
  };
41
- export {};
@@ -1,6 +1,6 @@
1
1
  export const typeKindMap = {
2
- d: "domain",
3
2
  e: "enum",
3
+ d: "domain",
4
4
  r: "range",
5
5
  // Not supported (yet):
6
6
  // m: 'multiRange',
@@ -28,3 +28,9 @@ export const routineKindMap = {
28
28
  // a: 'aggregate',
29
29
  // w: 'windowFunction',
30
30
  };
31
+ const unique = (arr) => [...new Set(arr)];
32
+ export const pgTypeKinds = unique([
33
+ ...Object.values(classKindMap),
34
+ ...Object.values(typeKindMap),
35
+ ...Object.values(routineKindMap),
36
+ ]);
package/lib/imports.d.ts CHANGED
@@ -1,11 +1,16 @@
1
1
  import type { Canonical } from "./extractor/index.ts";
2
2
  import type { FunctionReturnType } from "./extractor/index.ts";
3
- import type { FolderStructure } from "./types.ts";
3
+ import type { allowed_kind_names, FolderStructure } from "./types.ts";
4
4
  export interface ImportIdentifier {
5
5
  name: string;
6
6
  alias?: string;
7
7
  typeOnly?: boolean;
8
8
  }
9
+ type Supported<T> = {
10
+ [key in allowed_kind_names]: T extends {
11
+ kind: key;
12
+ } ? T : never;
13
+ }[allowed_kind_names];
9
14
  export declare class Import {
10
15
  from: string | ((files: FolderStructure) => string);
11
16
  namedImports?: (string | ImportIdentifier)[];
@@ -21,7 +26,7 @@ export declare class Import {
21
26
  });
22
27
  static fromInternal(opts: {
23
28
  source: string;
24
- type: Canonical | FunctionReturnType.ExistingTable;
29
+ type: Supported<Canonical | FunctionReturnType.ExistingTable>;
25
30
  withName?: string;
26
31
  typeOnly?: boolean;
27
32
  }): Import;
@@ -33,3 +38,4 @@ export declare class ImportList {
33
38
  add(item: Import): void;
34
39
  stringify(files: FolderStructure): string;
35
40
  }
41
+ export {};
package/lib/imports.js CHANGED
@@ -1,4 +1,4 @@
1
- import { dirname, relative } from "node:path";
1
+ import { dirname, relative } from "node:path/posix";
2
2
  import { eq } from "./util.js";
3
3
  export class Import {
4
4
  from;
@@ -18,9 +18,12 @@ export class Import {
18
18
  return new Import({
19
19
  from: files => {
20
20
  const schema = files.children[t.schema];
21
- const kind = schema.children[`${t.kind}s`];
22
- const type = kind.children[t.name];
23
- const path = `${files.name}/${schema.name}/${kind.kind}/${type.name}.ts`;
21
+ const kind = schema?.children[t.kind];
22
+ const type = kind?.children[t.name];
23
+ if (!schema || !kind || !type) {
24
+ throw new Error(`Type ${t.kind}/${t.name} not found in schema "${t.schema}"`);
25
+ }
26
+ const path = `${files.name}/${schema.name}/${kind.kind}s/${type.name}.ts`;
24
27
  return relative(dirname(opts.source), path);
25
28
  },
26
29
  namedImports: [opts.withName ?? t.name],
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,188 @@
1
+ import { Canonical } from "./extractor/canonicalise.js";
2
+ import { Import, ImportList } from "./imports.js";
3
+ import { describe, it, expect } from "bun:test";
4
+ const files = {
5
+ name: "root",
6
+ type: "root",
7
+ children: {
8
+ public: {
9
+ name: "public",
10
+ type: "schema",
11
+ children: {
12
+ function: {
13
+ kind: "function",
14
+ type: "kind",
15
+ children: {},
16
+ },
17
+ view: {
18
+ kind: "view",
19
+ type: "kind",
20
+ children: {},
21
+ },
22
+ materializedView: {
23
+ kind: "materializedView",
24
+ type: "kind",
25
+ children: {},
26
+ },
27
+ composite: {
28
+ kind: "composite",
29
+ type: "kind",
30
+ children: {},
31
+ },
32
+ table: {
33
+ kind: "table",
34
+ type: "kind",
35
+ children: {
36
+ testTable: {
37
+ name: "testTable",
38
+ type: "type",
39
+ },
40
+ },
41
+ },
42
+ range: {
43
+ kind: "range",
44
+ type: "kind",
45
+ children: {},
46
+ },
47
+ enum: {
48
+ kind: "enum",
49
+ type: "kind",
50
+ children: {
51
+ testEnum: {
52
+ name: "testEnum",
53
+ type: "type",
54
+ },
55
+ },
56
+ },
57
+ domain: {
58
+ kind: "domain",
59
+ type: "kind",
60
+ children: {},
61
+ },
62
+ },
63
+ },
64
+ },
65
+ };
66
+ describe("Import Class", () => {
67
+ it("should initialize correctly with constructor arguments", () => {
68
+ const importInstance = new Import({
69
+ from: "module/path",
70
+ namedImports: ["component"],
71
+ star: "starImport",
72
+ default: "defaultImport",
73
+ typeOnly: true,
74
+ });
75
+ expect(importInstance.from).toBe("module/path");
76
+ expect(importInstance.namedImports).toEqual(["component"]);
77
+ expect(importInstance.star).toBe("starImport");
78
+ expect(importInstance.default).toBe("defaultImport");
79
+ expect(importInstance.typeOnly).toBe(true);
80
+ });
81
+ it("should create import fromInternal method correctly", () => {
82
+ const importInstance = Import.fromInternal({
83
+ source: "root/public/testEnum/testEnum.ts",
84
+ type: {
85
+ schema: "public",
86
+ kind: Canonical.Kind.Enum,
87
+ name: "testEnum",
88
+ canonical_name: "test",
89
+ dimensions: 1,
90
+ enum_values: ["test1", "test2", "test3"],
91
+ original_type: "string",
92
+ },
93
+ });
94
+ expect(importInstance).toBeInstanceOf(Import);
95
+ expect(typeof importInstance.from === "function" ||
96
+ typeof importInstance.from === "string").toBe(true);
97
+ if (typeof importInstance.from === "function") {
98
+ const generatedPath = importInstance.from(files);
99
+ expect(generatedPath).toBe("../enums/testEnum.ts");
100
+ }
101
+ });
102
+ it("should handle missing properties in fromInternal method", () => {
103
+ const importInstance = Import.fromInternal({
104
+ source: "root/public/testEnum/testEnum.ts",
105
+ type: {
106
+ schema: "public",
107
+ kind: Canonical.Kind.Enum,
108
+ name: "testEnum",
109
+ canonical_name: "test",
110
+ dimensions: 1,
111
+ enum_values: ["test1", "test2", "test3"],
112
+ original_type: "string",
113
+ },
114
+ });
115
+ expect(importInstance).toBeInstanceOf(Import);
116
+ expect(typeof importInstance.from === "function" ||
117
+ typeof importInstance.from === "string").toBe(true);
118
+ if (typeof importInstance.from === "function") {
119
+ const generatedPath = importInstance.from(files);
120
+ expect(generatedPath).toBe("../enums/testEnum.ts");
121
+ }
122
+ });
123
+ it("should handle missing `namedImports` or other constructor properties", () => {
124
+ const importInstance = new Import({ from: "module/path" });
125
+ expect(importInstance.from).toBe("module/path");
126
+ expect(importInstance.namedImports).toBeUndefined();
127
+ expect(importInstance.star).toBeUndefined();
128
+ expect(importInstance.default).toBeUndefined();
129
+ expect(importInstance.typeOnly).toBe(false);
130
+ });
131
+ });
132
+ describe("ImportList Class", () => {
133
+ it("should add imports correctly", () => {
134
+ const importList = new ImportList();
135
+ const newImport = new Import({
136
+ from: "module/path",
137
+ namedImports: ["MyComponent"],
138
+ });
139
+ importList.add(newImport);
140
+ expect(importList.imports).toHaveLength(1);
141
+ expect(importList.imports[0]).toBe(newImport);
142
+ });
143
+ it("should merge import lists correctly", () => {
144
+ const list1 = new ImportList([
145
+ new Import({ from: "module1", namedImports: ["a"] }),
146
+ ]);
147
+ const list2 = new ImportList([
148
+ new Import({ from: "module2", namedImports: ["b"] }),
149
+ ]);
150
+ const mergedList = ImportList.merge([list1, list2]);
151
+ expect(mergedList.imports).toHaveLength(2);
152
+ });
153
+ it("should merge import lists correctly with empty list", () => {
154
+ const list1 = new ImportList([
155
+ new Import({ from: "module1", namedImports: ["a"] }),
156
+ ]);
157
+ const list2 = new ImportList([]);
158
+ const mergedList = ImportList.merge([list1, list2]);
159
+ expect(mergedList.imports).toHaveLength(1);
160
+ });
161
+ it("should stringify imports correctly", () => {
162
+ const importList = new ImportList([
163
+ new Import({ from: "module1", namedImports: ["a"] }),
164
+ new Import({ from: "module1", namedImports: ["b"] }),
165
+ ]);
166
+ const result = importList.stringify(files);
167
+ expect(result).toContain('import { a, b } from "module1";');
168
+ });
169
+ it("should handle empty ImportList gracefully", () => {
170
+ const importList = new ImportList();
171
+ const files = {
172
+ name: "root",
173
+ type: "root",
174
+ children: {},
175
+ };
176
+ const result = importList.stringify(files);
177
+ expect(result).toBe("");
178
+ });
179
+ it("should handle duplicate imports and avoid repetition", () => {
180
+ const importList = new ImportList([
181
+ new Import({ from: "module1", namedImports: ["a"] }),
182
+ new Import({ from: "module1", namedImports: ["a"] }),
183
+ ]);
184
+ const result = importList.stringify(files);
185
+ expect(result).toBe('import { a } from "module1";');
186
+ expect(result.split("\n")).toBeArrayOfSize(1);
187
+ });
188
+ });
package/lib/index.js CHANGED
@@ -14,11 +14,27 @@ const yellow = (str) => (NO_COLOR ? str : `\x1b[33m${str}\x1b[0m`);
14
14
  const blue = (str) => (NO_COLOR ? str : `\x1b[34m${str}\x1b[0m`);
15
15
  const bold = (str) => (NO_COLOR ? str : `\x1b[1m${str}\x1b[0m`);
16
16
  const underline = (str) => (NO_COLOR ? str : `\x1b[4m${str}\x1b[0m`);
17
+ const formatTime = (time) => {
18
+ const mins = Math.floor(time / 60000);
19
+ const secs = Math.floor((time % 60000) / 1000);
20
+ const ms = Math.floor(time % 1000);
21
+ const us = Math.floor((time * 1000) % 1000)
22
+ .toString()
23
+ .padStart(3, "0");
24
+ const parts = [];
25
+ if (mins)
26
+ parts.push(mins + "m");
27
+ if (secs)
28
+ parts.push(secs + "s");
29
+ if (!mins)
30
+ parts.push(ms + (!secs && us ? "." + us : "") + "ms");
31
+ return parts.join("");
32
+ };
17
33
  const THRESHOLD1 = 800;
18
34
  const THRESHOLD2 = 1500;
19
35
  const time = (start, addParens = true) => {
20
36
  const diff = performance.now() - start;
21
- const diffstr = diff.toFixed(2) + "ms";
37
+ const diffstr = formatTime(diff);
22
38
  const str = addParens ? parens(diffstr) : diffstr;
23
39
  if (diff < THRESHOLD1)
24
40
  return green(str);
@@ -115,9 +131,9 @@ const multifile = async (generators, schemas, opts) => {
115
131
  for (const schema of Object.values(schemas)) {
116
132
  console.log("Selected schema '%s':\n", schema.name);
117
133
  const schemaDir = joinpath(out, schema.name);
118
- const [unique_functions, overloaded_functions] = filter_overloaded_functions(schema.functions);
134
+ const [unique_functions, overloaded_functions] = filter_overloaded_functions(schema.function);
119
135
  const [supported_functions, unsupported_functions] = filter_unsupported_functions(unique_functions);
120
- schema.functions = supported_functions;
136
+ schema.function = supported_functions;
121
137
  {
122
138
  const skipped = unsupported_functions.map(f => ` - ${f.name}`);
123
139
  if (skipped.length) {
@@ -136,11 +152,12 @@ const multifile = async (generators, schemas, opts) => {
136
152
  if (schema[kind].length < 1)
137
153
  continue;
138
154
  createIndex = true;
139
- await mkdir(joinpath(schemaDir, kind), { recursive: true });
140
- console.log(" Creating %s:\n", kind);
155
+ const kindDir = joinpath(schemaDir, kind + "s");
156
+ await mkdir(kindDir, { recursive: true });
157
+ console.log(" Creating %s:\n", kind + "s");
141
158
  for (const [i, item] of schema[kind].entries()) {
142
159
  const index = "[" + (i + 1 + "]").padEnd(3, " ");
143
- const filename = joinpath(schemaDir, kind, def_gen.formatSchemaMemberName(item) + ".ts");
160
+ const filename = joinpath(kindDir, def_gen.formatSchemaMemberName(item) + ".ts");
144
161
  const exists = await existsSync(filename);
145
162
  if (exists) {
146
163
  warnings.add(`Skipping ${item.kind} "${item.name}": formatted name clashes. Wanted to create ${filename}`);
@@ -159,7 +176,7 @@ const multifile = async (generators, schemas, opts) => {
159
176
  {
160
177
  const start = performance.now();
161
178
  const imports = new ImportList();
162
- const fileName = joinpath(schemaDir, kind, "index.ts");
179
+ const fileName = joinpath(kindDir, "index.ts");
163
180
  const kindIndex = join(gens.map(gen => gen.schemaKindIndex({ source: fileName, imports }, schema, kind, def_gen)));
164
181
  const file = join([imports.stringify(files), kindIndex]);
165
182
  await write(fileName, file);