@eide/foir-cli 0.1.16 → 0.1.17
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/dist/codegen/field-mapping.d.ts +1 -0
- package/dist/codegen/field-mapping.d.ts.map +1 -1
- package/dist/codegen/field-mapping.js +8 -0
- package/dist/codegen/generators/customer-profile-hooks.d.ts +5 -0
- package/dist/codegen/generators/customer-profile-hooks.d.ts.map +1 -0
- package/dist/codegen/generators/customer-profile-hooks.js +78 -0
- package/dist/codegen/generators/customer-profile-loaders.d.ts +5 -0
- package/dist/codegen/generators/customer-profile-loaders.d.ts.map +1 -0
- package/dist/codegen/generators/customer-profile-loaders.js +67 -0
- package/dist/codegen/generators/customer-profile-operations.d.ts +5 -0
- package/dist/codegen/generators/customer-profile-operations.d.ts.map +1 -0
- package/dist/codegen/generators/customer-profile-operations.js +126 -0
- package/dist/codegen/generators/public-schema-content.d.ts +14 -0
- package/dist/codegen/generators/public-schema-content.d.ts.map +1 -0
- package/dist/codegen/generators/public-schema-content.js +22 -0
- package/dist/codegen/generators/react-hooks-index.d.ts +6 -0
- package/dist/codegen/generators/react-hooks-index.d.ts.map +1 -0
- package/dist/codegen/generators/react-hooks-index.js +20 -0
- package/dist/codegen/generators/react-hooks.d.ts +7 -0
- package/dist/codegen/generators/react-hooks.d.ts.map +1 -0
- package/dist/codegen/generators/react-hooks.js +139 -0
- package/dist/codegen/generators/remix-loaders-index.d.ts +6 -0
- package/dist/codegen/generators/remix-loaders-index.d.ts.map +1 -0
- package/dist/codegen/generators/remix-loaders-index.js +20 -0
- package/dist/codegen/generators/remix-loaders.d.ts +7 -0
- package/dist/codegen/generators/remix-loaders.d.ts.map +1 -0
- package/dist/codegen/generators/remix-loaders.js +107 -0
- package/dist/codegen/generators/static-documents.d.ts +14 -0
- package/dist/codegen/generators/static-documents.d.ts.map +1 -0
- package/dist/codegen/generators/static-documents.js +728 -0
- package/dist/codegen/generators/typed-operations-common.d.ts +6 -0
- package/dist/codegen/generators/typed-operations-common.d.ts.map +1 -0
- package/dist/codegen/generators/typed-operations-common.js +74 -0
- package/dist/codegen/generators/typed-operations-index.d.ts +6 -0
- package/dist/codegen/generators/typed-operations-index.d.ts.map +1 -0
- package/dist/codegen/generators/typed-operations-index.js +22 -0
- package/dist/codegen/generators/typed-operations.d.ts +11 -0
- package/dist/codegen/generators/typed-operations.d.ts.map +1 -0
- package/dist/codegen/generators/typed-operations.js +251 -0
- package/dist/commands/pull.d.ts.map +1 -1
- package/dist/commands/pull.js +135 -25
- package/dist/config/pull-config.d.ts +6 -0
- package/dist/config/pull-config.d.ts.map +1 -1
- package/dist/config/pull-config.js +50 -1
- package/dist/config/types.d.ts +23 -0
- package/dist/config/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates the shared _common.ts file for typed operations.
|
|
3
|
+
* Contains generic wrapper types used by all per-model operation modules.
|
|
4
|
+
*/
|
|
5
|
+
export function generateTypedOperationsCommon() {
|
|
6
|
+
return `/**
|
|
7
|
+
* Shared types for typed GraphQL operations.
|
|
8
|
+
*
|
|
9
|
+
* @generated by foir — DO NOT EDIT MANUALLY
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** A record with strongly-typed data. */
|
|
13
|
+
export interface BaseRecord<T> {
|
|
14
|
+
id: string;
|
|
15
|
+
modelKey: string;
|
|
16
|
+
naturalKey: string | null;
|
|
17
|
+
data: T;
|
|
18
|
+
metadata: Record<string, unknown> | null;
|
|
19
|
+
publishedVersionNumber: number | null;
|
|
20
|
+
publishedAt: string | null;
|
|
21
|
+
versionNumber: number | null;
|
|
22
|
+
changeDescription: string | null;
|
|
23
|
+
createdAt: string;
|
|
24
|
+
updatedAt: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Resolved content wrapping strongly-typed data. */
|
|
28
|
+
export interface ResolvedContent<T> {
|
|
29
|
+
content: T;
|
|
30
|
+
record: { id: string; modelKey: string; naturalKey: string | null };
|
|
31
|
+
version: { id: string; versionNumber: number } | null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Paginated list result. */
|
|
35
|
+
export interface PaginatedResult<T> {
|
|
36
|
+
items: BaseRecord<T>[];
|
|
37
|
+
total: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Result of a createRecord mutation. */
|
|
41
|
+
export interface CreateRecordResult<T> {
|
|
42
|
+
record: BaseRecord<T>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Result of an updateRecord mutation. */
|
|
46
|
+
export interface UpdateRecordResult<T> {
|
|
47
|
+
record: BaseRecord<T>;
|
|
48
|
+
matched: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Result of a deleteRecord mutation. */
|
|
52
|
+
export interface DeleteRecordResult {
|
|
53
|
+
id: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Share resource type. */
|
|
57
|
+
export interface ShareResult {
|
|
58
|
+
id: string;
|
|
59
|
+
resourceType: string;
|
|
60
|
+
permission: string;
|
|
61
|
+
status: string;
|
|
62
|
+
acceptedAt: string | null;
|
|
63
|
+
declinedAt: string | null;
|
|
64
|
+
expiresAt: string | null;
|
|
65
|
+
createdAt: string;
|
|
66
|
+
revokedAt: string | null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** A share that includes the shared record. */
|
|
70
|
+
export interface ShareWithRecord<T> extends ShareResult {
|
|
71
|
+
record: BaseRecord<T>;
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates the operations/index.ts barrel re-export file.
|
|
3
|
+
*/
|
|
4
|
+
import type { CodegenModel } from '../fetch-models.js';
|
|
5
|
+
export declare function generateTypedOperationsIndex(models: CodegenModel[], hasCustomerProfile: boolean): string;
|
|
6
|
+
//# sourceMappingURL=typed-operations-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-operations-index.d.ts","sourceRoot":"","sources":["../../../src/codegen/generators/typed-operations-index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,YAAY,EAAE,EACtB,kBAAkB,EAAE,OAAO,GAC1B,MAAM,CAsBR"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates the operations/index.ts barrel re-export file.
|
|
3
|
+
*/
|
|
4
|
+
export function generateTypedOperationsIndex(models, hasCustomerProfile) {
|
|
5
|
+
const lines = [];
|
|
6
|
+
lines.push(`/**
|
|
7
|
+
* Typed GraphQL operations.
|
|
8
|
+
*
|
|
9
|
+
* @generated by foir — DO NOT EDIT MANUALLY
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export * from './_common.js';
|
|
13
|
+
`);
|
|
14
|
+
for (const model of models) {
|
|
15
|
+
lines.push(`export * from './${model.key}.js';`);
|
|
16
|
+
}
|
|
17
|
+
if (hasCustomerProfile) {
|
|
18
|
+
lines.push(`export * from './customer-profile.js';`);
|
|
19
|
+
}
|
|
20
|
+
lines.push('');
|
|
21
|
+
return lines.join('\n');
|
|
22
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates per-model typed operation modules.
|
|
3
|
+
* Each module exports gql tagged templates + typed Variables/Result interfaces.
|
|
4
|
+
*/
|
|
5
|
+
import type { CodegenModel } from '../fetch-models.js';
|
|
6
|
+
export declare function generateTypedOperations(model: CodegenModel, typesRelPath: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Compute the relative import path from the operations dir to the types dir.
|
|
9
|
+
*/
|
|
10
|
+
export declare function computeTypesRelPath(opsDir: string, typesDir: string): string;
|
|
11
|
+
//# sourceMappingURL=typed-operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-operations.d.ts","sourceRoot":"","sources":["../../../src/codegen/generators/typed-operations.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,YAAY,EACnB,YAAY,EAAE,MAAM,GACnB,MAAM,CA4QR;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,MAAM,CAGR"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates per-model typed operation modules.
|
|
3
|
+
* Each module exports gql tagged templates + typed Variables/Result interfaces.
|
|
4
|
+
*/
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { toPascalCase, toUpperSnakeCase } from '../field-mapping.js';
|
|
7
|
+
export function generateTypedOperations(model, typesRelPath) {
|
|
8
|
+
const typeName = toPascalCase(model.key);
|
|
9
|
+
const upperSnake = toUpperSnakeCase(model.key);
|
|
10
|
+
const pluralName = model.pluralName
|
|
11
|
+
? toPascalCase(model.pluralName.replace(/\s+/g, ''))
|
|
12
|
+
: `${typeName}s`;
|
|
13
|
+
const pluralUpperSnake = model.pluralName
|
|
14
|
+
? toUpperSnakeCase(model.pluralName.replace(/\s+/g, ''))
|
|
15
|
+
: `${upperSnake}S`;
|
|
16
|
+
const dataType = `${typeName}Data`;
|
|
17
|
+
const lines = [];
|
|
18
|
+
lines.push(`/**
|
|
19
|
+
* Typed operations for ${model.name ?? model.key}
|
|
20
|
+
*
|
|
21
|
+
* @generated by foir — DO NOT EDIT MANUALLY
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import type { ${dataType} } from '${typesRelPath}/models/${model.key}.js';
|
|
25
|
+
import type {
|
|
26
|
+
BaseRecord,
|
|
27
|
+
ResolvedContent,
|
|
28
|
+
PaginatedResult,
|
|
29
|
+
CreateRecordResult,
|
|
30
|
+
UpdateRecordResult,
|
|
31
|
+
DeleteRecordResult,${model.config.sharing?.enabled ? '\n ShareResult,\n ShareWithRecord,' : ''}
|
|
32
|
+
} from './_common.js';
|
|
33
|
+
`);
|
|
34
|
+
// Type alias
|
|
35
|
+
lines.push(`export type ${typeName}Record = BaseRecord<${dataType}>;`);
|
|
36
|
+
lines.push('');
|
|
37
|
+
// GET query
|
|
38
|
+
lines.push(`export const GET_${upperSnake} = \`
|
|
39
|
+
query Get${typeName}($id: ID!, $locale: String, $preview: Boolean) {
|
|
40
|
+
record(id: $id) {
|
|
41
|
+
id modelKey naturalKey data metadata
|
|
42
|
+
publishedVersionNumber publishedAt versionNumber changeDescription
|
|
43
|
+
createdAt updatedAt
|
|
44
|
+
resolved(locale: $locale, preview: $preview) {
|
|
45
|
+
content
|
|
46
|
+
record { id modelKey naturalKey }
|
|
47
|
+
version { id versionNumber }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
\`;`);
|
|
52
|
+
lines.push('');
|
|
53
|
+
lines.push(`export interface Get${typeName}Variables {
|
|
54
|
+
id: string;
|
|
55
|
+
locale?: string;
|
|
56
|
+
preview?: boolean;
|
|
57
|
+
}`);
|
|
58
|
+
lines.push('');
|
|
59
|
+
lines.push(`export interface Get${typeName}Result {
|
|
60
|
+
record: ${typeName}Record & {
|
|
61
|
+
resolved: ResolvedContent<${dataType}> | null;
|
|
62
|
+
} | null;
|
|
63
|
+
}`);
|
|
64
|
+
lines.push('');
|
|
65
|
+
// GET BY KEY query
|
|
66
|
+
lines.push(`export const GET_${upperSnake}_BY_KEY = \`
|
|
67
|
+
query Get${typeName}ByKey($naturalKey: String!, $locale: String, $preview: Boolean) {
|
|
68
|
+
recordByKey(modelKey: "${model.key}", naturalKey: $naturalKey) {
|
|
69
|
+
id modelKey naturalKey data metadata
|
|
70
|
+
publishedVersionNumber publishedAt versionNumber changeDescription
|
|
71
|
+
createdAt updatedAt
|
|
72
|
+
resolved(locale: $locale, preview: $preview) {
|
|
73
|
+
content
|
|
74
|
+
record { id modelKey naturalKey }
|
|
75
|
+
version { id versionNumber }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
\`;`);
|
|
80
|
+
lines.push('');
|
|
81
|
+
lines.push(`export interface Get${typeName}ByKeyVariables {
|
|
82
|
+
naturalKey: string;
|
|
83
|
+
locale?: string;
|
|
84
|
+
preview?: boolean;
|
|
85
|
+
}`);
|
|
86
|
+
lines.push('');
|
|
87
|
+
lines.push(`export interface Get${typeName}ByKeyResult {
|
|
88
|
+
recordByKey: ${typeName}Record & {
|
|
89
|
+
resolved: ResolvedContent<${dataType}> | null;
|
|
90
|
+
} | null;
|
|
91
|
+
}`);
|
|
92
|
+
lines.push('');
|
|
93
|
+
// LIST query
|
|
94
|
+
lines.push(`export const LIST_${pluralUpperSnake} = \`
|
|
95
|
+
query List${pluralName}($limit: Int, $offset: Int, $filters: [FilterInput!], $sort: SortInput) {
|
|
96
|
+
records(modelKey: "${model.key}", limit: $limit, offset: $offset, filters: $filters, sort: $sort) {
|
|
97
|
+
items {
|
|
98
|
+
id modelKey naturalKey data metadata
|
|
99
|
+
publishedVersionNumber publishedAt versionNumber changeDescription
|
|
100
|
+
createdAt updatedAt
|
|
101
|
+
}
|
|
102
|
+
total
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
\`;`);
|
|
106
|
+
lines.push('');
|
|
107
|
+
lines.push(`export interface List${pluralName}Variables {
|
|
108
|
+
limit?: number;
|
|
109
|
+
offset?: number;
|
|
110
|
+
filters?: Array<{ field: string; operator: string; value: unknown }>;
|
|
111
|
+
sort?: { field: string; direction: 'ASC' | 'DESC' };
|
|
112
|
+
}`);
|
|
113
|
+
lines.push('');
|
|
114
|
+
lines.push(`export interface List${pluralName}Result {
|
|
115
|
+
records: PaginatedResult<${dataType}>;
|
|
116
|
+
}`);
|
|
117
|
+
lines.push('');
|
|
118
|
+
// CREATE mutation
|
|
119
|
+
lines.push(`export const CREATE_${upperSnake} = \`
|
|
120
|
+
mutation Create${typeName}($input: CreateRecordInput!) {
|
|
121
|
+
createRecord(input: $input) {
|
|
122
|
+
record {
|
|
123
|
+
id modelKey naturalKey data metadata createdAt updatedAt
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
\`;`);
|
|
128
|
+
lines.push('');
|
|
129
|
+
lines.push(`export interface Create${typeName}Variables {
|
|
130
|
+
input: {
|
|
131
|
+
modelKey: string;
|
|
132
|
+
naturalKey?: string;
|
|
133
|
+
data: Partial<${dataType}>;
|
|
134
|
+
metadata?: Record<string, unknown>;
|
|
135
|
+
};
|
|
136
|
+
}`);
|
|
137
|
+
lines.push('');
|
|
138
|
+
lines.push(`export interface Create${typeName}Result {
|
|
139
|
+
createRecord: CreateRecordResult<${dataType}>;
|
|
140
|
+
}`);
|
|
141
|
+
lines.push('');
|
|
142
|
+
// UPDATE mutation
|
|
143
|
+
lines.push(`export const UPDATE_${upperSnake} = \`
|
|
144
|
+
mutation Update${typeName}($input: UpdateRecordInput!) {
|
|
145
|
+
updateRecord(input: $input) {
|
|
146
|
+
record {
|
|
147
|
+
id modelKey naturalKey data metadata createdAt updatedAt
|
|
148
|
+
}
|
|
149
|
+
matched
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
\`;`);
|
|
153
|
+
lines.push('');
|
|
154
|
+
lines.push(`export interface Update${typeName}Variables {
|
|
155
|
+
input: {
|
|
156
|
+
id: string;
|
|
157
|
+
data?: Partial<${dataType}>;
|
|
158
|
+
metadata?: Record<string, unknown>;
|
|
159
|
+
changeDescription?: string;
|
|
160
|
+
};
|
|
161
|
+
}`);
|
|
162
|
+
lines.push('');
|
|
163
|
+
lines.push(`export interface Update${typeName}Result {
|
|
164
|
+
updateRecord: UpdateRecordResult<${dataType}>;
|
|
165
|
+
}`);
|
|
166
|
+
lines.push('');
|
|
167
|
+
// DELETE mutation
|
|
168
|
+
lines.push(`export const DELETE_${upperSnake} = \`
|
|
169
|
+
mutation Delete${typeName}($id: ID!) {
|
|
170
|
+
deleteRecord(id: $id) { id }
|
|
171
|
+
}
|
|
172
|
+
\`;`);
|
|
173
|
+
lines.push('');
|
|
174
|
+
lines.push(`export interface Delete${typeName}Variables {
|
|
175
|
+
id: string;
|
|
176
|
+
}`);
|
|
177
|
+
lines.push('');
|
|
178
|
+
lines.push(`export interface Delete${typeName}Result {
|
|
179
|
+
deleteRecord: DeleteRecordResult;
|
|
180
|
+
}`);
|
|
181
|
+
lines.push('');
|
|
182
|
+
// PUBLISH/UNPUBLISH
|
|
183
|
+
lines.push(`export const PUBLISH_${upperSnake}_VERSION = \`
|
|
184
|
+
mutation Publish${typeName}Version($versionId: ID!) {
|
|
185
|
+
publishVersion(versionId: $versionId)
|
|
186
|
+
}
|
|
187
|
+
\`;`);
|
|
188
|
+
lines.push('');
|
|
189
|
+
lines.push(`export const UNPUBLISH_${upperSnake} = \`
|
|
190
|
+
mutation Unpublish${typeName}($id: ID!) {
|
|
191
|
+
unpublishRecord(id: $id)
|
|
192
|
+
}
|
|
193
|
+
\`;`);
|
|
194
|
+
lines.push('');
|
|
195
|
+
// Sharing operations (conditional)
|
|
196
|
+
if (model.config.sharing?.enabled) {
|
|
197
|
+
lines.push(`// --- Sharing operations ---`);
|
|
198
|
+
lines.push('');
|
|
199
|
+
lines.push(`export const SHARE_${upperSnake} = \`
|
|
200
|
+
mutation Share${typeName}($recordId: ID!, $sharedWithCustomerId: ID!, $permission: SharePermission!) {
|
|
201
|
+
shareRecord(recordId: $recordId, sharedWithCustomerId: $sharedWithCustomerId, permission: $permission) {
|
|
202
|
+
id resourceType permission status acceptedAt declinedAt expiresAt createdAt revokedAt
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
\`;`);
|
|
206
|
+
lines.push('');
|
|
207
|
+
lines.push(`export interface Share${typeName}Variables {
|
|
208
|
+
recordId: string;
|
|
209
|
+
sharedWithCustomerId: string;
|
|
210
|
+
permission: 'VIEW' | 'EDIT' | 'ADMIN';
|
|
211
|
+
}`);
|
|
212
|
+
lines.push('');
|
|
213
|
+
lines.push(`export interface Share${typeName}Result {
|
|
214
|
+
shareRecord: ShareResult;
|
|
215
|
+
}`);
|
|
216
|
+
lines.push('');
|
|
217
|
+
lines.push(`export const ${upperSnake}_SHARES = \`
|
|
218
|
+
query ${typeName}Shares($resourceId: ID!, $status: ShareStatus) {
|
|
219
|
+
shares(resourceType: RECORD, resourceId: $resourceId, status: $status) {
|
|
220
|
+
id resourceType permission status acceptedAt declinedAt expiresAt createdAt revokedAt
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
\`;`);
|
|
224
|
+
lines.push('');
|
|
225
|
+
lines.push(`export const ${pluralUpperSnake}_SHARED_WITH_ME = \`
|
|
226
|
+
query ${pluralName}SharedWithMe($status: ShareStatus) {
|
|
227
|
+
sharedWithMe(resourceType: RECORD, modelKey: "${model.key}", status: $status) {
|
|
228
|
+
id resourceType permission status acceptedAt declinedAt expiresAt createdAt revokedAt
|
|
229
|
+
record {
|
|
230
|
+
id modelKey naturalKey data metadata
|
|
231
|
+
publishedVersionNumber publishedAt versionNumber changeDescription
|
|
232
|
+
createdAt updatedAt
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
\`;`);
|
|
237
|
+
lines.push('');
|
|
238
|
+
lines.push(`export interface ${pluralName}SharedWithMeResult {
|
|
239
|
+
sharedWithMe: ShareWithRecord<${dataType}>[];
|
|
240
|
+
}`);
|
|
241
|
+
lines.push('');
|
|
242
|
+
}
|
|
243
|
+
return lines.join('\n');
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Compute the relative import path from the operations dir to the types dir.
|
|
247
|
+
*/
|
|
248
|
+
export function computeTypesRelPath(opsDir, typesDir) {
|
|
249
|
+
const rel = path.relative(opsDir, typesDir).replace(/\\/g, '/');
|
|
250
|
+
return rel.startsWith('.') ? rel : `./${rel}`;
|
|
251
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull.d.ts","sourceRoot":"","sources":["../../src/commands/pull.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"pull.d.ts","sourceRoot":"","sources":["../../src/commands/pull.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAmCtD,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,aAAa,GAC9B,IAAI,CA+TN"}
|
package/dist/commands/pull.js
CHANGED
|
@@ -17,6 +17,18 @@ import { generateSwiftModelKeys } from '../codegen/generators/swift-model-keys.j
|
|
|
17
17
|
import { generateCustomerProfileTypes } from '../codegen/generators/customer-profile-types.js';
|
|
18
18
|
import { generateSwiftCustomerProfileFile } from '../codegen/generators/swift-customer-profile.js';
|
|
19
19
|
import { generateCustomerProfileDocuments } from '../codegen/generators/customer-profile-documents.js';
|
|
20
|
+
import { generateStaticDocuments } from '../codegen/generators/static-documents.js';
|
|
21
|
+
import { generateTypedOperationsCommon } from '../codegen/generators/typed-operations-common.js';
|
|
22
|
+
import { generateTypedOperations, computeTypesRelPath } from '../codegen/generators/typed-operations.js';
|
|
23
|
+
import { generateTypedOperationsIndex } from '../codegen/generators/typed-operations-index.js';
|
|
24
|
+
import { generateCustomerProfileOperations } from '../codegen/generators/customer-profile-operations.js';
|
|
25
|
+
import { generateReactHooks } from '../codegen/generators/react-hooks.js';
|
|
26
|
+
import { generateReactHooksIndex } from '../codegen/generators/react-hooks-index.js';
|
|
27
|
+
import { generateCustomerProfileHooks } from '../codegen/generators/customer-profile-hooks.js';
|
|
28
|
+
import { generateRemixLoaders } from '../codegen/generators/remix-loaders.js';
|
|
29
|
+
import { generateRemixLoadersIndex } from '../codegen/generators/remix-loaders-index.js';
|
|
30
|
+
import { generateCustomerProfileLoaders } from '../codegen/generators/customer-profile-loaders.js';
|
|
31
|
+
import { fetchPublicSchema } from '../codegen/generators/public-schema-content.js';
|
|
20
32
|
import { writeFiles } from '../codegen/write-files.js';
|
|
21
33
|
export function registerPullCommand(program, globalOpts) {
|
|
22
34
|
program
|
|
@@ -39,12 +51,13 @@ export function registerPullCommand(program, globalOpts) {
|
|
|
39
51
|
swift: cmdOpts.swift,
|
|
40
52
|
};
|
|
41
53
|
const config = await loadPullConfig(flags);
|
|
42
|
-
// Fetch models + customer profile schema
|
|
54
|
+
// Fetch models + customer profile schema + public schema
|
|
43
55
|
const client = await createClient(opts);
|
|
44
56
|
console.log(chalk.dim('Fetching models…'));
|
|
45
|
-
const [allModels, cpSchema] = await Promise.all([
|
|
57
|
+
const [allModels, cpSchema, publicSchema] = await Promise.all([
|
|
46
58
|
fetchModelsForCodegen(client),
|
|
47
59
|
fetchCustomerProfileSchema(client),
|
|
60
|
+
fetchPublicSchema(client),
|
|
48
61
|
]);
|
|
49
62
|
if (allModels.length === 0 && !cpSchema) {
|
|
50
63
|
console.log(chalk.yellow('No models found. Nothing to generate.'));
|
|
@@ -59,7 +72,17 @@ export function registerPullCommand(program, globalOpts) {
|
|
|
59
72
|
const cwd = process.cwd();
|
|
60
73
|
const typesDir = resolve(cwd, config.output.types);
|
|
61
74
|
const docsDir = resolve(cwd, config.output.documents);
|
|
75
|
+
const opsDir = resolve(cwd, config.output.operations);
|
|
76
|
+
const hooksDir = config.output.hooks
|
|
77
|
+
? resolve(cwd, config.output.hooks)
|
|
78
|
+
: null;
|
|
79
|
+
const loadersDir = config.output.loaders
|
|
80
|
+
? resolve(cwd, config.output.loaders)
|
|
81
|
+
: null;
|
|
62
82
|
const files = [];
|
|
83
|
+
const hasCustomerProfile = !!(cpSchema && cpSchema.fields.length > 0);
|
|
84
|
+
const publicModels = models.filter((m) => m.config.publicApi && m.config.records);
|
|
85
|
+
// ─── Types ───────────────────────────────────────────────
|
|
63
86
|
// 1. Static files
|
|
64
87
|
files.push({
|
|
65
88
|
path: resolve(typesDir, 'field-types.ts'),
|
|
@@ -81,22 +104,27 @@ export function registerPullCommand(program, globalOpts) {
|
|
|
81
104
|
path: resolve(typesDir, 'models', 'index.ts'),
|
|
82
105
|
content: generateModelIndex(models),
|
|
83
106
|
});
|
|
84
|
-
// 4. Customer profile types
|
|
85
|
-
if (
|
|
107
|
+
// 4. Customer profile types
|
|
108
|
+
if (hasCustomerProfile) {
|
|
86
109
|
files.push({
|
|
87
110
|
path: resolve(typesDir, 'customer-profile.ts'),
|
|
88
111
|
content: generateCustomerProfileTypes(cpSchema),
|
|
89
112
|
});
|
|
90
113
|
}
|
|
91
|
-
// 5.
|
|
92
|
-
|
|
114
|
+
// 5. Main index
|
|
115
|
+
files.push({
|
|
116
|
+
path: resolve(typesDir, 'index.ts'),
|
|
117
|
+
content: generateMainIndex(hasCustomerProfile),
|
|
118
|
+
});
|
|
119
|
+
// ─── Documents (.graphql) ────────────────────────────────
|
|
120
|
+
// 6. Per-model GraphQL documents
|
|
93
121
|
for (const model of publicModels) {
|
|
94
122
|
files.push({
|
|
95
123
|
path: resolve(docsDir, `${model.key}.graphql`),
|
|
96
124
|
content: generateModelDocuments(model),
|
|
97
125
|
});
|
|
98
126
|
}
|
|
99
|
-
//
|
|
127
|
+
// 6a. Shared fragments
|
|
100
128
|
const hasSharingModels = publicModels.some((m) => m.config.sharing?.enabled);
|
|
101
129
|
if (hasSharingModels) {
|
|
102
130
|
files.push({
|
|
@@ -104,31 +132,101 @@ export function registerPullCommand(program, globalOpts) {
|
|
|
104
132
|
content: generateSharedFragments(),
|
|
105
133
|
});
|
|
106
134
|
}
|
|
107
|
-
//
|
|
135
|
+
// 6b. Customer profile GraphQL documents
|
|
108
136
|
files.push({
|
|
109
137
|
path: resolve(docsDir, 'customer-profile.graphql'),
|
|
110
138
|
content: generateCustomerProfileDocuments(),
|
|
111
139
|
});
|
|
112
|
-
//
|
|
113
|
-
const
|
|
140
|
+
// 6c. Static domain documents
|
|
141
|
+
const staticDocs = generateStaticDocuments(config.domains);
|
|
142
|
+
for (const doc of staticDocs) {
|
|
143
|
+
files.push({
|
|
144
|
+
path: resolve(docsDir, doc.filename),
|
|
145
|
+
content: doc.content,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
// 6d. Public schema (for consumer codegen)
|
|
149
|
+
if (publicSchema) {
|
|
150
|
+
files.push({
|
|
151
|
+
path: resolve(docsDir, 'public-schema.graphql'),
|
|
152
|
+
content: publicSchema,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
// ─── Typed Operations ────────────────────────────────────
|
|
156
|
+
// 7. Operations common types
|
|
157
|
+
const typesRelPath = computeTypesRelPath(opsDir, typesDir);
|
|
114
158
|
files.push({
|
|
115
|
-
path: resolve(
|
|
116
|
-
content:
|
|
159
|
+
path: resolve(opsDir, '_common.ts'),
|
|
160
|
+
content: generateTypedOperationsCommon(),
|
|
161
|
+
});
|
|
162
|
+
// 7a. Per-model typed operations
|
|
163
|
+
for (const model of publicModels) {
|
|
164
|
+
files.push({
|
|
165
|
+
path: resolve(opsDir, `${model.key}.ts`),
|
|
166
|
+
content: generateTypedOperations(model, typesRelPath),
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
// 7b. Customer profile operations
|
|
170
|
+
if (hasCustomerProfile) {
|
|
171
|
+
files.push({
|
|
172
|
+
path: resolve(opsDir, 'customer-profile.ts'),
|
|
173
|
+
content: generateCustomerProfileOperations(typesRelPath),
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
// 7c. Operations index
|
|
177
|
+
files.push({
|
|
178
|
+
path: resolve(opsDir, 'index.ts'),
|
|
179
|
+
content: generateTypedOperationsIndex(publicModels, hasCustomerProfile),
|
|
117
180
|
});
|
|
118
|
-
//
|
|
181
|
+
// ─── React Hooks (when target includes 'react') ─────────
|
|
182
|
+
if (hooksDir) {
|
|
183
|
+
for (const model of publicModels) {
|
|
184
|
+
files.push({
|
|
185
|
+
path: resolve(hooksDir, `${model.key}.ts`),
|
|
186
|
+
content: generateReactHooks(model),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if (hasCustomerProfile) {
|
|
190
|
+
files.push({
|
|
191
|
+
path: resolve(hooksDir, 'customer-profile.ts'),
|
|
192
|
+
content: generateCustomerProfileHooks(),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
files.push({
|
|
196
|
+
path: resolve(hooksDir, 'index.ts'),
|
|
197
|
+
content: generateReactHooksIndex(publicModels, hasCustomerProfile),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
// ─── Remix Loaders (when target includes 'remix') ───────
|
|
201
|
+
if (loadersDir) {
|
|
202
|
+
for (const model of publicModels) {
|
|
203
|
+
files.push({
|
|
204
|
+
path: resolve(loadersDir, `${model.key}.ts`),
|
|
205
|
+
content: generateRemixLoaders(model),
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
if (hasCustomerProfile) {
|
|
209
|
+
files.push({
|
|
210
|
+
path: resolve(loadersDir, 'customer-profile.ts'),
|
|
211
|
+
content: generateCustomerProfileLoaders(),
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
files.push({
|
|
215
|
+
path: resolve(loadersDir, 'index.ts'),
|
|
216
|
+
content: generateRemixLoadersIndex(publicModels, hasCustomerProfile),
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
// ─── Swift (when configured) ────────────────────────────
|
|
119
220
|
if (config.output.swift) {
|
|
120
221
|
const swiftDir = resolve(cwd, config.output.swift);
|
|
121
|
-
// Shared types
|
|
122
222
|
files.push({
|
|
123
223
|
path: resolve(swiftDir, 'FieldTypes.swift'),
|
|
124
224
|
content: generateSwiftFieldTypesFile(),
|
|
125
225
|
});
|
|
126
|
-
// Model keys
|
|
127
226
|
files.push({
|
|
128
227
|
path: resolve(swiftDir, 'ModelKeys.swift'),
|
|
129
228
|
content: generateSwiftModelKeys(models),
|
|
130
229
|
});
|
|
131
|
-
// Per-model Swift files
|
|
132
230
|
for (const model of models) {
|
|
133
231
|
const swiftTypeName = toPascalCase(model.key);
|
|
134
232
|
files.push({
|
|
@@ -136,7 +234,6 @@ export function registerPullCommand(program, globalOpts) {
|
|
|
136
234
|
content: generateSwiftModelFile(model),
|
|
137
235
|
});
|
|
138
236
|
}
|
|
139
|
-
// Customer profile Swift file
|
|
140
237
|
if (hasCustomerProfile) {
|
|
141
238
|
files.push({
|
|
142
239
|
path: resolve(swiftDir, 'CustomerProfile.swift'),
|
|
@@ -144,7 +241,8 @@ export function registerPullCommand(program, globalOpts) {
|
|
|
144
241
|
});
|
|
145
242
|
}
|
|
146
243
|
}
|
|
147
|
-
//
|
|
244
|
+
// ─── Output ─────────────────────────────────────────────
|
|
245
|
+
// Dry run
|
|
148
246
|
if (config.dryRun) {
|
|
149
247
|
console.log(chalk.bold('\nDry run — files that would be generated:\n'));
|
|
150
248
|
for (const file of files) {
|
|
@@ -158,17 +256,29 @@ export function registerPullCommand(program, globalOpts) {
|
|
|
158
256
|
await writeFiles(files, config.prettier);
|
|
159
257
|
// Summary
|
|
160
258
|
const modelCount = models.length;
|
|
161
|
-
const docCount = publicModels.length;
|
|
162
|
-
const
|
|
259
|
+
const docCount = publicModels.length + staticDocs.length;
|
|
260
|
+
const opsCount = publicModels.length + (hasCustomerProfile ? 1 : 0) + 2; // +2 for _common + index
|
|
261
|
+
const hookCount = hooksDir
|
|
262
|
+
? publicModels.length + (hasCustomerProfile ? 1 : 0) + 1
|
|
263
|
+
: 0;
|
|
264
|
+
const loaderCount = loadersDir
|
|
265
|
+
? publicModels.length + (hasCustomerProfile ? 1 : 0) + 1
|
|
266
|
+
: 0;
|
|
267
|
+
const swiftCount = config.output.swift ? models.length + 2 : 0;
|
|
163
268
|
const cpSuffix = hasCustomerProfile ? ', customer profile' : '';
|
|
164
269
|
console.log(chalk.green(`\nGenerated ${files.length} file(s)`) +
|
|
165
|
-
chalk.dim(` (${modelCount}
|
|
166
|
-
console.log(chalk.dim(` Types:
|
|
167
|
-
|
|
168
|
-
|
|
270
|
+
chalk.dim(` (${modelCount} type(s), ${docCount} document(s), ${opsCount} operation(s)${cpSuffix}${hookCount > 0 ? `, ${hookCount} hook(s)` : ''}${loaderCount > 0 ? `, ${loaderCount} loader(s)` : ''}${swiftCount > 0 ? `, ${swiftCount} Swift file(s)` : ''})`));
|
|
271
|
+
console.log(chalk.dim(` Types: ${typesDir}`));
|
|
272
|
+
console.log(chalk.dim(` Documents: ${docsDir}`));
|
|
273
|
+
console.log(chalk.dim(` Operations: ${opsDir}`));
|
|
274
|
+
if (hooksDir) {
|
|
275
|
+
console.log(chalk.dim(` Hooks: ${hooksDir}`));
|
|
276
|
+
}
|
|
277
|
+
if (loadersDir) {
|
|
278
|
+
console.log(chalk.dim(` Loaders: ${loadersDir}`));
|
|
169
279
|
}
|
|
170
280
|
if (config.output.swift) {
|
|
171
|
-
console.log(chalk.dim(` Swift:
|
|
281
|
+
console.log(chalk.dim(` Swift: ${resolve(cwd, config.output.swift)}`));
|
|
172
282
|
}
|
|
173
283
|
}));
|
|
174
284
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pull config loader — searches for foir.config.ts / .foirrc.ts and merges with CLI flags.
|
|
3
3
|
*/
|
|
4
|
+
import type { CodegenTarget, DomainConfig } from './types.js';
|
|
4
5
|
export interface PullCliFlags {
|
|
5
6
|
config?: string;
|
|
6
7
|
only?: string;
|
|
@@ -13,8 +14,13 @@ export interface ResolvedPullConfig {
|
|
|
13
14
|
output: {
|
|
14
15
|
types: string;
|
|
15
16
|
documents: string;
|
|
17
|
+
operations: string;
|
|
18
|
+
hooks?: string;
|
|
19
|
+
loaders?: string;
|
|
16
20
|
swift?: string;
|
|
17
21
|
};
|
|
22
|
+
targets: CodegenTarget[];
|
|
23
|
+
domains: Required<DomainConfig>;
|
|
18
24
|
only: string[];
|
|
19
25
|
includeInline: boolean;
|
|
20
26
|
prettier: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pull-config.d.ts","sourceRoot":"","sources":["../../src/config/pull-config.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"pull-config.d.ts","sourceRoot":"","sources":["../../src/config/pull-config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAGV,aAAa,EACb,YAAY,EACb,MAAM,YAAY,CAAC;AAuDpB,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,kBAAkB,CAAC,CAqE7B"}
|