@palantir/pack.document-schema.type-gen 0.0.4-beta.0 → 0.0.4-beta.1
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.
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/external-refs.js +20 -0
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/external-refs.js.map +1 -0
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/simple-record.js +16 -0
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/simple-record.js.map +1 -0
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/union-types.js +48 -0
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/union-types.js.map +1 -0
- package/build/esm/utils/ir/__tests__/generateModelsFromIr.test.js +293 -0
- package/build/esm/utils/ir/__tests__/generateModelsFromIr.test.js.map +1 -0
- package/build/esm/utils/ir/generateModelsFromIr.js +1 -1
- package/build/esm/utils/ir/generateModelsFromIr.js.map +1 -1
- package/build/esm/utils/schema/generateTypesFromSchema.js +1 -1
- package/build/esm/utils/schema/generateTypesFromSchema.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/refTypes.js.map +1 -1
- package/build/types/utils/ir/__tests__/generateModelsFromIr.test.d.ts +2 -0
- package/build/types/utils/ir/__tests__/generateModelsFromIr.test.d.ts.map +1 -0
- package/build/types/utils/schema/generateTypesFromSchema.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Metadata } from '@palantir/pack.document-schema.model-types';
|
|
2
|
+
import { EventSchema } from './schema.js';
|
|
3
|
+
export const EventModel = {
|
|
4
|
+
__type: {},
|
|
5
|
+
zodSchema: EventSchema,
|
|
6
|
+
[Metadata]: {
|
|
7
|
+
externalRefFieldTypes: {
|
|
8
|
+
documentRef: 'docRef',
|
|
9
|
+
userRef: 'userRef'
|
|
10
|
+
},
|
|
11
|
+
name: 'Event'
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export const DocumentModel = {
|
|
15
|
+
Event: EventModel,
|
|
16
|
+
[Metadata]: {
|
|
17
|
+
version: 1
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=external-refs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-refs.js","names":["Metadata","EventSchema","EventModel","__type","zodSchema","externalRefFieldTypes","documentRef","userRef","name","DocumentModel","Event","version"],"sources":["external-refs.ts"],"sourcesContent":["import type {\n DocumentSchema,\n Model,\n} from '@palantir/pack.document-schema.model-types';\nimport { Metadata } from '@palantir/pack.document-schema.model-types';\nimport type { Event } from './types.js';\nimport { EventSchema } from './schema.js';\n\nexport interface EventModel extends Model<Event, typeof EventSchema> {}\nexport const EventModel: EventModel = {\n __type: {} as Event,\n zodSchema: EventSchema,\n [Metadata]: {\n externalRefFieldTypes: {\n documentRef: 'docRef',\n userRef: 'userRef',\n },\n name: 'Event',\n },\n};\n\nexport const DocumentModel = {\n Event: EventModel,\n [Metadata]: {\n version: 1,\n },\n} as const satisfies DocumentSchema;\n\nexport type DocumentModel = typeof DocumentModel;\n"],"mappings":"AAIA,SAASA,QAAQ,QAAQ,4CAA4C;AAErE,SAASC,WAAW,QAAQ,aAAa;AAGzC,OAAO,MAAMC,UAAsB,GAAG;EACpCC,MAAM,EAAE,CAAC,CAAU;EACnBC,SAAS,EAAEH,WAAW;EACtB,CAACD,QAAQ,GAAG;IACVK,qBAAqB,EAAE;MACrBC,WAAW,EAAE,QAAQ;MACrBC,OAAO,EAAE;IACX,CAAC;IACDC,IAAI,EAAE;EACR;AACF,CAAC;AAED,OAAO,MAAMC,aAAa,GAAG;EAC3BC,KAAK,EAAER,UAAU;EACjB,CAACF,QAAQ,GAAG;IACVW,OAAO,EAAE;EACX;AACF,CAAmC","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Metadata } from '@palantir/pack.document-schema.model-types';
|
|
2
|
+
import { PersonSchema } from './schema.js';
|
|
3
|
+
export const PersonModel = {
|
|
4
|
+
__type: {},
|
|
5
|
+
zodSchema: PersonSchema,
|
|
6
|
+
[Metadata]: {
|
|
7
|
+
name: 'Person'
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export const DocumentModel = {
|
|
11
|
+
Person: PersonModel,
|
|
12
|
+
[Metadata]: {
|
|
13
|
+
version: 1
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=simple-record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simple-record.js","names":["Metadata","PersonSchema","PersonModel","__type","zodSchema","name","DocumentModel","Person","version"],"sources":["simple-record.ts"],"sourcesContent":["import type {\n DocumentSchema,\n Model,\n} from '@palantir/pack.document-schema.model-types';\nimport { Metadata } from '@palantir/pack.document-schema.model-types';\nimport type { Person } from './types.js';\nimport { PersonSchema } from './schema.js';\n\nexport interface PersonModel extends Model<Person, typeof PersonSchema> {}\nexport const PersonModel: PersonModel = {\n __type: {} as Person,\n zodSchema: PersonSchema,\n [Metadata]: {\n name: 'Person',\n },\n};\n\nexport const DocumentModel = {\n Person: PersonModel,\n [Metadata]: {\n version: 1,\n },\n} as const satisfies DocumentSchema;\n\nexport type DocumentModel = typeof DocumentModel;\n"],"mappings":"AAIA,SAASA,QAAQ,QAAQ,4CAA4C;AAErE,SAASC,YAAY,QAAQ,aAAa;AAG1C,OAAO,MAAMC,WAAwB,GAAG;EACtCC,MAAM,EAAE,CAAC,CAAW;EACpBC,SAAS,EAAEH,YAAY;EACvB,CAACD,QAAQ,GAAG;IACVK,IAAI,EAAE;EACR;AACF,CAAC;AAED,OAAO,MAAMC,aAAa,GAAG;EAC3BC,MAAM,EAAEL,WAAW;EACnB,CAACF,QAAQ,GAAG;IACVQ,OAAO,EAAE;EACX;AACF,CAAmC","ignoreList":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Metadata } from '@palantir/pack.document-schema.model-types';
|
|
2
|
+
import { NodeObjectSchema, NodeSchema, NodeTextBoxSchema, ObjectNodeSchema, TextBoxSchema } from './schema.js';
|
|
3
|
+
export const ObjectNodeModel = {
|
|
4
|
+
__type: {},
|
|
5
|
+
zodSchema: ObjectNodeSchema,
|
|
6
|
+
[Metadata]: {
|
|
7
|
+
name: 'ObjectNode'
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export const TextBoxModel = {
|
|
11
|
+
__type: {},
|
|
12
|
+
zodSchema: TextBoxSchema,
|
|
13
|
+
[Metadata]: {
|
|
14
|
+
name: 'TextBox'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const NodeModel = {
|
|
18
|
+
__type: {},
|
|
19
|
+
zodSchema: NodeSchema,
|
|
20
|
+
[Metadata]: {
|
|
21
|
+
name: 'Node'
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export const NodeObjectModel = {
|
|
25
|
+
__type: {},
|
|
26
|
+
zodSchema: NodeObjectSchema,
|
|
27
|
+
[Metadata]: {
|
|
28
|
+
name: 'NodeObject'
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export const NodeTextBoxModel = {
|
|
32
|
+
__type: {},
|
|
33
|
+
zodSchema: NodeTextBoxSchema,
|
|
34
|
+
[Metadata]: {
|
|
35
|
+
name: 'NodeTextBox'
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export const DocumentModel = {
|
|
39
|
+
ObjectNode: ObjectNodeModel,
|
|
40
|
+
TextBox: TextBoxModel,
|
|
41
|
+
Node: NodeModel,
|
|
42
|
+
NodeObject: NodeObjectModel,
|
|
43
|
+
NodeTextBox: NodeTextBoxModel,
|
|
44
|
+
[Metadata]: {
|
|
45
|
+
version: 1
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=union-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"union-types.js","names":["Metadata","NodeObjectSchema","NodeSchema","NodeTextBoxSchema","ObjectNodeSchema","TextBoxSchema","ObjectNodeModel","__type","zodSchema","name","TextBoxModel","NodeModel","NodeObjectModel","NodeTextBoxModel","DocumentModel","ObjectNode","TextBox","Node","NodeObject","NodeTextBox","version"],"sources":["union-types.ts"],"sourcesContent":["import type {\n DocumentSchema,\n Model,\n} from '@palantir/pack.document-schema.model-types';\nimport { Metadata } from '@palantir/pack.document-schema.model-types';\nimport type {\n Node,\n NodeObject,\n NodeTextBox,\n ObjectNode,\n TextBox,\n} from './types.js';\nimport {\n NodeObjectSchema,\n NodeSchema,\n NodeTextBoxSchema,\n ObjectNodeSchema,\n TextBoxSchema,\n} from './schema.js';\n\nexport interface ObjectNodeModel\n extends Model<ObjectNode, typeof ObjectNodeSchema> {}\nexport const ObjectNodeModel: ObjectNodeModel = {\n __type: {} as ObjectNode,\n zodSchema: ObjectNodeSchema,\n [Metadata]: {\n name: 'ObjectNode',\n },\n};\n\nexport interface TextBoxModel extends Model<TextBox, typeof TextBoxSchema> {}\nexport const TextBoxModel: TextBoxModel = {\n __type: {} as TextBox,\n zodSchema: TextBoxSchema,\n [Metadata]: {\n name: 'TextBox',\n },\n};\n\nexport interface NodeModel extends Model<Node, typeof NodeSchema> {}\nexport const NodeModel: NodeModel = {\n __type: {} as Node,\n zodSchema: NodeSchema,\n [Metadata]: {\n name: 'Node',\n },\n};\n\nexport interface NodeObjectModel\n extends Model<NodeObject, typeof NodeObjectSchema> {}\nexport const NodeObjectModel: NodeObjectModel = {\n __type: {} as NodeObject,\n zodSchema: NodeObjectSchema,\n [Metadata]: {\n name: 'NodeObject',\n },\n};\n\nexport interface NodeTextBoxModel\n extends Model<NodeTextBox, typeof NodeTextBoxSchema> {}\nexport const NodeTextBoxModel: NodeTextBoxModel = {\n __type: {} as NodeTextBox,\n zodSchema: NodeTextBoxSchema,\n [Metadata]: {\n name: 'NodeTextBox',\n },\n};\n\nexport const DocumentModel = {\n ObjectNode: ObjectNodeModel,\n TextBox: TextBoxModel,\n Node: NodeModel,\n NodeObject: NodeObjectModel,\n NodeTextBox: NodeTextBoxModel,\n [Metadata]: {\n version: 1,\n },\n} as const satisfies DocumentSchema;\n\nexport type DocumentModel = typeof DocumentModel;\n"],"mappings":"AAIA,SAASA,QAAQ,QAAQ,4CAA4C;AAQrE,SACEC,gBAAgB,EAChBC,UAAU,EACVC,iBAAiB,EACjBC,gBAAgB,EAChBC,aAAa,QACR,aAAa;AAIpB,OAAO,MAAMC,eAAgC,GAAG;EAC9CC,MAAM,EAAE,CAAC,CAAe;EACxBC,SAAS,EAAEJ,gBAAgB;EAC3B,CAACJ,QAAQ,GAAG;IACVS,IAAI,EAAE;EACR;AACF,CAAC;AAGD,OAAO,MAAMC,YAA0B,GAAG;EACxCH,MAAM,EAAE,CAAC,CAAY;EACrBC,SAAS,EAAEH,aAAa;EACxB,CAACL,QAAQ,GAAG;IACVS,IAAI,EAAE;EACR;AACF,CAAC;AAGD,OAAO,MAAME,SAAoB,GAAG;EAClCJ,MAAM,EAAE,CAAC,CAAS;EAClBC,SAAS,EAAEN,UAAU;EACrB,CAACF,QAAQ,GAAG;IACVS,IAAI,EAAE;EACR;AACF,CAAC;AAID,OAAO,MAAMG,eAAgC,GAAG;EAC9CL,MAAM,EAAE,CAAC,CAAe;EACxBC,SAAS,EAAEP,gBAAgB;EAC3B,CAACD,QAAQ,GAAG;IACVS,IAAI,EAAE;EACR;AACF,CAAC;AAID,OAAO,MAAMI,gBAAkC,GAAG;EAChDN,MAAM,EAAE,CAAC,CAAgB;EACzBC,SAAS,EAAEL,iBAAiB;EAC5B,CAACH,QAAQ,GAAG;IACVS,IAAI,EAAE;EACR;AACF,CAAC;AAED,OAAO,MAAMK,aAAa,GAAG;EAC3BC,UAAU,EAAET,eAAe;EAC3BU,OAAO,EAAEN,YAAY;EACrBO,IAAI,EAAEN,SAAS;EACfO,UAAU,EAAEN,eAAe;EAC3BO,WAAW,EAAEN,gBAAgB;EAC7B,CAACb,QAAQ,GAAG;IACVoB,OAAO,EAAE;EACX;AACF,CAAmC","ignoreList":[]}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import path from "path";
|
|
18
|
+
import { describe, expect, it } from "vitest";
|
|
19
|
+
import { generateModelsFromIr } from "../generateModelsFromIr.js";
|
|
20
|
+
import { formatWithPrettier } from "./formatWithPrettier.js";
|
|
21
|
+
describe("generateModelsFromIr", () => {
|
|
22
|
+
const snapshotDir = path.join(__dirname, "__snapshots__", "generateModelsFromIr");
|
|
23
|
+
it("should generate Model constants for simple record types", async () => {
|
|
24
|
+
const result = await generateModelsFromIr({
|
|
25
|
+
name: "Test Schema",
|
|
26
|
+
description: "A test schema",
|
|
27
|
+
version: 1,
|
|
28
|
+
primaryModelKeys: ["Person"],
|
|
29
|
+
models: {
|
|
30
|
+
Person: {
|
|
31
|
+
type: "record",
|
|
32
|
+
record: {
|
|
33
|
+
key: "Person",
|
|
34
|
+
name: "Person",
|
|
35
|
+
description: "A person record",
|
|
36
|
+
fields: [{
|
|
37
|
+
key: "name",
|
|
38
|
+
name: "Name",
|
|
39
|
+
description: "Person name",
|
|
40
|
+
value: {
|
|
41
|
+
type: "value",
|
|
42
|
+
value: {
|
|
43
|
+
type: "string",
|
|
44
|
+
string: {
|
|
45
|
+
minLength: 2,
|
|
46
|
+
maxLength: 50
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
meta: {
|
|
51
|
+
addedIn: 1
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
key: "age",
|
|
55
|
+
name: "Age",
|
|
56
|
+
description: "Person age",
|
|
57
|
+
value: {
|
|
58
|
+
type: "value",
|
|
59
|
+
value: {
|
|
60
|
+
type: "integer",
|
|
61
|
+
integer: {
|
|
62
|
+
minValue: 0,
|
|
63
|
+
maxValue: 150
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
meta: {
|
|
68
|
+
addedIn: 1
|
|
69
|
+
}
|
|
70
|
+
}],
|
|
71
|
+
meta: {
|
|
72
|
+
addedIn: 1
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
const formatted = await formatWithPrettier(result);
|
|
79
|
+
|
|
80
|
+
// Verify imports are properly formatted (no weird indentation)
|
|
81
|
+
const lines = formatted.split("\n");
|
|
82
|
+
const importLines = lines.filter(line => line.startsWith("import"));
|
|
83
|
+
expect(importLines.length).toBeGreaterThan(0);
|
|
84
|
+
// All imports should start at column 0 (no leading whitespace)
|
|
85
|
+
importLines.forEach(line => {
|
|
86
|
+
expect(line).toMatch(/^import/);
|
|
87
|
+
});
|
|
88
|
+
await expect(formatted).toMatchFileSnapshot(path.join(snapshotDir, "simple-record.ts"));
|
|
89
|
+
});
|
|
90
|
+
it("should generate Model constants with external ref fields", async () => {
|
|
91
|
+
const result = await generateModelsFromIr({
|
|
92
|
+
name: "Test Schema",
|
|
93
|
+
description: "A test schema with external refs",
|
|
94
|
+
version: 1,
|
|
95
|
+
primaryModelKeys: ["Event"],
|
|
96
|
+
models: {
|
|
97
|
+
Event: {
|
|
98
|
+
type: "record",
|
|
99
|
+
record: {
|
|
100
|
+
key: "Event",
|
|
101
|
+
name: "Event",
|
|
102
|
+
description: "An event record with external refs",
|
|
103
|
+
fields: [{
|
|
104
|
+
key: "documentRef",
|
|
105
|
+
name: "Document Reference",
|
|
106
|
+
description: "Reference to a document",
|
|
107
|
+
value: {
|
|
108
|
+
type: "value",
|
|
109
|
+
value: {
|
|
110
|
+
type: "docRef",
|
|
111
|
+
docRef: {
|
|
112
|
+
documentTypeRids: []
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
meta: {
|
|
117
|
+
addedIn: 1
|
|
118
|
+
}
|
|
119
|
+
}, {
|
|
120
|
+
key: "userRef",
|
|
121
|
+
name: "User Reference",
|
|
122
|
+
description: "Reference to a user",
|
|
123
|
+
value: {
|
|
124
|
+
type: "value",
|
|
125
|
+
value: {
|
|
126
|
+
type: "userRef",
|
|
127
|
+
userRef: {}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
meta: {
|
|
131
|
+
addedIn: 1
|
|
132
|
+
}
|
|
133
|
+
}, {
|
|
134
|
+
key: "timestamp",
|
|
135
|
+
name: "Timestamp",
|
|
136
|
+
description: "Event timestamp",
|
|
137
|
+
value: {
|
|
138
|
+
type: "value",
|
|
139
|
+
value: {
|
|
140
|
+
type: "datetime",
|
|
141
|
+
datetime: {}
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
meta: {
|
|
145
|
+
addedIn: 1
|
|
146
|
+
}
|
|
147
|
+
}],
|
|
148
|
+
meta: {
|
|
149
|
+
addedIn: 1
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
const formatted = await formatWithPrettier(result);
|
|
156
|
+
|
|
157
|
+
// Verify external ref fields are included in metadata
|
|
158
|
+
expect(formatted).toContain("externalRefFieldTypes");
|
|
159
|
+
expect(formatted).toContain("documentRef: 'docRef'");
|
|
160
|
+
expect(formatted).toContain("userRef: 'userRef'");
|
|
161
|
+
await expect(formatted).toMatchFileSnapshot(path.join(snapshotDir, "external-refs.ts"));
|
|
162
|
+
});
|
|
163
|
+
it("should generate Model constants for union types", async () => {
|
|
164
|
+
// Define the ObjectNode record
|
|
165
|
+
|
|
166
|
+
// Define the TextBox record
|
|
167
|
+
|
|
168
|
+
// Define the Node union
|
|
169
|
+
|
|
170
|
+
const result = await generateModelsFromIr({
|
|
171
|
+
name: "Test Schema",
|
|
172
|
+
description: "A test schema with unions",
|
|
173
|
+
version: 1,
|
|
174
|
+
primaryModelKeys: ["ObjectNode", "TextBox", "Node"],
|
|
175
|
+
models: {
|
|
176
|
+
ObjectNode: {
|
|
177
|
+
type: "record",
|
|
178
|
+
record: {
|
|
179
|
+
key: "ObjectNode",
|
|
180
|
+
name: "ObjectNode",
|
|
181
|
+
description: "A node in the graph",
|
|
182
|
+
fields: [{
|
|
183
|
+
key: "x",
|
|
184
|
+
name: "X",
|
|
185
|
+
description: "X coordinate",
|
|
186
|
+
value: {
|
|
187
|
+
type: "value",
|
|
188
|
+
value: {
|
|
189
|
+
type: "double",
|
|
190
|
+
double: {}
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
meta: {
|
|
194
|
+
addedIn: 1
|
|
195
|
+
}
|
|
196
|
+
}, {
|
|
197
|
+
key: "y",
|
|
198
|
+
name: "Y",
|
|
199
|
+
description: "Y coordinate",
|
|
200
|
+
value: {
|
|
201
|
+
type: "value",
|
|
202
|
+
value: {
|
|
203
|
+
type: "double",
|
|
204
|
+
double: {}
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
meta: {
|
|
208
|
+
addedIn: 1
|
|
209
|
+
}
|
|
210
|
+
}],
|
|
211
|
+
meta: {
|
|
212
|
+
addedIn: 1
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
TextBox: {
|
|
217
|
+
type: "record",
|
|
218
|
+
record: {
|
|
219
|
+
key: "TextBox",
|
|
220
|
+
name: "TextBox",
|
|
221
|
+
description: "A text box in the graph",
|
|
222
|
+
fields: [{
|
|
223
|
+
key: "x",
|
|
224
|
+
name: "X",
|
|
225
|
+
description: "X coordinate",
|
|
226
|
+
value: {
|
|
227
|
+
type: "value",
|
|
228
|
+
value: {
|
|
229
|
+
type: "double",
|
|
230
|
+
double: {}
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
meta: {
|
|
234
|
+
addedIn: 1
|
|
235
|
+
}
|
|
236
|
+
}, {
|
|
237
|
+
key: "text",
|
|
238
|
+
name: "Text",
|
|
239
|
+
description: "Text content",
|
|
240
|
+
value: {
|
|
241
|
+
type: "value",
|
|
242
|
+
value: {
|
|
243
|
+
type: "string",
|
|
244
|
+
string: {}
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
meta: {
|
|
248
|
+
addedIn: 1
|
|
249
|
+
}
|
|
250
|
+
}],
|
|
251
|
+
meta: {
|
|
252
|
+
addedIn: 1
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
Node: {
|
|
257
|
+
type: "union",
|
|
258
|
+
union: {
|
|
259
|
+
key: "Node",
|
|
260
|
+
discriminant: "type",
|
|
261
|
+
name: "Node",
|
|
262
|
+
description: "A node in the graph",
|
|
263
|
+
variants: {
|
|
264
|
+
object: "ObjectNode",
|
|
265
|
+
"text-box": "TextBox"
|
|
266
|
+
},
|
|
267
|
+
meta: {
|
|
268
|
+
addedIn: 1
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
const formatted = await formatWithPrettier(result);
|
|
275
|
+
|
|
276
|
+
// Verify all models are generated (primary models + union variants)
|
|
277
|
+
expect(formatted).toContain("export const ObjectNodeModel");
|
|
278
|
+
expect(formatted).toContain("export const TextBoxModel");
|
|
279
|
+
expect(formatted).toContain("export const NodeModel");
|
|
280
|
+
expect(formatted).toContain("export const NodeObjectModel");
|
|
281
|
+
expect(formatted).toContain("export const NodeTextBoxModel");
|
|
282
|
+
|
|
283
|
+
// Verify DocumentSchema contains all models
|
|
284
|
+
expect(formatted).toContain("export const DocumentModel");
|
|
285
|
+
expect(formatted).toContain("ObjectNode: ObjectNodeModel");
|
|
286
|
+
expect(formatted).toContain("TextBox: TextBoxModel");
|
|
287
|
+
expect(formatted).toContain("Node: NodeModel");
|
|
288
|
+
expect(formatted).toContain("NodeObject: NodeObjectModel");
|
|
289
|
+
expect(formatted).toContain("NodeTextBox: NodeTextBoxModel");
|
|
290
|
+
await expect(formatted).toMatchFileSnapshot(path.join(snapshotDir, "union-types.ts"));
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
//# sourceMappingURL=generateModelsFromIr.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateModelsFromIr.test.js","names":["path","describe","expect","it","generateModelsFromIr","formatWithPrettier","snapshotDir","join","__dirname","result","name","description","version","primaryModelKeys","models","Person","type","record","key","fields","value","string","minLength","maxLength","meta","addedIn","integer","minValue","maxValue","formatted","lines","split","importLines","filter","line","startsWith","length","toBeGreaterThan","forEach","toMatch","toMatchFileSnapshot","Event","docRef","documentTypeRids","userRef","datetime","toContain","ObjectNode","double","TextBox","Node","union","discriminant","variants","object"],"sources":["generateModelsFromIr.test.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport path from \"path\";\nimport { describe, expect, it } from \"vitest\";\nimport type {\n IFieldDef,\n IModelDef,\n IRealTimeDocumentSchema,\n IRecordDef,\n IUnionDef,\n} from \"../../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { generateModelsFromIr } from \"../generateModelsFromIr.js\";\nimport { formatWithPrettier } from \"./formatWithPrettier.js\";\n\ndescribe(\"generateModelsFromIr\", () => {\n const snapshotDir = path.join(__dirname, \"__snapshots__\", \"generateModelsFromIr\");\n\n it(\"should generate Model constants for simple record types\", async () => {\n const personField1: IFieldDef = {\n key: \"name\",\n name: \"Name\",\n description: \"Person name\",\n value: {\n type: \"value\",\n value: {\n type: \"string\",\n string: { minLength: 2, maxLength: 50 },\n },\n },\n meta: { addedIn: 1 },\n };\n\n const personField2: IFieldDef = {\n key: \"age\",\n name: \"Age\",\n description: \"Person age\",\n value: {\n type: \"value\",\n value: {\n type: \"integer\",\n integer: { minValue: 0, maxValue: 150 },\n },\n },\n meta: { addedIn: 1 },\n };\n\n const personRecord: IRecordDef = {\n key: \"Person\",\n name: \"Person\",\n description: \"A person record\",\n fields: [personField1, personField2],\n meta: { addedIn: 1 },\n };\n\n const schema: IRealTimeDocumentSchema = {\n name: \"Test Schema\",\n description: \"A test schema\",\n version: 1,\n primaryModelKeys: [\"Person\"],\n models: {\n Person: {\n type: \"record\",\n record: personRecord,\n } as IModelDef,\n },\n };\n\n const result = await generateModelsFromIr(schema);\n const formatted = await formatWithPrettier(result);\n\n // Verify imports are properly formatted (no weird indentation)\n const lines = formatted.split(\"\\n\");\n const importLines = lines.filter(line => line.startsWith(\"import\"));\n expect(importLines.length).toBeGreaterThan(0);\n // All imports should start at column 0 (no leading whitespace)\n importLines.forEach(line => {\n expect(line).toMatch(/^import/);\n });\n\n await expect(formatted).toMatchFileSnapshot(path.join(snapshotDir, \"simple-record.ts\"));\n });\n\n it(\"should generate Model constants with external ref fields\", async () => {\n const eventField1: IFieldDef = {\n key: \"documentRef\",\n name: \"Document Reference\",\n description: \"Reference to a document\",\n value: {\n type: \"value\",\n value: {\n type: \"docRef\",\n docRef: {\n documentTypeRids: [],\n },\n },\n },\n meta: { addedIn: 1 },\n };\n\n const eventField2: IFieldDef = {\n key: \"userRef\",\n name: \"User Reference\",\n description: \"Reference to a user\",\n value: {\n type: \"value\",\n value: {\n type: \"userRef\",\n userRef: {},\n },\n },\n meta: { addedIn: 1 },\n };\n\n const eventField3: IFieldDef = {\n key: \"timestamp\",\n name: \"Timestamp\",\n description: \"Event timestamp\",\n value: {\n type: \"value\",\n value: {\n type: \"datetime\",\n datetime: {},\n },\n },\n meta: { addedIn: 1 },\n };\n\n const eventRecord: IRecordDef = {\n key: \"Event\",\n name: \"Event\",\n description: \"An event record with external refs\",\n fields: [eventField1, eventField2, eventField3],\n meta: { addedIn: 1 },\n };\n\n const schema: IRealTimeDocumentSchema = {\n name: \"Test Schema\",\n description: \"A test schema with external refs\",\n version: 1,\n primaryModelKeys: [\"Event\"],\n models: {\n Event: {\n type: \"record\",\n record: eventRecord,\n } as IModelDef,\n },\n };\n\n const result = await generateModelsFromIr(schema);\n const formatted = await formatWithPrettier(result);\n\n // Verify external ref fields are included in metadata\n expect(formatted).toContain(\"externalRefFieldTypes\");\n expect(formatted).toContain(\"documentRef: 'docRef'\");\n expect(formatted).toContain(\"userRef: 'userRef'\");\n\n await expect(formatted).toMatchFileSnapshot(path.join(snapshotDir, \"external-refs.ts\"));\n });\n\n it(\"should generate Model constants for union types\", async () => {\n // Define the ObjectNode record\n const objectNodeRecord: IRecordDef = {\n key: \"ObjectNode\",\n name: \"ObjectNode\",\n description: \"A node in the graph\",\n fields: [\n {\n key: \"x\",\n name: \"X\",\n description: \"X coordinate\",\n value: {\n type: \"value\",\n value: {\n type: \"double\",\n double: {},\n },\n },\n meta: { addedIn: 1 },\n },\n {\n key: \"y\",\n name: \"Y\",\n description: \"Y coordinate\",\n value: {\n type: \"value\",\n value: {\n type: \"double\",\n double: {},\n },\n },\n meta: { addedIn: 1 },\n },\n ],\n meta: { addedIn: 1 },\n };\n\n // Define the TextBox record\n const textBoxRecord: IRecordDef = {\n key: \"TextBox\",\n name: \"TextBox\",\n description: \"A text box in the graph\",\n fields: [\n {\n key: \"x\",\n name: \"X\",\n description: \"X coordinate\",\n value: {\n type: \"value\",\n value: {\n type: \"double\",\n double: {},\n },\n },\n meta: { addedIn: 1 },\n },\n {\n key: \"text\",\n name: \"Text\",\n description: \"Text content\",\n value: {\n type: \"value\",\n value: {\n type: \"string\",\n string: {},\n },\n },\n meta: { addedIn: 1 },\n },\n ],\n meta: { addedIn: 1 },\n };\n\n // Define the Node union\n const nodeUnion: IUnionDef = {\n key: \"Node\",\n discriminant: \"type\",\n name: \"Node\",\n description: \"A node in the graph\",\n variants: {\n object: \"ObjectNode\",\n \"text-box\": \"TextBox\",\n },\n meta: { addedIn: 1 },\n };\n\n const schema: IRealTimeDocumentSchema = {\n name: \"Test Schema\",\n description: \"A test schema with unions\",\n version: 1,\n primaryModelKeys: [\"ObjectNode\", \"TextBox\", \"Node\"],\n models: {\n ObjectNode: {\n type: \"record\",\n record: objectNodeRecord,\n } as IModelDef,\n TextBox: {\n type: \"record\",\n record: textBoxRecord,\n } as IModelDef,\n Node: {\n type: \"union\",\n union: nodeUnion,\n } as IModelDef,\n },\n };\n\n const result = await generateModelsFromIr(schema);\n const formatted = await formatWithPrettier(result);\n\n // Verify all models are generated (primary models + union variants)\n expect(formatted).toContain(\"export const ObjectNodeModel\");\n expect(formatted).toContain(\"export const TextBoxModel\");\n expect(formatted).toContain(\"export const NodeModel\");\n expect(formatted).toContain(\"export const NodeObjectModel\");\n expect(formatted).toContain(\"export const NodeTextBoxModel\");\n\n // Verify DocumentSchema contains all models\n expect(formatted).toContain(\"export const DocumentModel\");\n expect(formatted).toContain(\"ObjectNode: ObjectNodeModel\");\n expect(formatted).toContain(\"TextBox: TextBoxModel\");\n expect(formatted).toContain(\"Node: NodeModel\");\n expect(formatted).toContain(\"NodeObject: NodeObjectModel\");\n expect(formatted).toContain(\"NodeTextBox: NodeTextBoxModel\");\n\n await expect(formatted).toMatchFileSnapshot(path.join(snapshotDir, \"union-types.ts\"));\n });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SAAS,CAAC,CAACiB,SAAS,CAAC,2BAA2B,CAAC;IACxD5C,MAAM,CAAC2B,SAAS,CAAC,CAACiB,SAAS,CAAC,wBAAwB,CAAC;IACrD5C,MAAM,CAAC2B,SAAS,CAAC,CAACiB,SAAS,CAAC,8BAA8B,CAAC;IAC3D5C,MAAM,CAAC2B,SAAS,CAAC,CAACiB,SAAS,CAAC,+BAA+B,CAAC;;IAE5D;IACA5C,MAAM,CAAC2B,SAAS,CAAC,CAACiB,SAAS,CAAC,4BAA4B,CAAC;IACzD5C,MAAM,CAAC2B,SAAS,CAAC,CAACiB,SAAS,CAAC,6BAA6B,CAAC;IAC1D5C,MAAM,CAAC2B,SAAS,CAAC,CAACiB,SAAS,CAAC,uBAAuB,CAAC;IACpD5C,MAAM,CAAC2B,SAAS,CAAC,CAACiB,SAAS,CAAC,iBAAiB,CAAC;IAC9C5C,MAAM,CAAC2B,SAAS,CAAC,CAACiB,SAAS,CAAC,6BAA6B,CAAC;IAC1D5C,MAAM,CAAC2B,SAAS,CAAC,CAACiB,SAAS,CAAC,+BAA+B,CAAC;IAE5D,MAAM5C,MAAM,CAAC2B,SAAS,CAAC,CAACW,mBAAmB,CAACxC,IAAI,CAACO,IAAI,CAACD,WAAW,EAAE,gBAAgB,CAAC,CAAC;EACvF,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -24,7 +24,7 @@ export class ModelGenerator {
|
|
|
24
24
|
generateModels() {
|
|
25
25
|
const typeImportPath = this.options?.typeImportPath ?? "./types.js";
|
|
26
26
|
const schemaImportPath = this.options?.schemaImportPath ?? "./schema.js";
|
|
27
|
-
const modelTypesPackage = "@palantir/pack.schema";
|
|
27
|
+
const modelTypesPackage = "@palantir/pack.document-schema.model-types";
|
|
28
28
|
|
|
29
29
|
// Generate imports
|
|
30
30
|
let imports = `import type { DocumentSchema, Model } from "${modelTypesPackage}";\n`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateModelsFromIr.js","names":["invariant","formatVariantName","ModelGenerator","constructor","schema","options","undefined","generateModels","typeImportPath","schemaImportPath","modelTypesPackage","imports","typeNames","Set","primaryModelKeys","modelKey","model","models","type","variantName","Object","keys","union","variants","formattedVariantName","variantTypeName","key","add","typeImports","Array","from","sort","join","schemaNames","variantSchemaName","schemaImports","modelConstants","generateModelConstants","documentSchema","generateDocumentSchema","Promise","resolve","constants","processedModels","process","env","NODE_ENV","has","modelConstant","generateModelConstant","push","typeName","modelName","schemaName","externalRefFields","extractExternalRefFieldTypes","externalRefFieldTypesCode","length","entries","map","field","record","fields","value","valueType","modelEntries","generateModelsFromIr","generator"],"sources":["generateModelsFromIr.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nimport type { IRealTimeDocumentSchema } from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { formatVariantName } from \"../formatVariantName.js\";\n\nexport interface ModelGeneratorOptions {\n typeImportPath?: string;\n schemaImportPath?: string;\n}\n\nexport class ModelGenerator {\n constructor(\n private readonly schema: IRealTimeDocumentSchema,\n private readonly options: ModelGeneratorOptions | undefined = undefined,\n ) {}\n\n public generateModels(): Promise<string> {\n const typeImportPath = this.options?.typeImportPath ?? \"./types.js\";\n const schemaImportPath = this.options?.schemaImportPath ?? \"./schema.js\";\n const modelTypesPackage = \"@palantir/pack.schema\";\n\n // Generate imports\n let imports = `import type { DocumentSchema, Model } from \"${modelTypesPackage}\";\\n`;\n imports += `import { Metadata } from \"${modelTypesPackage}\";\\n`;\n\n // Collect all type names (primary models + union variants)\n const typeNames = new Set(this.schema.primaryModelKeys);\n\n // Add union variant type names\n for (const modelKey of this.schema.primaryModelKeys) {\n const model = this.schema.models[modelKey];\n if (model?.type === \"union\") {\n for (const variantName of Object.keys(model.union.variants)) {\n const formattedVariantName = formatVariantName(variantName);\n const variantTypeName = `${model.union.key}${formattedVariantName}`;\n typeNames.add(variantTypeName);\n }\n }\n }\n\n const typeImports = Array.from(typeNames).sort().join(\", \");\n imports += `import type { ${typeImports} } from \"${typeImportPath}\";\\n`;\n\n // Collect all schema names (primary models + union variants)\n const schemaNames = new Set<string>();\n for (const modelKey of this.schema.primaryModelKeys) {\n schemaNames.add(`${modelKey}Schema`);\n\n const model = this.schema.models[modelKey];\n if (model?.type === \"union\") {\n for (const variantName of Object.keys(model.union.variants)) {\n const formattedVariantName = formatVariantName(variantName);\n const variantSchemaName = `${model.union.key}${formattedVariantName}Schema`;\n schemaNames.add(variantSchemaName);\n }\n }\n }\n\n const schemaImports = Array.from(schemaNames).sort().join(\", \");\n imports += `import { ${schemaImports} } from \"${schemaImportPath}\";\\n\\n`;\n\n // Generate model constants\n const modelConstants = this.generateModelConstants();\n\n // Generate DocumentSchema\n const documentSchema = this.generateDocumentSchema();\n\n return Promise.resolve(imports + modelConstants + \"\\n\\n\" + documentSchema + \"\\n\");\n }\n\n private generateModelConstants(): string {\n const constants: string[] = [];\n const processedModels = new Set<string>();\n\n // Generate models for primary keys and their union variants\n for (const modelKey of this.schema.primaryModelKeys) {\n const model = this.schema.models[modelKey];\n invariant(model != null, `Model not found: ${modelKey}`);\n\n // Generate primary model constant\n if (!processedModels.has(modelKey)) {\n const modelConstant = this.generateModelConstant(modelKey, modelKey);\n constants.push(modelConstant);\n processedModels.add(modelKey);\n }\n\n // Generate union variant constants\n if (model.type === \"union\") {\n for (const variantName of Object.keys(model.union.variants)) {\n const formattedVariantName = formatVariantName(variantName);\n const variantTypeName = `${model.union.key}${formattedVariantName}`;\n\n if (!processedModels.has(variantTypeName)) {\n const modelConstant = this.generateModelConstant(variantTypeName, variantTypeName);\n constants.push(modelConstant);\n processedModels.add(variantTypeName);\n }\n }\n }\n }\n\n return constants.join(\"\\n\\n\");\n }\n\n private generateModelConstant(typeName: string, modelName: string): string {\n const schemaName = `${typeName}Schema`;\n const externalRefFields = this.extractExternalRefFieldTypes(modelName);\n\n let externalRefFieldTypesCode = \"\";\n if (externalRefFields.length > 0) {\n const entries = externalRefFields.map(([field, type]) => ` ${field}: \"${type}\",`).join(\n \"\\n\",\n );\n externalRefFieldTypesCode = `\\n externalRefFieldTypes: {\\n${entries}\\n },`;\n }\n\n return `export interface ${modelName}Model extends Model<${typeName}, typeof ${schemaName}> {}\nexport const ${modelName}Model: ${modelName}Model = {\n __type: {} as ${typeName},\n zodSchema: ${schemaName},\n [Metadata]: {${externalRefFieldTypesCode}\n name: \"${modelName}\",\n },\n};`;\n }\n\n private extractExternalRefFieldTypes(modelName: string): Array<[string, string]> {\n const model = this.schema.models[modelName];\n if (model?.type !== \"record\") {\n return [];\n }\n\n const externalRefFields: Array<[string, string]> = [];\n for (const field of model.record.fields) {\n if (field.value.type === \"value\") {\n const valueType = field.value.value.type;\n if (valueType === \"docRef\") {\n externalRefFields.push([field.key, \"docRef\"]);\n } else if (valueType === \"mediaRef\") {\n externalRefFields.push([field.key, \"mediaRef\"]);\n } else if (valueType === \"object\") {\n externalRefFields.push([field.key, \"objectRef\"]);\n } else if (valueType === \"userRef\") {\n externalRefFields.push([field.key, \"userRef\"]);\n }\n }\n }\n\n return externalRefFields;\n }\n\n private generateDocumentSchema(): string {\n const modelEntries: string[] = [];\n const processedModels = new Set<string>();\n\n // Collect all model names that will be generated\n for (const modelKey of this.schema.primaryModelKeys) {\n const model = this.schema.models[modelKey];\n invariant(model != null, `Model not found: ${modelKey}`);\n\n // Add primary model\n if (!processedModels.has(modelKey)) {\n modelEntries.push(` ${modelKey}: ${modelKey}Model`);\n processedModels.add(modelKey);\n }\n\n // Add union variant models\n if (model.type === \"union\") {\n for (const variantName of Object.keys(model.union.variants)) {\n const formattedVariantName = formatVariantName(variantName);\n const variantTypeName = `${model.union.key}${formattedVariantName}`;\n\n if (!processedModels.has(variantTypeName)) {\n modelEntries.push(` ${variantTypeName}: ${variantTypeName}Model`);\n processedModels.add(variantTypeName);\n }\n }\n }\n }\n\n return `export const DocumentModel = {\n${modelEntries.join(\",\\n\")},\n [Metadata]: {\n version: 1,\n },\n} as const satisfies DocumentSchema;\\n\n export type DocumentModel = typeof DocumentModel;`;\n }\n}\n\nexport async function generateModelsFromIr(\n schema: IRealTimeDocumentSchema,\n options?: ModelGeneratorOptions,\n): Promise<string> {\n const generator = new ModelGenerator(schema, options);\n return generator.generateModels();\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AAEtC,SAASC,iBAAiB,QAAQ,yBAAyB;AAO3D,OAAO,MAAMC,cAAc,CAAC;EAC1BC,WAAWA,CACQC,MAA+B,EAC/BC,OAA0C,GAAGC,SAAS,EACvE;IAAA,KAFiBF,MAA+B,GAA/BA,MAA+B;IAAA,KAC/BC,OAA0C,GAA1CA,OAA0C;EAC1D;EAEIE,cAAcA,CAAA,EAAoB;IACvC,MAAMC,cAAc,GAAG,IAAI,CAACH,OAAO,EAAEG,cAAc,IAAI,YAAY;IACnE,MAAMC,gBAAgB,GAAG,IAAI,CAACJ,OAAO,EAAEI,gBAAgB,IAAI,aAAa;IACxE,MAAMC,iBAAiB,GAAG,uBAAuB;;IAEjD;IACA,IAAIC,OAAO,GAAG,+CAA+CD,iBAAiB,MAAM;IACpFC,OAAO,IAAI,6BAA6BD,iBAAiB,MAAM;;IAE/D;IACA,MAAME,SAAS,GAAG,IAAIC,GAAG,CAAC,IAAI,CAACT,MAAM,CAACU,gBAAgB,CAAC;;IAEvD;IACA,KAAK,MAAMC,QAAQ,IAAI,IAAI,CAACX,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,IAAI,IAAI,IAAA4B,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAvB9C,SAAS,QAAgB,oBAAoBe,QAAQ,EAAE,IAAvDf,SAAS;;MAET;MACA,IAAI,CAAC2C,eAAe,CAACI,GAAG,CAAChC,QAAQ,CAAC,EAAE;QAClCkD,YAAY,CAACf,IAAI,CAAC,KAAKnC,QAAQ,KAAKA,QAAQ,OAAO,CAAC;QACpD4B,eAAe,CAAChB,GAAG,CAACZ,QAAQ,CAAC;MAC/B;;MAEA;MACA,IAAIC,KAAK,CAACE,IAAI,KAAK,OAAO,EAAE;QAC1B,KAAK,MAAMC,WAAW,IAAIC,MAAM,CAACC,IAAI,CAACL,KAAK,CAACM,KAAK,CAACC,QAAQ,CAAC,EAAE;UAC3D,MAAMC,oBAAoB,GAAGvB,iBAAiB,CAACkB,WAAW,CAAC;UAC3D,MAAMM,eAAe,GAAG,GAAGT,KAAK,CAACM,KAAK,CAACI,GAAG,GAAGF,oBAAoB,EAAE;UAEnE,IAAI,CAACmB,eAAe,CAACI,GAAG,CAACtB,eAAe,CAAC,EAAE;YACzCwC,YAAY,CAACf,IAAI,CAAC,KAAKzB,eAAe,KAAKA,eAAe,OAAO,CAAC;YAClEkB,eAAe,CAAChB,GAAG,CAACF,eAAe,CAAC;UACtC;QACF;MACF;IACF;IAEA,OAAO;AACX,EAAEwC,YAAY,CAACjC,IAAI,CAAC,KAAK,CAAC;AAC1B;AACA;AACA;AACA;AACA,mDAAmD;EACjD;AACF;AAEA,OAAO,eAAekC,oBAAoBA,CACxC9D,MAA+B,EAC/BC,OAA+B,EACd;EACjB,MAAM8D,SAAS,GAAG,IAAIjE,cAAc,CAACE,MAAM,EAAEC,OAAO,CAAC;EACrD,OAAO8D,SAAS,CAAC5D,cAAc,CAAC,CAAC;AACnC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"generateModelsFromIr.js","names":["invariant","formatVariantName","ModelGenerator","constructor","schema","options","undefined","generateModels","typeImportPath","schemaImportPath","modelTypesPackage","imports","typeNames","Set","primaryModelKeys","modelKey","model","models","type","variantName","Object","keys","union","variants","formattedVariantName","variantTypeName","key","add","typeImports","Array","from","sort","join","schemaNames","variantSchemaName","schemaImports","modelConstants","generateModelConstants","documentSchema","generateDocumentSchema","Promise","resolve","constants","processedModels","process","env","NODE_ENV","has","modelConstant","generateModelConstant","push","typeName","modelName","schemaName","externalRefFields","extractExternalRefFieldTypes","externalRefFieldTypesCode","length","entries","map","field","record","fields","value","valueType","modelEntries","generateModelsFromIr","generator"],"sources":["generateModelsFromIr.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nimport type { IRealTimeDocumentSchema } from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { formatVariantName } from \"../formatVariantName.js\";\n\nexport interface ModelGeneratorOptions {\n typeImportPath?: string;\n schemaImportPath?: string;\n}\n\nexport class ModelGenerator {\n constructor(\n private readonly schema: IRealTimeDocumentSchema,\n private readonly options: ModelGeneratorOptions | undefined = undefined,\n ) {}\n\n public generateModels(): Promise<string> {\n const typeImportPath = this.options?.typeImportPath ?? \"./types.js\";\n const schemaImportPath = this.options?.schemaImportPath ?? \"./schema.js\";\n const modelTypesPackage = \"@palantir/pack.document-schema.model-types\";\n\n // Generate imports\n let imports = `import type { DocumentSchema, Model } from \"${modelTypesPackage}\";\\n`;\n imports += `import { Metadata } from \"${modelTypesPackage}\";\\n`;\n\n // Collect all type names (primary models + union variants)\n const typeNames = new Set(this.schema.primaryModelKeys);\n\n // Add union variant type names\n for (const modelKey of this.schema.primaryModelKeys) {\n const model = this.schema.models[modelKey];\n if (model?.type === \"union\") {\n for (const variantName of Object.keys(model.union.variants)) {\n const formattedVariantName = formatVariantName(variantName);\n const variantTypeName = `${model.union.key}${formattedVariantName}`;\n typeNames.add(variantTypeName);\n }\n }\n }\n\n const typeImports = Array.from(typeNames).sort().join(\", \");\n imports += `import type { ${typeImports} } from \"${typeImportPath}\";\\n`;\n\n // Collect all schema names (primary models + union variants)\n const schemaNames = new Set<string>();\n for (const modelKey of this.schema.primaryModelKeys) {\n schemaNames.add(`${modelKey}Schema`);\n\n const model = this.schema.models[modelKey];\n if (model?.type === \"union\") {\n for (const variantName of Object.keys(model.union.variants)) {\n const formattedVariantName = formatVariantName(variantName);\n const variantSchemaName = `${model.union.key}${formattedVariantName}Schema`;\n schemaNames.add(variantSchemaName);\n }\n }\n }\n\n const schemaImports = Array.from(schemaNames).sort().join(\", \");\n imports += `import { ${schemaImports} } from \"${schemaImportPath}\";\\n\\n`;\n\n // Generate model constants\n const modelConstants = this.generateModelConstants();\n\n // Generate DocumentSchema\n const documentSchema = this.generateDocumentSchema();\n\n return Promise.resolve(imports + modelConstants + \"\\n\\n\" + documentSchema + \"\\n\");\n }\n\n private generateModelConstants(): string {\n const constants: string[] = [];\n const processedModels = new Set<string>();\n\n // Generate models for primary keys and their union variants\n for (const modelKey of this.schema.primaryModelKeys) {\n const model = this.schema.models[modelKey];\n invariant(model != null, `Model not found: ${modelKey}`);\n\n // Generate primary model constant\n if (!processedModels.has(modelKey)) {\n const modelConstant = this.generateModelConstant(modelKey, modelKey);\n constants.push(modelConstant);\n processedModels.add(modelKey);\n }\n\n // Generate union variant constants\n if (model.type === \"union\") {\n for (const variantName of Object.keys(model.union.variants)) {\n const formattedVariantName = formatVariantName(variantName);\n const variantTypeName = `${model.union.key}${formattedVariantName}`;\n\n if (!processedModels.has(variantTypeName)) {\n const modelConstant = this.generateModelConstant(variantTypeName, variantTypeName);\n constants.push(modelConstant);\n processedModels.add(variantTypeName);\n }\n }\n }\n }\n\n return constants.join(\"\\n\\n\");\n }\n\n private generateModelConstant(typeName: string, modelName: string): string {\n const schemaName = `${typeName}Schema`;\n const externalRefFields = this.extractExternalRefFieldTypes(modelName);\n\n let externalRefFieldTypesCode = \"\";\n if (externalRefFields.length > 0) {\n const entries = externalRefFields.map(([field, type]) => ` ${field}: \"${type}\",`).join(\n \"\\n\",\n );\n externalRefFieldTypesCode = `\\n externalRefFieldTypes: {\\n${entries}\\n },`;\n }\n\n return `export interface ${modelName}Model extends Model<${typeName}, typeof ${schemaName}> {}\nexport const ${modelName}Model: ${modelName}Model = {\n __type: {} as ${typeName},\n zodSchema: ${schemaName},\n [Metadata]: {${externalRefFieldTypesCode}\n name: \"${modelName}\",\n },\n};`;\n }\n\n private extractExternalRefFieldTypes(modelName: string): Array<[string, string]> {\n const model = this.schema.models[modelName];\n if (model?.type !== \"record\") {\n return [];\n }\n\n const externalRefFields: Array<[string, string]> = [];\n for (const field of model.record.fields) {\n if (field.value.type === \"value\") {\n const valueType = field.value.value.type;\n if (valueType === \"docRef\") {\n externalRefFields.push([field.key, \"docRef\"]);\n } else if (valueType === \"mediaRef\") {\n externalRefFields.push([field.key, \"mediaRef\"]);\n } else if (valueType === \"object\") {\n externalRefFields.push([field.key, \"objectRef\"]);\n } else if (valueType === \"userRef\") {\n externalRefFields.push([field.key, \"userRef\"]);\n }\n }\n }\n\n return externalRefFields;\n }\n\n private generateDocumentSchema(): string {\n const modelEntries: string[] = [];\n const processedModels = new Set<string>();\n\n // Collect all model names that will be generated\n for (const modelKey of this.schema.primaryModelKeys) {\n const model = this.schema.models[modelKey];\n invariant(model != null, `Model not found: ${modelKey}`);\n\n // Add primary model\n if (!processedModels.has(modelKey)) {\n modelEntries.push(` ${modelKey}: ${modelKey}Model`);\n processedModels.add(modelKey);\n }\n\n // Add union variant models\n if (model.type === \"union\") {\n for (const variantName of Object.keys(model.union.variants)) {\n const formattedVariantName = formatVariantName(variantName);\n const variantTypeName = `${model.union.key}${formattedVariantName}`;\n\n if (!processedModels.has(variantTypeName)) {\n modelEntries.push(` ${variantTypeName}: ${variantTypeName}Model`);\n processedModels.add(variantTypeName);\n }\n }\n }\n }\n\n return `export const DocumentModel = {\n${modelEntries.join(\",\\n\")},\n [Metadata]: {\n version: 1,\n },\n} as const satisfies DocumentSchema;\\n\n export type DocumentModel = typeof DocumentModel;`;\n }\n}\n\nexport async function generateModelsFromIr(\n schema: IRealTimeDocumentSchema,\n options?: ModelGeneratorOptions,\n): Promise<string> {\n const generator = new ModelGenerator(schema, options);\n return generator.generateModels();\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AAEtC,SAASC,iBAAiB,QAAQ,yBAAyB;AAO3D,OAAO,MAAMC,cAAc,CAAC;EAC1BC,WAAWA,CACQC,MAA+B,EAC/BC,OAA0C,GAAGC,SAAS,EACvE;IAAA,KAFiBF,MAA+B,GAA/BA,MAA+B;IAAA,KAC/BC,OAA0C,GAA1CA,OAA0C;EAC1D;EAEIE,cAAcA,CAAA,EAAoB;IACvC,MAAMC,cAAc,GAAG,IAAI,CAACH,OAAO,EAAEG,cAAc,IAAI,YAAY;IACnE,MAAMC,gBAAgB,GAAG,IAAI,CAACJ,OAAO,EAAEI,gBAAgB,IAAI,aAAa;IACxE,MAAMC,iBAAiB,GAAG,4CAA4C;;IAEtE;IACA,IAAIC,OAAO,GAAG,+CAA+CD,iBAAiB,MAAM;IACpFC,OAAO,IAAI,6BAA6BD,iBAAiB,MAAM;;IAE/D;IACA,MAAME,SAAS,GAAG,IAAIC,GAAG,CAAC,IAAI,CAACT,MAAM,CAACU,gBAAgB,CAAC;;IAEvD;IACA,KAAK,MAAMC,QAAQ,IAAI,IAAI,CAACX,MAAM,CAACU,gBAAgB,EAAE;MACnD,MAAME,KAAK,GAAG,IAAI,CAACZ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C,SAAS,QAAgB,oBAAoBe,QAAQ,EAAE,IAAvDf,SAAS;;MAET;MACA,IAAI,CAAC2C,eAAe,CAACI,GAAG,CAAChC,QAAQ,CAAC,EAAE;QAClCkD,YAAY,CAACf,IAAI,CAAC,KAAKnC,QAAQ,KAAKA,QAAQ,OAAO,CAAC;QACpD4B,eAAe,CAAChB,GAAG,CAACZ,QAAQ,CAAC;MAC/B;;MAEA;MACA,IAAIC,KAAK,CAACE,IAAI,KAAK,OAAO,EAAE;QAC1B,KAAK,MAAMC,WAAW,IAAIC,MAAM,CAACC,IAAI,CAACL,KAAK,CAACM,KAAK,CAACC,QAAQ,CAAC,EAAE;UAC3D,MAAMC,oBAAoB,GAAGvB,iBAAiB,CAACkB,WAAW,CAAC;UAC3D,MAAMM,eAAe,GAAG,GAAGT,KAAK,CAACM,KAAK,CAACI,GAAG,GAAGF,oBAAoB,EAAE;UAEnE,IAAI,CAACmB,eAAe,CAACI,GAAG,CAACtB,eAAe,CAAC,EAAE;YACzCwC,YAAY,CAACf,IAAI,CAAC,KAAKzB,eAAe,KAAKA,eAAe,OAAO,CAAC;YAClEkB,eAAe,CAAChB,GAAG,CAACF,eAAe,CAAC;UACtC;QACF;MACF;IACF;IAEA,OAAO;AACX,EAAEwC,YAAY,CAACjC,IAAI,CAAC,KAAK,CAAC;AAC1B;AACA;AACA;AACA;AACA,mDAAmD;EACjD;AACF;AAEA,OAAO,eAAekC,oBAAoBA,CACxC9D,MAA+B,EAC/BC,OAA+B,EACd;EACjB,MAAM8D,SAAS,GAAG,IAAIjE,cAAc,CAACE,MAAM,EAAEC,OAAO,CAAC;EACrD,OAAO8D,SAAS,CAAC5D,cAAc,CAAC,CAAC;AACnC","ignoreList":[]}
|
|
@@ -103,7 +103,7 @@ export function generateTypesFromSchema(schema) {
|
|
|
103
103
|
// Add conditional imports based on which ref types are used
|
|
104
104
|
if (usedRefTypes.size > 0) {
|
|
105
105
|
const refTypesList = Array.from(usedRefTypes).sort().join(", ");
|
|
106
|
-
output += `import type { ${refTypesList} } from "@palantir/pack.schema";\n`;
|
|
106
|
+
output += `import type { ${refTypesList} } from "@palantir/pack.document-schema.model-types";\n`;
|
|
107
107
|
}
|
|
108
108
|
output += "\n";
|
|
109
109
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypesFromSchema.js","names":["formatVariantName","SchemaDefKind","RECORD","UNION","TypeKind","ANY","ARRAY","DOC_REF","DOUBLE","MEDIA_REF","OBJECT_REF","OPTIONAL","REF","STRING","USER_REF","isRecordSchema","item","type","isUnionSchema","isRefField","field","isArrayField","isOptionalField","detectUsedRefTypes","schema","refTypes","Set","scanField","items","add","Object","values","fields","variant","variants","generateTypesFromSchema","runtimeSchema","usedRefTypes","output","size","refTypesList","Array","from","sort","join","exportName","entries","generateRecordInterface","unionEntries","filter","_","forEach","i","unionOutput","generateUnionType","length","record","docs","fieldName","fieldType","tsType","convertTypeToTypeScript","optional","union","variantInterfaces","variantName","variantType","interfaceName","push","name","discriminatorValue","refType","recordName","findRecordExportName","map","v"],"sources":["generateTypesFromSchema.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ReturnedSchema, Schema } from \"@palantir/pack.schema\";\nimport { formatVariantName } from \"../formatVariantName.js\";\n\n// Define schema types for internal use\nconst SchemaDefKind = {\n RECORD: \"record\",\n UNION: \"union\",\n} as const;\n\nconst TypeKind = {\n ANY: \"any\",\n ARRAY: \"array\",\n DOC_REF: \"docRef\",\n DOUBLE: \"double\",\n MEDIA_REF: \"mediaRef\",\n OBJECT_REF: \"objectRef\",\n OPTIONAL: \"optional\",\n REF: \"ref\",\n STRING: \"string\",\n USER_REF: \"userRef\",\n} as const;\n\n// Base type definition for schema fields\ninterface BaseSchemaField {\n readonly type: string;\n}\n\ninterface AnyField extends BaseSchemaField {\n readonly type: typeof TypeKind.ANY;\n}\n\ninterface ArrayField extends BaseSchemaField {\n readonly type: typeof TypeKind.ARRAY;\n readonly items: SchemaField;\n}\n\ninterface DocRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.DOC_REF;\n}\n\ninterface DoubleField extends BaseSchemaField {\n readonly type: typeof TypeKind.DOUBLE;\n}\n\ninterface MediaRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.MEDIA_REF;\n}\n\ninterface ObjectRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.OBJECT_REF;\n}\n\ninterface OptionalField extends BaseSchemaField {\n readonly type: typeof TypeKind.OPTIONAL;\n readonly item: SchemaField;\n}\n\ninterface RefField extends BaseSchemaField {\n readonly type: typeof TypeKind.REF;\n readonly refType: \"record\" | \"union\";\n readonly name: string;\n}\n\ninterface StringField extends BaseSchemaField {\n readonly type: typeof TypeKind.STRING;\n}\n\ninterface UserRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.USER_REF;\n}\n\ntype SchemaField =\n | AnyField\n | ArrayField\n | DocRefField\n | DoubleField\n | MediaRefField\n | ObjectRefField\n | OptionalField\n | RefField\n | StringField\n | UserRefField;\n\ninterface RuntimeSchemaRecord {\n readonly type: typeof SchemaDefKind.RECORD;\n readonly name: string;\n readonly docs?: string;\n readonly fields: Readonly<Record<string, SchemaField>>;\n readonly ref?: RefField & {\n readonly refType: \"record\";\n };\n}\n\ninterface RuntimeSchemaUnion {\n readonly type: typeof SchemaDefKind.UNION;\n readonly name?: string;\n readonly variants: Readonly<Record<string, SchemaField>>;\n readonly discriminant: string;\n readonly ref?: RefField & {\n readonly refType: \"union\";\n };\n}\n\ntype RuntimeSchemaItem = RuntimeSchemaRecord | RuntimeSchemaUnion;\ntype RuntimeSchema = Record<string, RuntimeSchemaItem>;\n\n// Type guards\nfunction isRecordSchema(item: RuntimeSchemaItem): item is RuntimeSchemaRecord {\n return item.type === SchemaDefKind.RECORD && \"name\" in item && \"fields\" in item;\n}\n\nfunction isUnionSchema(item: RuntimeSchemaItem): item is RuntimeSchemaUnion {\n return item.type === SchemaDefKind.UNION && \"variants\" in item && \"discriminant\" in item;\n}\n\nfunction isRefField(field: SchemaField): field is RefField {\n return field.type === TypeKind.REF && \"refType\" in field && \"name\" in field;\n}\n\nfunction isArrayField(field: SchemaField): field is ArrayField {\n return field.type === TypeKind.ARRAY && \"items\" in field;\n}\n\nfunction isOptionalField(field: SchemaField): field is OptionalField {\n return field.type === TypeKind.OPTIONAL && \"item\" in field;\n}\n\nfunction detectUsedRefTypes(schema: RuntimeSchema): Set<string> {\n const refTypes = new Set<string>();\n\n function scanField(field: SchemaField): void {\n switch (field.type) {\n case TypeKind.ARRAY:\n if (isArrayField(field)) {\n scanField(field.items);\n }\n break;\n case TypeKind.DOC_REF:\n refTypes.add(\"DocumentRef\");\n break;\n case TypeKind.MEDIA_REF:\n refTypes.add(\"MediaRef\");\n break;\n case TypeKind.OBJECT_REF:\n refTypes.add(\"ObjectRef\");\n break;\n case TypeKind.OPTIONAL:\n if (isOptionalField(field)) {\n scanField(field.item);\n }\n break;\n case TypeKind.USER_REF:\n refTypes.add(\"UserRef\");\n break;\n }\n }\n\n for (const item of Object.values(schema)) {\n if (isRecordSchema(item)) {\n for (const field of Object.values(item.fields)) {\n scanField(field);\n }\n } else if (isUnionSchema(item)) {\n for (const variant of Object.values(item.variants)) {\n scanField(variant);\n }\n }\n }\n\n return refTypes;\n}\n\nexport function generateTypesFromSchema<T extends ReturnedSchema>(\n schema: Schema<T>,\n): string {\n const runtimeSchema = schema as unknown as RuntimeSchema;\n\n // Detect which ref types are used in the schema\n const usedRefTypes = detectUsedRefTypes(runtimeSchema);\n\n let output = \"// Generated TypeScript interfaces from document schema\\n\";\n\n // Add conditional imports based on which ref types are used\n if (usedRefTypes.size > 0) {\n const refTypesList = Array.from(usedRefTypes).sort().join(\", \");\n output += `import type { ${refTypesList} } from \"@palantir/pack.schema\";\\n`;\n }\n\n output += \"\\n\";\n\n // First pass: generate record interfaces\n for (const [exportName, item] of Object.entries(runtimeSchema)) {\n if (item.type === SchemaDefKind.RECORD && isRecordSchema(item)) {\n output += generateRecordInterface(item, exportName, runtimeSchema);\n output += \"\\n\";\n }\n }\n\n // Second pass: generate union types\n const unionEntries = Object.entries(runtimeSchema).filter(\n ([_, item]) => item.type === SchemaDefKind.UNION && isUnionSchema(item),\n );\n\n unionEntries.forEach(([exportName, item], i) => {\n if (isUnionSchema(item)) {\n const unionOutput = generateUnionType(item, exportName, runtimeSchema);\n if (unionOutput) {\n output += unionOutput;\n // Only add newline if not the last union\n if (i < unionEntries.length - 1) {\n output += \"\\n\";\n }\n }\n }\n });\n\n return output;\n}\n\nfunction generateRecordInterface(\n record: RuntimeSchemaRecord,\n exportName: string,\n schema: RuntimeSchema,\n): string {\n let output = \"\";\n\n if (record.docs) {\n output += `/**\\n * ${record.docs}\\n */\\n`;\n }\n\n output += `export interface ${exportName} {\\n`;\n\n for (const [fieldName, fieldType] of Object.entries(record.fields)) {\n const tsType = convertTypeToTypeScript(fieldType, schema);\n const optional = fieldType.type === TypeKind.OPTIONAL ? \"?\" : \"\";\n output += ` readonly ${fieldName}${optional}: ${tsType};\\n`;\n }\n\n output += \"}\\n\";\n\n return output;\n}\n\nfunction generateUnionType(\n union: RuntimeSchemaUnion,\n exportName: string,\n schema: RuntimeSchema,\n): string {\n let output = \"\";\n const variantInterfaces: Array<{ name: string; discriminatorValue: string }> = [];\n\n // First pass: generate variant interfaces\n for (const [variantName, variantType] of Object.entries(union.variants)) {\n const interfaceName = `${exportName}${formatVariantName(variantName)}`;\n variantInterfaces.push({ name: interfaceName, discriminatorValue: variantName });\n\n if (variantType.type === TypeKind.REF && variantType.refType === \"record\") {\n // Find the corresponding record name in the schema\n const recordName = findRecordExportName(variantType.name, schema);\n if (recordName) {\n output += `export interface ${interfaceName} extends ${recordName} {\\n`;\n output += ` readonly type: \"${variantName}\";\\n`;\n output += \"}\\n\\n\";\n }\n } else {\n // Handle value types\n const tsType = convertTypeToTypeScript(variantType, schema);\n output += `export interface ${interfaceName} {\\n`;\n output += ` readonly type: \"${variantName}\";\\n`;\n output += ` readonly value: ${tsType};\\n`;\n output += \"}\\n\\n\";\n }\n }\n\n // Second pass: generate the union type\n output += `export type ${exportName} = ${variantInterfaces.map(v => v.name).join(\" | \")};\\n\\n`;\n\n // Third pass: generate type guards\n for (let i = 0; i < variantInterfaces.length; i++) {\n const variant = variantInterfaces[i]!;\n output +=\n `export function is${variant.name}(value: ${exportName}): value is ${variant.name} {\\n`;\n output += ` return value.type === \"${variant.discriminatorValue}\";\\n`;\n output += \"}\\n\\n\";\n }\n\n return output;\n}\n\nfunction findRecordExportName(\n recordName: string,\n schema: RuntimeSchema,\n): string | null {\n for (const [exportName, item] of Object.entries(schema)) {\n if (isRecordSchema(item) && item.name === recordName) {\n return exportName;\n }\n }\n return null;\n}\n\nfunction convertTypeToTypeScript(\n fieldType: SchemaField,\n schema?: RuntimeSchema,\n): string {\n switch (fieldType.type) {\n case TypeKind.ANY:\n return \"any\";\n case TypeKind.ARRAY:\n if (isArrayField(fieldType)) {\n return `readonly ${convertTypeToTypeScript(fieldType.items, schema)}[]`;\n }\n return \"readonly unknown[]\";\n case TypeKind.DOC_REF:\n return \"DocumentRef\";\n case TypeKind.DOUBLE:\n return \"number\";\n case TypeKind.MEDIA_REF:\n return \"MediaRef\";\n case TypeKind.OBJECT_REF:\n return \"ObjectRef\";\n case TypeKind.OPTIONAL:\n if (isOptionalField(fieldType)) {\n return convertTypeToTypeScript(fieldType.item, schema);\n }\n return \"unknown\";\n case TypeKind.REF:\n if (isRefField(fieldType) && fieldType.refType === \"record\") {\n const exportName = schema ? findRecordExportName(fieldType.name, schema) : null;\n return exportName || (isRefField(fieldType) ? fieldType.name : \"unknown\");\n } else if (isRefField(fieldType) && fieldType.refType === \"union\") {\n return isRefField(fieldType) ? fieldType.name : \"unknown\";\n }\n return \"unknown\";\n case TypeKind.STRING:\n return \"string\";\n case TypeKind.USER_REF:\n return \"UserRef\";\n default:\n fieldType satisfies never;\n return \"unknown\";\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,iBAAiB,QAAQ,yBAAyB;;AAE3D;AACA,MAAMC,aAAa,GAAG;EACpBC,MAAM,EAAE,QAAQ;EAChBC,KAAK,EAAE;AACT,CAAU;AAEV,MAAMC,QAAQ,GAAG;EACfC,GAAG,EAAE,KAAK;EACVC,KAAK,EAAE,OAAO;EACdC,OAAO,EAAE,QAAQ;EACjBC,MAAM,EAAE,QAAQ;EAChBC,SAAS,EAAE,UAAU;EACrBC,UAAU,EAAE,WAAW;EACvBC,QAAQ,EAAE,UAAU;EACpBC,GAAG,EAAE,KAAK;EACVC,MAAM,EAAE,QAAQ;EAChBC,QAAQ,EAAE;AACZ,CAAU;;AAEV;;AAoFA;AACA,SAASC,cAAcA,CAACC,IAAuB,EAA+B;EAC5E,OAAOA,IAAI,CAACC,IAAI,KAAKhB,aAAa,CAACC,MAAM,IAAI,MAAM,IAAIc,IAAI,IAAI,QAAQ,IAAIA,IAAI;AACjF;AAEA,SAASE,aAAaA,CAACF,IAAuB,EAA8B;EAC1E,OAAOA,IAAI,CAACC,IAAI,KAAKhB,aAAa,CAACE,KAAK,IAAI,UAAU,IAAIa,IAAI,IAAI,cAAc,IAAIA,IAAI;AAC1F;AAEA,SAASG,UAAUA,CAACC,KAAkB,EAAqB;EACzD,OAAOA,KAAK,CAACH,IAAI,KAAKb,QAAQ,CAACQ,GAAG,IAAI,SAAS,IAAIQ,KAAK,IAAI,MAAM,IAAIA,KAAK;AAC7E;AAEA,SAASC,YAAYA,CAACD,KAAkB,E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AAS,CAACY,OAAO,KAAK,QAAQ,EAAE;QAC3D,MAAM1B,UAAU,GAAGrB,MAAM,GAAGiD,oBAAoB,CAACd,SAAS,CAACU,IAAI,EAAE7C,MAAM,CAAC,GAAG,IAAI;QAC/E,OAAOqB,UAAU,KAAK1B,UAAU,CAACwC,SAAS,CAAC,GAAGA,SAAS,CAACU,IAAI,GAAG,SAAS,CAAC;MAC3E,CAAC,MAAM,IAAIlD,UAAU,CAACwC,SAAS,CAAC,IAAIA,SAAS,CAACY,OAAO,KAAK,OAAO,EAAE;QACjE,OAAOpD,UAAU,CAACwC,SAAS,CAAC,GAAGA,SAAS,CAACU,IAAI,GAAG,SAAS;MAC3D;MACA,OAAO,SAAS;IAClB,KAAKjE,QAAQ,CAACS,MAAM;MAClB,OAAO,QAAQ;IACjB,KAAKT,QAAQ,CAACU,QAAQ;MACpB,OAAO,SAAS;IAClB;MAEE,OAAO,SAAS;EACpB;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"generateTypesFromSchema.js","names":["formatVariantName","SchemaDefKind","RECORD","UNION","TypeKind","ANY","ARRAY","DOC_REF","DOUBLE","MEDIA_REF","OBJECT_REF","OPTIONAL","REF","STRING","USER_REF","isRecordSchema","item","type","isUnionSchema","isRefField","field","isArrayField","isOptionalField","detectUsedRefTypes","schema","refTypes","Set","scanField","items","add","Object","values","fields","variant","variants","generateTypesFromSchema","runtimeSchema","usedRefTypes","output","size","refTypesList","Array","from","sort","join","exportName","entries","generateRecordInterface","unionEntries","filter","_","forEach","i","unionOutput","generateUnionType","length","record","docs","fieldName","fieldType","tsType","convertTypeToTypeScript","optional","union","variantInterfaces","variantName","variantType","interfaceName","push","name","discriminatorValue","refType","recordName","findRecordExportName","map","v"],"sources":["generateTypesFromSchema.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ReturnedSchema, Schema } from \"@palantir/pack.schema\";\nimport { formatVariantName } from \"../formatVariantName.js\";\n\n// Define schema types for internal use\nconst SchemaDefKind = {\n RECORD: \"record\",\n UNION: \"union\",\n} as const;\n\nconst TypeKind = {\n ANY: \"any\",\n ARRAY: \"array\",\n DOC_REF: \"docRef\",\n DOUBLE: \"double\",\n MEDIA_REF: \"mediaRef\",\n OBJECT_REF: \"objectRef\",\n OPTIONAL: \"optional\",\n REF: \"ref\",\n STRING: \"string\",\n USER_REF: \"userRef\",\n} as const;\n\n// Base type definition for schema fields\ninterface BaseSchemaField {\n readonly type: string;\n}\n\ninterface AnyField extends BaseSchemaField {\n readonly type: typeof TypeKind.ANY;\n}\n\ninterface ArrayField extends BaseSchemaField {\n readonly type: typeof TypeKind.ARRAY;\n readonly items: SchemaField;\n}\n\ninterface DocRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.DOC_REF;\n}\n\ninterface DoubleField extends BaseSchemaField {\n readonly type: typeof TypeKind.DOUBLE;\n}\n\ninterface MediaRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.MEDIA_REF;\n}\n\ninterface ObjectRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.OBJECT_REF;\n}\n\ninterface OptionalField extends BaseSchemaField {\n readonly type: typeof TypeKind.OPTIONAL;\n readonly item: SchemaField;\n}\n\ninterface RefField extends BaseSchemaField {\n readonly type: typeof TypeKind.REF;\n readonly refType: \"record\" | \"union\";\n readonly name: string;\n}\n\ninterface StringField extends BaseSchemaField {\n readonly type: typeof TypeKind.STRING;\n}\n\ninterface UserRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.USER_REF;\n}\n\ntype SchemaField =\n | AnyField\n | ArrayField\n | DocRefField\n | DoubleField\n | MediaRefField\n | ObjectRefField\n | OptionalField\n | RefField\n | StringField\n | UserRefField;\n\ninterface RuntimeSchemaRecord {\n readonly type: typeof SchemaDefKind.RECORD;\n readonly name: string;\n readonly docs?: string;\n readonly fields: Readonly<Record<string, SchemaField>>;\n readonly ref?: RefField & {\n readonly refType: \"record\";\n };\n}\n\ninterface RuntimeSchemaUnion {\n readonly type: typeof SchemaDefKind.UNION;\n readonly name?: string;\n readonly variants: Readonly<Record<string, SchemaField>>;\n readonly discriminant: string;\n readonly ref?: RefField & {\n readonly refType: \"union\";\n };\n}\n\ntype RuntimeSchemaItem = RuntimeSchemaRecord | RuntimeSchemaUnion;\ntype RuntimeSchema = Record<string, RuntimeSchemaItem>;\n\n// Type guards\nfunction isRecordSchema(item: RuntimeSchemaItem): item is RuntimeSchemaRecord {\n return item.type === SchemaDefKind.RECORD && \"name\" in item && \"fields\" in item;\n}\n\nfunction isUnionSchema(item: RuntimeSchemaItem): item is RuntimeSchemaUnion {\n return item.type === SchemaDefKind.UNION && \"variants\" in item && \"discriminant\" in item;\n}\n\nfunction isRefField(field: SchemaField): field is RefField {\n return field.type === TypeKind.REF && \"refType\" in field && \"name\" in field;\n}\n\nfunction isArrayField(field: SchemaField): field is ArrayField {\n return field.type === TypeKind.ARRAY && \"items\" in field;\n}\n\nfunction isOptionalField(field: SchemaField): field is OptionalField {\n return field.type === TypeKind.OPTIONAL && \"item\" in field;\n}\n\nfunction detectUsedRefTypes(schema: RuntimeSchema): Set<string> {\n const refTypes = new Set<string>();\n\n function scanField(field: SchemaField): void {\n switch (field.type) {\n case TypeKind.ARRAY:\n if (isArrayField(field)) {\n scanField(field.items);\n }\n break;\n case TypeKind.DOC_REF:\n refTypes.add(\"DocumentRef\");\n break;\n case TypeKind.MEDIA_REF:\n refTypes.add(\"MediaRef\");\n break;\n case TypeKind.OBJECT_REF:\n refTypes.add(\"ObjectRef\");\n break;\n case TypeKind.OPTIONAL:\n if (isOptionalField(field)) {\n scanField(field.item);\n }\n break;\n case TypeKind.USER_REF:\n refTypes.add(\"UserRef\");\n break;\n }\n }\n\n for (const item of Object.values(schema)) {\n if (isRecordSchema(item)) {\n for (const field of Object.values(item.fields)) {\n scanField(field);\n }\n } else if (isUnionSchema(item)) {\n for (const variant of Object.values(item.variants)) {\n scanField(variant);\n }\n }\n }\n\n return refTypes;\n}\n\nexport function generateTypesFromSchema<T extends ReturnedSchema>(\n schema: Schema<T>,\n): string {\n const runtimeSchema = schema as unknown as RuntimeSchema;\n\n // Detect which ref types are used in the schema\n const usedRefTypes = detectUsedRefTypes(runtimeSchema);\n\n let output = \"// Generated TypeScript interfaces from document schema\\n\";\n\n // Add conditional imports based on which ref types are used\n if (usedRefTypes.size > 0) {\n const refTypesList = Array.from(usedRefTypes).sort().join(\", \");\n output +=\n `import type { ${refTypesList} } from \"@palantir/pack.document-schema.model-types\";\\n`;\n }\n\n output += \"\\n\";\n\n // First pass: generate record interfaces\n for (const [exportName, item] of Object.entries(runtimeSchema)) {\n if (item.type === SchemaDefKind.RECORD && isRecordSchema(item)) {\n output += generateRecordInterface(item, exportName, runtimeSchema);\n output += \"\\n\";\n }\n }\n\n // Second pass: generate union types\n const unionEntries = Object.entries(runtimeSchema).filter(\n ([_, item]) => item.type === SchemaDefKind.UNION && isUnionSchema(item),\n );\n\n unionEntries.forEach(([exportName, item], i) => {\n if (isUnionSchema(item)) {\n const unionOutput = generateUnionType(item, exportName, runtimeSchema);\n if (unionOutput) {\n output += unionOutput;\n // Only add newline if not the last union\n if (i < unionEntries.length - 1) {\n output += \"\\n\";\n }\n }\n }\n });\n\n return output;\n}\n\nfunction generateRecordInterface(\n record: RuntimeSchemaRecord,\n exportName: string,\n schema: RuntimeSchema,\n): string {\n let output = \"\";\n\n if (record.docs) {\n output += `/**\\n * ${record.docs}\\n */\\n`;\n }\n\n output += `export interface ${exportName} {\\n`;\n\n for (const [fieldName, fieldType] of Object.entries(record.fields)) {\n const tsType = convertTypeToTypeScript(fieldType, schema);\n const optional = fieldType.type === TypeKind.OPTIONAL ? \"?\" : \"\";\n output += ` readonly ${fieldName}${optional}: ${tsType};\\n`;\n }\n\n output += \"}\\n\";\n\n return output;\n}\n\nfunction generateUnionType(\n union: RuntimeSchemaUnion,\n exportName: string,\n schema: RuntimeSchema,\n): string {\n let output = \"\";\n const variantInterfaces: Array<{ name: string; discriminatorValue: string }> = [];\n\n // First pass: generate variant interfaces\n for (const [variantName, variantType] of Object.entries(union.variants)) {\n const interfaceName = `${exportName}${formatVariantName(variantName)}`;\n variantInterfaces.push({ name: interfaceName, discriminatorValue: variantName });\n\n if (variantType.type === TypeKind.REF && variantType.refType === \"record\") {\n // Find the corresponding record name in the schema\n const recordName = findRecordExportName(variantType.name, schema);\n if (recordName) {\n output += `export interface ${interfaceName} extends ${recordName} {\\n`;\n output += ` readonly type: \"${variantName}\";\\n`;\n output += \"}\\n\\n\";\n }\n } else {\n // Handle value types\n const tsType = convertTypeToTypeScript(variantType, schema);\n output += `export interface ${interfaceName} {\\n`;\n output += ` readonly type: \"${variantName}\";\\n`;\n output += ` readonly value: ${tsType};\\n`;\n output += \"}\\n\\n\";\n }\n }\n\n // Second pass: generate the union type\n output += `export type ${exportName} = ${variantInterfaces.map(v => v.name).join(\" | \")};\\n\\n`;\n\n // Third pass: generate type guards\n for (let i = 0; i < variantInterfaces.length; i++) {\n const variant = variantInterfaces[i]!;\n output +=\n `export function is${variant.name}(value: ${exportName}): value is ${variant.name} {\\n`;\n output += ` return value.type === \"${variant.discriminatorValue}\";\\n`;\n output += \"}\\n\\n\";\n }\n\n return output;\n}\n\nfunction findRecordExportName(\n recordName: string,\n schema: RuntimeSchema,\n): string | null {\n for (const [exportName, item] of Object.entries(schema)) {\n if (isRecordSchema(item) && item.name === recordName) {\n return exportName;\n }\n }\n return null;\n}\n\nfunction convertTypeToTypeScript(\n fieldType: SchemaField,\n schema?: RuntimeSchema,\n): string {\n switch (fieldType.type) {\n case TypeKind.ANY:\n return \"any\";\n case TypeKind.ARRAY:\n if (isArrayField(fieldType)) {\n return `readonly ${convertTypeToTypeScript(fieldType.items, schema)}[]`;\n }\n return \"readonly unknown[]\";\n case TypeKind.DOC_REF:\n return \"DocumentRef\";\n case TypeKind.DOUBLE:\n return \"number\";\n case TypeKind.MEDIA_REF:\n return \"MediaRef\";\n case TypeKind.OBJECT_REF:\n return \"ObjectRef\";\n case TypeKind.OPTIONAL:\n if (isOptionalField(fieldType)) {\n return convertTypeToTypeScript(fieldType.item, schema);\n }\n return \"unknown\";\n case TypeKind.REF:\n if (isRefField(fieldType) && fieldType.refType === \"record\") {\n const exportName = schema ? findRecordExportName(fieldType.name, schema) : null;\n return exportName || (isRefField(fieldType) ? fieldType.name : \"unknown\");\n } else if (isRefField(fieldType) && fieldType.refType === \"union\") {\n return isRefField(fieldType) ? fieldType.name : \"unknown\";\n }\n return \"unknown\";\n case TypeKind.STRING:\n return \"string\";\n case TypeKind.USER_REF:\n return \"UserRef\";\n default:\n fieldType satisfies never;\n return \"unknown\";\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,iBAAiB,QAAQ,yBAAyB;;AAE3D;AACA,MAAMC,aAAa,GAAG;EACpBC,MAAM,EAAE,QAAQ;EAChBC,KAAK,EAAE;AACT,CAAU;AAEV,MAAMC,QAAQ,GAAG;EACfC,GAAG,EAAE,KAAK;EACVC,KAAK,EAAE,OAAO;EACdC,OAAO,EAAE,QAAQ;EACjBC,MAAM,EAAE,QAAQ;EAChBC,SAAS,EAAE,UAAU;EACrBC,UAAU,EAAE,WAAW;EACvBC,QAAQ,EAAE,UAAU;EACpBC,GAAG,EAAE,KAAK;EACVC,MAAM,EAAE,QAAQ;EAChBC,QAAQ,EAAE;AACZ,CAAU;;AAEV;;AAoFA;AACA,SAASC,cAAcA,CAACC,IAAuB,EAA+B;EAC5E,OAAOA,IAAI,CAACC,IAAI,K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,OAAO;MACnB,OAAO,aAAa;IACtB,KAAKH,QAAQ,CAACI,MAAM;MAClB,OAAO,QAAQ;IACjB,KAAKJ,QAAQ,CAACK,SAAS;MACrB,OAAO,UAAU;IACnB,KAAKL,QAAQ,CAACM,UAAU;MACtB,OAAO,WAAW;IACpB,KAAKN,QAAQ,CAACO,QAAQ;MACpB,IAAIW,eAAe,CAACqC,SAAS,CAAC,EAAE;QAC9B,OAAOE,uBAAuB,CAACF,SAAS,CAAC3C,IAAI,EAAEQ,MAAM,CAAC;MACxD;MACA,OAAO,SAAS;IAClB,KAAKpB,QAAQ,CAACQ,GAAG;MACf,IAAIO,UAAU,CAACwC,SAAS,CAAC,IAAIA,SAAS,CAACY,OAAO,KAAK,QAAQ,EAAE;QAC3D,MAAM1B,UAAU,GAAGrB,MAAM,GAAGiD,oBAAoB,CAACd,SAAS,CAACU,IAAI,EAAE7C,MAAM,CAAC,GAAG,IAAI;QAC/E,OAAOqB,UAAU,KAAK1B,UAAU,CAACwC,SAAS,CAAC,GAAGA,SAAS,CAACU,IAAI,GAAG,SAAS,CAAC;MAC3E,CAAC,MAAM,IAAIlD,UAAU,CAACwC,SAAS,CAAC,IAAIA,SAAS,CAACY,OAAO,KAAK,OAAO,EAAE;QACjE,OAAOpD,UAAU,CAACwC,SAAS,CAAC,GAAGA,SAAS,CAACU,IAAI,GAAG,SAAS;MAC3D;MACA,OAAO,SAAS;IAClB,KAAKjE,QAAQ,CAACS,MAAM;MAClB,OAAO,QAAQ;IACjB,KAAKT,QAAQ,CAACU,QAAQ;MACpB,OAAO,SAAS;IAClB;MAEE,OAAO,SAAS;EACpB;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refTypes.js","names":[],"sources":["refTypes.ts"],"sourcesContent":["// Generated TypeScript interfaces from document schema\nimport type { DocumentRef, MediaRef, ObjectRef, UserRef } from \"@palantir/pack.schema\";\n\n/**\n * A record containing all reference types\n */\nexport interface Document {\n readonly id: string;\n readonly docRef: DocumentRef;\n readonly userRef: UserRef;\n readonly objectRef: ObjectRef;\n readonly mediaRef: MediaRef;\n readonly optionalDocRef?: DocumentRef;\n readonly docRefArray: readonly DocumentRef[];\n readonly userRefArray: readonly UserRef[];\n}\n\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"refTypes.js","names":[],"sources":["refTypes.ts"],"sourcesContent":["// Generated TypeScript interfaces from document schema\nimport type { DocumentRef, MediaRef, ObjectRef, UserRef } from \"@palantir/pack.document-schema.model-types\";\n\n/**\n * A record containing all reference types\n */\nexport interface Document {\n readonly id: string;\n readonly docRef: DocumentRef;\n readonly userRef: UserRef;\n readonly objectRef: ObjectRef;\n readonly mediaRef: MediaRef;\n readonly optionalDocRef?: DocumentRef;\n readonly docRefArray: readonly DocumentRef[];\n readonly userRefArray: readonly UserRef[];\n}\n\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateModelsFromIr.test.d.ts","sourceRoot":"","sources":["../../../../../src/utils/ir/__tests__/generateModelsFromIr.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypesFromSchema.d.ts","sourceRoot":"","sources":["../../../../src/utils/schema/generateTypesFromSchema.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AA4KpE,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,cAAc,EAC9D,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAChB,MAAM,
|
|
1
|
+
{"version":3,"file":"generateTypesFromSchema.d.ts","sourceRoot":"","sources":["../../../../src/utils/schema/generateTypesFromSchema.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AA4KpE,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,cAAc,EAC9D,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAChB,MAAM,CA4CR"}
|