@eide/foir-cli 0.1.32 → 0.1.33

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.
@@ -20,6 +20,11 @@ export interface FieldSchemaForGen {
20
20
  }
21
21
  export declare function getFieldType(field: FieldSchemaForGen, mode?: 'output' | 'input'): string;
22
22
  export declare function getRequiredImports(fields: FieldSchemaForGen[]): Set<string>;
23
+ /**
24
+ * Extract model keys referenced by reference-type fields via `referenceTypes`.
25
+ * Used to generate parameterized `ReferenceValue<Partial<ModelData>>` types.
26
+ */
27
+ export declare function getReferenceTypeModelRefs(fields: FieldSchemaForGen[]): Set<string>;
23
28
  export declare function getInlineSchemaReferences(fields: FieldSchemaForGen[]): Set<string>;
24
29
  export declare function toCamelCase(str: string): string;
25
30
  export declare function toPascalCase(str: string): string;
@@ -1 +1 @@
1
- {"version":3,"file":"field-mapping.d.ts","sourceRoot":"","sources":["../../src/codegen/field-mapping.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,qBAAqB,aAoBhC,CAAC;AAEH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAoD1D,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,wBAAgB,YAAY,CAC1B,KAAK,EAAE,iBAAiB,EACxB,IAAI,GAAE,QAAQ,GAAG,OAAkB,GAClC,MAAM,CAqCR;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAW3E;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,iBAAiB,EAAE,GAC1B,GAAG,CAAC,MAAM,CAAC,CAcb;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAMpD;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKrD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CA2EjE"}
1
+ {"version":3,"file":"field-mapping.d.ts","sourceRoot":"","sources":["../../src/codegen/field-mapping.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,qBAAqB,aAoBhC,CAAC;AAEH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAoD1D,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,wBAAgB,YAAY,CAC1B,KAAK,EAAE,iBAAiB,EACxB,IAAI,GAAE,QAAQ,GAAG,OAAkB,GAClC,MAAM,CAqCR;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,iBAAiB,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAW3E;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,iBAAiB,EAAE,GAC1B,GAAG,CAAC,MAAM,CAAC,CAUb;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,iBAAiB,EAAE,GAC1B,GAAG,CAAC,MAAM,CAAC,CAcb;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAMpD;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAKrD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CA2EjE"}
@@ -127,6 +127,21 @@ export function getRequiredImports(fields) {
127
127
  }
128
128
  return imports;
129
129
  }
130
+ /**
131
+ * Extract model keys referenced by reference-type fields via `referenceTypes`.
132
+ * Used to generate parameterized `ReferenceValue<Partial<ModelData>>` types.
133
+ */
134
+ export function getReferenceTypeModelRefs(fields) {
135
+ const refs = new Set();
136
+ for (const field of fields) {
137
+ if (field.type === 'reference' && field.options?.referenceTypes) {
138
+ for (const rt of field.options.referenceTypes) {
139
+ refs.add(rt);
140
+ }
141
+ }
142
+ }
143
+ return refs;
144
+ }
130
145
  export function getInlineSchemaReferences(fields) {
131
146
  const refs = new Set();
132
147
  for (const field of fields) {
@@ -10,7 +10,7 @@ export function generateConfigFile() {
10
10
  * @generated by foir — DO NOT EDIT MANUALLY
11
11
  */
12
12
 
13
- import type { FieldDef } from './field-types.js';
13
+ import type { FieldDef, JsonValue } from './field-types.js';
14
14
 
15
15
  /**
16
16
  * Model configuration
@@ -66,7 +66,7 @@ export interface ModelConfig {
66
66
  };
67
67
 
68
68
  /** Lifecycle hooks configuration */
69
- hooks?: Record<string, unknown>;
69
+ hooks?: Record<string, JsonValue>;
70
70
 
71
71
  /** Field definitions */
72
72
  fieldDefs: readonly FieldDef[];
@@ -1 +1 @@
1
- {"version":3,"file":"field-types.d.ts","sourceRoot":"","sources":["../../../src/codegen/generators/field-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wBAAgB,sBAAsB,IAAI,MAAM,CA+U/C"}
1
+ {"version":3,"file":"field-types.d.ts","sourceRoot":"","sources":["../../../src/codegen/generators/field-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wBAAgB,sBAAsB,IAAI,MAAM,CAsV/C"}
@@ -10,12 +10,19 @@ export function generateFieldTypesFile() {
10
10
  * @generated by foir — DO NOT EDIT MANUALLY
11
11
  */
12
12
 
13
+ // =============================================================================
14
+ // JSON-SAFE BASE TYPE
15
+ // =============================================================================
16
+
17
+ /** Recursive JSON-serializable value type. Safe for TanStack Router, Remix, RSC, and other serialization boundaries. */
18
+ export type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
19
+
13
20
  // =============================================================================
14
21
  // VALUE TYPES
15
22
  // =============================================================================
16
23
 
17
24
  /** Rich text content (Lexical JSON format) */
18
- export type RichtextValue = unknown;
25
+ export type RichtextValue = JsonValue;
19
26
 
20
27
  /** Currency value with amount and ISO 4217 code */
21
28
  export interface CurrencyValue {
@@ -63,19 +70,19 @@ export interface LinkRecordReference {
63
70
  naturalKey: string;
64
71
  }
65
72
 
66
- /** Record reference value */
67
- export interface ReferenceValue {
73
+ /** Record reference value (generic TPreview for typed preview data when reference target is known) */
74
+ export interface ReferenceValue<TPreview = Record<string, JsonValue>> {
68
75
  _type: 'reference';
69
76
  _schema: string;
70
77
  naturalKey: string;
71
- _preview?: Record<string, unknown>;
78
+ _preview?: TPreview;
72
79
  }
73
80
 
74
81
  /** Composite/inline value */
75
82
  export interface CompositeValue {
76
83
  _type: 'composite';
77
84
  _schema: string;
78
- fields: Record<string, unknown>;
85
+ fields: Record<string, JsonValue>;
79
86
  }
80
87
 
81
88
  /** A single item in a flexible field array */
@@ -86,8 +93,8 @@ export interface FlexibleFieldItem {
86
93
  _label: string;
87
94
  _required?: boolean;
88
95
  _helpText?: string;
89
- _config?: Record<string, unknown>;
90
- value: unknown;
96
+ _config?: Record<string, JsonValue>;
97
+ value: JsonValue;
91
98
  }
92
99
 
93
100
  // =============================================================================
@@ -159,7 +166,7 @@ export interface ReferenceFilter {
159
166
  export interface FilterInput {
160
167
  field: string;
161
168
  operator: string;
162
- value: unknown;
169
+ value: JsonValue;
163
170
  }
164
171
 
165
172
  export interface SortInput {
@@ -176,7 +183,7 @@ export interface VariantContext {
176
183
  locale?: string;
177
184
  device?: string;
178
185
  region?: string;
179
- contexts?: Record<string, unknown>;
186
+ contexts?: Record<string, JsonValue>;
180
187
  }
181
188
 
182
189
  /** Reference resolution options */
@@ -191,7 +198,7 @@ export interface ResolvedRecord {
191
198
  id: string;
192
199
  modelKey: string;
193
200
  naturalKey: string | null;
194
- metadata?: Record<string, unknown>;
201
+ metadata?: Record<string, JsonValue>;
195
202
  }
196
203
 
197
204
  /** Resolved variant info */
@@ -206,7 +213,7 @@ export interface ResolvedField {
206
213
  type: string;
207
214
  label?: string;
208
215
  required?: boolean;
209
- value: unknown;
216
+ value: JsonValue;
210
217
  }
211
218
 
212
219
  /** Resolved content */
@@ -217,7 +224,7 @@ export interface ResolvedContent {
217
224
  /** Resolution context output */
218
225
  export interface ResolutionContext {
219
226
  locale: string;
220
- contexts: Record<string, unknown>;
227
+ contexts: Record<string, JsonValue>;
221
228
  }
222
229
 
223
230
  /** Base resolved record content */
@@ -237,7 +244,7 @@ export interface BaseFieldDef {
237
244
  label: string;
238
245
  required?: boolean;
239
246
  helpText?: string;
240
- defaultValue?: unknown;
247
+ defaultValue?: JsonValue;
241
248
  }
242
249
 
243
250
  export interface TextFieldDef extends BaseFieldDef {
@@ -1 +1 @@
1
- {"version":3,"file":"model-types.d.ts","sourceRoot":"","sources":["../../../src/codegen/generators/model-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAgBvD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,YAAY,EAAE,GACxB,MAAM,CAyBR"}
1
+ {"version":3,"file":"model-types.d.ts","sourceRoot":"","sources":["../../../src/codegen/generators/model-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAiBvD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,YAAY,EAAE,GACxB,MAAM,CA2BR"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Generates per-model TypeScript files with config object + data interface.
3
3
  */
4
- import { getFieldType, getInlineSchemaReferences, generateFieldDef, sanitizeFieldName, toPascalCase, toCamelCase, FIELD_TYPE_MAPPING, } from '../field-mapping.js';
4
+ import { getFieldType, getInlineSchemaReferences, getReferenceTypeModelRefs, generateFieldDef, sanitizeFieldName, toPascalCase, toCamelCase, FIELD_TYPE_MAPPING, } from '../field-mapping.js';
5
5
  function isInlineOnlyModel(model) {
6
6
  return model.config.inline && !model.config.records;
7
7
  }
@@ -17,7 +17,8 @@ export function generateModelTypes(model, allModels) {
17
17
  const fields = model.fields ?? [];
18
18
  const fieldTypeImports = getFieldTypeImportsForFields(fields);
19
19
  const inlineSchemaRefs = getInlineSchemaReferences(fields);
20
- let code = buildImportStatements(model, fieldTypeImports, inlineSchemaRefs, allModels);
20
+ const referenceModelRefs = getReferenceTypeModelRefs(fields);
21
+ let code = buildImportStatements(model, fieldTypeImports, inlineSchemaRefs, referenceModelRefs, allModels);
21
22
  if (isInlineOnlyModel(model)) {
22
23
  code += generateDataInterface(model, fields, typeName, allModels);
23
24
  return code;
@@ -27,7 +28,7 @@ export function generateModelTypes(model, allModels) {
27
28
  code += generateDataInterface(model, fields, typeName + 'Data', allModels);
28
29
  return code;
29
30
  }
30
- function buildImportStatements(model, fieldTypeImports, inlineSchemaRefs, allModels) {
31
+ function buildImportStatements(model, fieldTypeImports, inlineSchemaRefs, referenceModelRefs, allModels) {
31
32
  const imports = [];
32
33
  if (!isInlineOnlyModel(model)) {
33
34
  imports.push("import type { ModelConfig } from '../config.js';");
@@ -36,7 +37,12 @@ function buildImportStatements(model, fieldTypeImports, inlineSchemaRefs, allMod
36
37
  const types = Array.from(fieldTypeImports).sort().join(', ');
37
38
  imports.push(`import type { ${types} } from '../field-types.js';`);
38
39
  }
39
- for (const refKey of inlineSchemaRefs) {
40
+ // Collect all model refs (inline schemas + reference type targets) to avoid duplicate imports
41
+ const allModelRefKeys = new Set([
42
+ ...inlineSchemaRefs,
43
+ ...referenceModelRefs,
44
+ ]);
45
+ for (const refKey of allModelRefKeys) {
40
46
  if (refKey === model.key)
41
47
  continue; // skip self-reference
42
48
  const refModel = allModels.find((m) => m.key === refKey);
@@ -127,6 +133,24 @@ function generateDataInterface(model, fields, interfaceName, allModels) {
127
133
  fieldType = toPascalCase(field.options.itemType) + 'Data[]';
128
134
  }
129
135
  }
136
+ // Parameterize ReferenceValue with known reference target types for typed _preview
137
+ if (field.type === 'reference' && field.options?.referenceTypes) {
138
+ const refTypes = field.options.referenceTypes;
139
+ const resolvedPreviewTypes = [];
140
+ for (const refKey of refTypes) {
141
+ const targetModel = allModels.find((m) => m.key === refKey);
142
+ if (targetModel) {
143
+ const targetTypeName = isInlineOnlyModel(targetModel)
144
+ ? toPascalCase(refKey)
145
+ : toPascalCase(refKey) + 'Data';
146
+ resolvedPreviewTypes.push(`Partial<${targetTypeName}>`);
147
+ }
148
+ }
149
+ // Only parameterize if all targets resolved — otherwise keep default generic
150
+ if (resolvedPreviewTypes.length === refTypes.length && resolvedPreviewTypes.length > 0) {
151
+ fieldType = `ReferenceValue<${resolvedPreviewTypes.join(' | ')}>`;
152
+ }
153
+ }
130
154
  const optional = field.required ? '' : '?';
131
155
  const comment = field.helpText ? ` /** ${field.helpText} */\n` : '';
132
156
  lines.push(comment + ` ${fieldName}${optional}: ${fieldType};`);
@@ -2,5 +2,5 @@
2
2
  * Generates the shared _common.ts file for typed operations.
3
3
  * Contains generic wrapper types used by all per-model operation modules.
4
4
  */
5
- export declare function generateTypedOperationsCommon(): string;
5
+ export declare function generateTypedOperationsCommon(typesRelPath: string): string;
6
6
  //# sourceMappingURL=typed-operations-common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"typed-operations-common.d.ts","sourceRoot":"","sources":["../../../src/codegen/generators/typed-operations-common.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,6BAA6B,IAAI,MAAM,CAqEtD"}
1
+ {"version":3,"file":"typed-operations-common.d.ts","sourceRoot":"","sources":["../../../src/codegen/generators/typed-operations-common.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAuE1E"}
@@ -2,20 +2,22 @@
2
2
  * Generates the shared _common.ts file for typed operations.
3
3
  * Contains generic wrapper types used by all per-model operation modules.
4
4
  */
5
- export function generateTypedOperationsCommon() {
5
+ export function generateTypedOperationsCommon(typesRelPath) {
6
6
  return `/**
7
7
  * Shared types for typed GraphQL operations.
8
8
  *
9
9
  * @generated by foir — DO NOT EDIT MANUALLY
10
10
  */
11
11
 
12
+ import type { JsonValue } from '${typesRelPath}/field-types.js';
13
+
12
14
  /** A record with strongly-typed data. */
13
15
  export interface BaseRecord<T> {
14
16
  id: string;
15
17
  modelKey: string;
16
18
  naturalKey: string | null;
17
19
  data: T;
18
- metadata: Record<string, unknown> | null;
20
+ metadata: Record<string, JsonValue> | null;
19
21
  publishedVersionNumber: number | null;
20
22
  publishedAt: string | null;
21
23
  versionNumber: number | null;
@@ -1 +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,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG5E"}
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,CA6QR;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG5E"}
@@ -21,6 +21,7 @@ export function generateTypedOperations(model, typesRelPath) {
21
21
  * @generated by foir — DO NOT EDIT MANUALLY
22
22
  */
23
23
 
24
+ import type { JsonValue } from '${typesRelPath}/field-types.js';
24
25
  import type { ${dataType} } from '${typesRelPath}/models/${model.key}.js';
25
26
  import type {
26
27
  BaseRecord,
@@ -107,7 +108,7 @@ import type {
107
108
  lines.push(`export interface List${pluralName}Variables {
108
109
  limit?: number;
109
110
  offset?: number;
110
- filters?: Array<{ field: string; operator: string; value: unknown }>;
111
+ filters?: Array<{ field: string; operator: string; value: JsonValue }>;
111
112
  sort?: { field: string; direction: 'ASC' | 'DESC' };
112
113
  }`);
113
114
  lines.push('');
@@ -131,7 +132,7 @@ import type {
131
132
  modelKey: string;
132
133
  naturalKey?: string;
133
134
  data: Partial<${dataType}>;
134
- metadata?: Record<string, unknown>;
135
+ metadata?: Record<string, JsonValue>;
135
136
  };
136
137
  }`);
137
138
  lines.push('');
@@ -155,7 +156,7 @@ import type {
155
156
  input: {
156
157
  id: string;
157
158
  data?: Partial<${dataType}>;
158
- metadata?: Record<string, unknown>;
159
+ metadata?: Record<string, JsonValue>;
159
160
  changeDescription?: string;
160
161
  };
161
162
  }`);
@@ -1 +1 @@
1
- {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/commands/operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAkBtD,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,aAAa,GAC9B,IAAI,CAsVN"}
1
+ {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/commands/operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAkBtD,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,aAAa,GAC9B,IAAI,CA8ZN"}
@@ -154,6 +154,61 @@ export function registerOperationsCommands(program, globalOpts) {
154
154
  }
155
155
  }
156
156
  }));
157
+ // quota
158
+ operations
159
+ .command('quota <key>')
160
+ .description('Show quota usage for an operation')
161
+ .option('--json', 'JSON output')
162
+ .action(withErrorHandler(globalOpts, async (key) => {
163
+ const opts = globalOpts();
164
+ const client = await createClient(opts);
165
+ // First get the operation to see its quota rules
166
+ const opData = await client.request(GetOperationDocument, { key });
167
+ if (!opData.operation)
168
+ throw new Error(`Operation "${key}" not found.`);
169
+ const quotas = opData.operation.quotas;
170
+ if (!quotas || quotas.length === 0) {
171
+ if (opts.json || opts.jsonl)
172
+ formatOutput({
173
+ operationKey: key,
174
+ quotas: [],
175
+ message: 'No quotas configured',
176
+ }, opts);
177
+ else
178
+ console.log('No quotas configured for this operation.');
179
+ return;
180
+ }
181
+ if (opts.json || opts.jsonl) {
182
+ formatOutput({ operationKey: key, quotas }, opts);
183
+ }
184
+ else {
185
+ console.log(`\nQuota rules for "${key}":\n`);
186
+ const header = [
187
+ 'Segment'.padEnd(20),
188
+ 'Scope'.padEnd(10),
189
+ 'Limit'.padEnd(8),
190
+ 'Window'.padEnd(10),
191
+ ].join(' | ');
192
+ console.log(header);
193
+ console.log('-'.repeat(header.length));
194
+ for (const q of quotas) {
195
+ const segment = q.segmentKey ?? '(default)';
196
+ const limit = q.points === 0 ? '\u221e' : String(q.points);
197
+ const window = q.duration >= 86400
198
+ ? `${q.duration / 86400}d`
199
+ : q.duration >= 3600
200
+ ? `${q.duration / 3600}h`
201
+ : `${q.duration}s`;
202
+ console.log([
203
+ segment.padEnd(20),
204
+ q.scope.padEnd(10),
205
+ limit.padEnd(8),
206
+ window.padEnd(10),
207
+ ].join(' | '));
208
+ }
209
+ console.log('');
210
+ }
211
+ }));
157
212
  // stats
158
213
  operations
159
214
  .command('stats <key>')
@@ -157,7 +157,7 @@ export function registerPullCommand(program, globalOpts) {
157
157
  const typesRelPath = computeTypesRelPath(opsDir, typesDir);
158
158
  files.push({
159
159
  path: resolve(opsDir, '_common.ts'),
160
- content: generateTypedOperationsCommon(),
160
+ content: generateTypedOperationsCommon(typesRelPath),
161
161
  });
162
162
  // 7a. Per-model typed operations
163
163
  for (const model of publicModels) {
@@ -760,6 +760,7 @@ export type CreateOperationInput = {
760
760
  models?: InputMaybe<Array<Scalars['String']['input']>>;
761
761
  name: Scalars['String']['input'];
762
762
  outputSchema?: InputMaybe<Scalars['JSON']['input']>;
763
+ quotas?: InputMaybe<Array<OperationQuotaInput>>;
763
764
  retryPolicy?: InputMaybe<Scalars['JSON']['input']>;
764
765
  streamConfig?: InputMaybe<OperationStreamConfigInput>;
765
766
  timeoutMs?: InputMaybe<Scalars['Int']['input']>;
@@ -2162,6 +2163,11 @@ export type Mutation = {
2162
2163
  * Promotes winning content to the target variant and cleans up experiment artifacts.
2163
2164
  */
2164
2165
  applyExperimentWinner: ApplyWinnerResult;
2166
+ /**
2167
+ * Assign a custom package to a tenant's subscription. Platform admin only.
2168
+ * Creates a minimal subscription if the tenant doesn't have one (no Stripe required).
2169
+ */
2170
+ assignBillingCustomPackage: BillingSubscription;
2165
2171
  batchPublishVersions: BatchPublishResult;
2166
2172
  batchRecordOperations: BatchRecordOperationsResult;
2167
2173
  bulkUpdateRecords: BulkUpdateRecordsResult;
@@ -2614,6 +2620,10 @@ export type MutationApplyExperimentWinnerArgs = {
2614
2620
  experimentId: Scalars['ID']['input'];
2615
2621
  winnerId: Scalars['String']['input'];
2616
2622
  };
2623
+ export type MutationAssignBillingCustomPackageArgs = {
2624
+ customPackageId: Scalars['ID']['input'];
2625
+ tenantId: Scalars['ID']['input'];
2626
+ };
2617
2627
  export type MutationBatchPublishVersionsArgs = {
2618
2628
  batchId?: InputMaybe<Scalars['String']['input']>;
2619
2629
  versionIds: Array<Scalars['ID']['input']>;
@@ -3446,6 +3456,8 @@ export type Operation = {
3446
3456
  models?: Maybe<Array<Scalars['String']['output']>>;
3447
3457
  name: Scalars['String']['output'];
3448
3458
  outputSchema?: Maybe<Scalars['JSON']['output']>;
3459
+ /** Quota rules for rate-limiting operation executions per scope. */
3460
+ quotas?: Maybe<Array<Scalars['JSON']['output']>>;
3449
3461
  retryPolicy?: Maybe<Scalars['JSON']['output']>;
3450
3462
  /** Streaming configuration. Operations with this set support STREAM execution mode. */
3451
3463
  streamConfig?: Maybe<OperationStreamConfig>;
@@ -3495,6 +3507,27 @@ export type OperationList = {
3495
3507
  items: Array<Operation>;
3496
3508
  total: Scalars['Int']['output'];
3497
3509
  };
3510
+ /** Quota rule input for operation create/update */
3511
+ export type OperationQuotaInput = {
3512
+ /** Optional condition expression (RuleExpression as JSON) */
3513
+ condition?: InputMaybe<Scalars['JSON']['input']>;
3514
+ /** Duration window in seconds */
3515
+ duration: Scalars['Int']['input'];
3516
+ /** Max points per duration window (0 = unlimited) */
3517
+ points: Scalars['Int']['input'];
3518
+ /** Scope for quota tracking: customer, user, or tenant */
3519
+ scope: Scalars['String']['input'];
3520
+ /** Segment key to match (null = default/fallback rule) */
3521
+ segmentKey?: InputMaybe<Scalars['String']['input']>;
3522
+ };
3523
+ /** Operation quota usage for the current context */
3524
+ export type OperationQuotaUsage = {
3525
+ consumed: Scalars['Int']['output'];
3526
+ limit?: Maybe<Scalars['Int']['output']>;
3527
+ operationKey: Scalars['String']['output'];
3528
+ remaining?: Maybe<Scalars['Int']['output']>;
3529
+ resetsAt?: Maybe<Scalars['DateTime']['output']>;
3530
+ };
3498
3531
  /** Streaming configuration for an operation */
3499
3532
  export type OperationStreamConfig = {
3500
3533
  /** Max gap between callback chunks in ms (default: 30000) */
@@ -3995,6 +4028,8 @@ export type Query = {
3995
4028
  operationExecutionStats: OperationExecutionStats;
3996
4029
  /** List operation executions with filtering. */
3997
4030
  operationExecutions: OperationExecutionList;
4031
+ /** Get quota usage for an operation in the current context. */
4032
+ operationQuotaUsage?: Maybe<OperationQuotaUsage>;
3998
4033
  /** List operations for the current project. */
3999
4034
  operations: OperationList;
4000
4035
  /** Get the operations signing secret status (masked). */
@@ -4476,6 +4511,9 @@ export type QueryOperationExecutionsArgs = {
4476
4511
  operationKey?: InputMaybe<Scalars['String']['input']>;
4477
4512
  status?: InputMaybe<OperationExecutionStatus>;
4478
4513
  };
4514
+ export type QueryOperationQuotaUsageArgs = {
4515
+ operationKey: Scalars['String']['input'];
4516
+ };
4479
4517
  export type QueryOperationsArgs = {
4480
4518
  category?: InputMaybe<Scalars['String']['input']>;
4481
4519
  isActive?: InputMaybe<Scalars['Boolean']['input']>;
@@ -5714,6 +5752,7 @@ export type UpdateOperationInput = {
5714
5752
  models?: InputMaybe<Array<Scalars['String']['input']>>;
5715
5753
  name?: InputMaybe<Scalars['String']['input']>;
5716
5754
  outputSchema?: InputMaybe<Scalars['JSON']['input']>;
5755
+ quotas?: InputMaybe<Array<OperationQuotaInput>>;
5717
5756
  retryPolicy?: InputMaybe<Scalars['JSON']['input']>;
5718
5757
  streamConfig?: InputMaybe<OperationStreamConfigInput>;
5719
5758
  timeoutMs?: InputMaybe<Scalars['Int']['input']>;