@lark-base-open/base-database-toolchain 1.5.0 → 1.5.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/CHANGELOG.md +9 -0
- package/dist/contract-conversion.js +1 -0
- package/dist/function-schema.d.ts +1 -0
- package/dist/function-schema.js +66 -1
- package/dist/go-adapter.mjs +198 -164
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.5.1] - 2026-12-01
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Report all Functions with contract errors in one run. For unsupported input schema keywords, show their locations and suggest supported alternatives where available.
|
|
8
|
+
- Convert Zod input literals to single-value enums for Edge Functions while preserving existing output, Durable, and runtime-only contracts.
|
|
9
|
+
- Generate contracts for `z.null()` outputs. For Functions previously generated in runtime-only mode because of this issue, run `contracts generate` again if `check` reports `CONTRACT_STALE`.
|
|
10
|
+
- Explain how to place a root-level input union inside a `z.object()` property when generating Function contracts.
|
|
11
|
+
|
|
3
12
|
## [1.5.0] - 2026-11-30
|
|
4
13
|
|
|
5
14
|
### Removed
|
|
@@ -4,6 +4,7 @@ interface SQLParamMeta {
|
|
|
4
4
|
description?: string;
|
|
5
5
|
enum?: unknown[];
|
|
6
6
|
}
|
|
7
|
+
export declare function inputConstToEnum(node: unknown): void;
|
|
7
8
|
export declare function normalizeFunctionInputSchema(value: unknown, source: string): string;
|
|
8
9
|
export declare function sqlParamSchema(param: SQLParamMeta, index: number): {
|
|
9
10
|
enum: unknown[];
|
package/dist/function-schema.js
CHANGED
|
@@ -249,8 +249,70 @@ function validateSchemaNode(value, path, depth, state) {
|
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
|
+
const SCHEMA_MAPS = new Set(['properties', 'patternProperties', '$defs']);
|
|
253
|
+
const SCHEMA_LISTS = new Set(['oneOf', 'anyOf', 'allOf', 'prefixItems']);
|
|
254
|
+
const SCHEMA_SINGLES = new Set([
|
|
255
|
+
'items',
|
|
256
|
+
'additionalProperties',
|
|
257
|
+
'propertyNames',
|
|
258
|
+
'contains',
|
|
259
|
+
'not',
|
|
260
|
+
]);
|
|
261
|
+
// Zod writes literals as `const`, which the Edge inputSchema subset does not
|
|
262
|
+
// accept; a single-value `enum` validates the same values. Output and Durable
|
|
263
|
+
// schemas accept `const` and keep it, so their generated contracts stay stable.
|
|
264
|
+
export function inputConstToEnum(node) {
|
|
265
|
+
if (!node || typeof node !== 'object' || Array.isArray(node))
|
|
266
|
+
return;
|
|
267
|
+
const schema = node;
|
|
268
|
+
if (Object.hasOwn(schema, 'const') && !Object.hasOwn(schema, 'enum')) {
|
|
269
|
+
schema.enum = [schema.const];
|
|
270
|
+
delete schema.const;
|
|
271
|
+
}
|
|
272
|
+
for (const [key, child] of Object.entries(schema)) {
|
|
273
|
+
if (SCHEMA_MAPS.has(key) && child && typeof child === 'object')
|
|
274
|
+
Object.values(child).forEach(inputConstToEnum);
|
|
275
|
+
else if (SCHEMA_LISTS.has(key) && Array.isArray(child))
|
|
276
|
+
child.forEach(inputConstToEnum);
|
|
277
|
+
else if (SCHEMA_SINGLES.has(key))
|
|
278
|
+
inputConstToEnum(child);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const KEYWORD_REPLACEMENTS = {
|
|
282
|
+
const: 'use enum with one value',
|
|
283
|
+
format: 'describe the format and validate it in the handler',
|
|
284
|
+
$ref: 'inline the type; recursive or reused schemas such as z.lazy() and z.json() are not supported in inputs',
|
|
285
|
+
$defs: 'inline the type; recursive or reused schemas such as z.lazy() and z.json() are not supported in inputs',
|
|
286
|
+
propertyNames: 'declare known properties with z.object(); records are not supported in inputs',
|
|
287
|
+
};
|
|
288
|
+
// Lists every unsupported keyword at once, walking the positions the validator
|
|
289
|
+
// descends into, so one generate run names all of them instead of the first.
|
|
290
|
+
function collectUnsupportedKeywords(value, path, out) {
|
|
291
|
+
if (!isRecord(value))
|
|
292
|
+
return;
|
|
293
|
+
for (const keyword of Object.keys(value)) {
|
|
294
|
+
if (ALLOWED_KEYWORDS.has(keyword))
|
|
295
|
+
continue;
|
|
296
|
+
const replacement = KEYWORD_REPLACEMENTS[keyword];
|
|
297
|
+
out.push(`${path}: ${JSON.stringify(keyword)}${replacement ? ` (${replacement})` : ''}`);
|
|
298
|
+
}
|
|
299
|
+
if (isRecord(value.properties))
|
|
300
|
+
for (const [name, child] of Object.entries(value.properties))
|
|
301
|
+
collectUnsupportedKeywords(child, `${path}.properties[${JSON.stringify(name)}]`, out);
|
|
302
|
+
collectUnsupportedKeywords(value.items, `${path}.items`, out);
|
|
303
|
+
collectUnsupportedKeywords(value.additionalProperties, `${path}.additionalProperties`, out);
|
|
304
|
+
for (const key of ['prefixItems', 'oneOf', 'anyOf']) {
|
|
305
|
+
const children = value[key];
|
|
306
|
+
if (Array.isArray(children))
|
|
307
|
+
children.forEach((child, index) => collectUnsupportedKeywords(child, `${path}.${key}[${index}]`, out));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
252
310
|
export function normalizeFunctionInputSchema(value, source) {
|
|
253
311
|
const schema = JSON.stringify(value);
|
|
312
|
+
const unsupported = [];
|
|
313
|
+
collectUnsupportedKeywords(JSON.parse(schema), source, unsupported);
|
|
314
|
+
if (unsupported.length)
|
|
315
|
+
throw new Error(`Invalid inputSchema: ${unsupported.length} unsupported keyword${unsupported.length > 1 ? 's' : ''}: ${unsupported.join('; ')}. Supported keywords: ${[...ALLOWED_KEYWORDS].join(', ')}`);
|
|
254
316
|
validateSchemaNode(JSON.parse(schema), source, 1, { nodes: 0 });
|
|
255
317
|
if (Buffer.byteLength(schema, 'utf8') > MAX_SCHEMA_BYTES) {
|
|
256
318
|
schemaError(source, 'exceeds 32 KiB');
|
|
@@ -578,7 +640,10 @@ export function deriveSQLInputSchema(meta, sql) {
|
|
|
578
640
|
export function checkFaaSInputSchemaContract(value, file) {
|
|
579
641
|
const result = { problems: [], hints: [] };
|
|
580
642
|
if (!isRecord(value) || value.type !== 'object') {
|
|
581
|
-
result.problems.push(
|
|
643
|
+
result.problems.push(isRecord(value) &&
|
|
644
|
+
(value.oneOf !== undefined || value.anyOf !== undefined)
|
|
645
|
+
? 'inputSchema.type must be "object"; a Zod union at the root becomes oneOf/anyOf. Keep the root a z.object() and put the union in a property, for example z.object({ command: z.discriminatedUnion("action", [...]).describe("...") })'
|
|
646
|
+
: 'inputSchema.type must be "object"');
|
|
582
647
|
return result;
|
|
583
648
|
}
|
|
584
649
|
const properties = isRecord(value.properties) ? value.properties : {};
|
package/dist/go-adapter.mjs
CHANGED
|
@@ -23,7 +23,7 @@ import { projectLayout } from './project-layout.js';
|
|
|
23
23
|
import { sourceArchiveEntryIgnored } from './source-archive-inputs.js';
|
|
24
24
|
import { inspectPage } from './page-inspection.js';
|
|
25
25
|
import { parse as parseJSONC } from 'jsonc-parser';
|
|
26
|
-
import { namedSQLParamSchema, checkSQLFunctionParameters, normalizeFunctionInputSchema, checkFaaSInputSchemaContract, } from './function-schema.js';
|
|
26
|
+
import { namedSQLParamSchema, checkSQLFunctionParameters, normalizeFunctionInputSchema, checkFaaSInputSchemaContract, inputConstToEnum, } from './function-schema.js';
|
|
27
27
|
import { checkDeclaredParameters, mutationEnumType, } from './function-params.js';
|
|
28
28
|
import { validateFunctionDescription, functionDescriptionHint, } from './function-description.js';
|
|
29
29
|
import { readMutationMetaItem } from './mutation.js';
|
|
@@ -241,82 +241,105 @@ export async function runCompiler(request) {
|
|
|
241
241
|
schema.description = param.description;
|
|
242
242
|
return schema;
|
|
243
243
|
}
|
|
244
|
-
function collectDatabaseContracts(functions, inputs, bindBatch) {
|
|
244
|
+
function collectDatabaseContracts(functions, inputs, bindBatch, failures) {
|
|
245
245
|
for (const [directory, type] of [
|
|
246
246
|
['database-functions', 1],
|
|
247
247
|
['mutations', 5],
|
|
248
248
|
]) {
|
|
249
249
|
for (const id of entries(path.join(root, directory))) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
meta
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
250
|
+
try {
|
|
251
|
+
const metadata = readJSON(path.join(root, directory, id, 'meta.json'));
|
|
252
|
+
assertMetadataKeys(type === 1 ? 'sql' : 'mutation', id, metadata);
|
|
253
|
+
validateFunctionDescription(metadata.description, metadata.name, path.join(directory, id, 'meta.json'));
|
|
254
|
+
const descriptionHint = functionDescriptionHint(metadata.description, path.join(directory, id, 'meta.json'));
|
|
255
|
+
if (descriptionHint)
|
|
256
|
+
functionHints.push({ ...descriptionHint, functionId: id });
|
|
257
|
+
const file = path.join(directory, id, type === 1 ? 'meta.json' : 'spec.json');
|
|
258
|
+
let params, declared;
|
|
259
|
+
if (type === 1) {
|
|
260
|
+
let meta = metadata.meta;
|
|
261
|
+
if (meta === undefined)
|
|
262
|
+
meta = { params: [] };
|
|
263
|
+
else if (!meta || typeof meta !== 'object' || Array.isArray(meta))
|
|
264
|
+
throw Error(file + ': meta must be an object containing a params array.');
|
|
265
|
+
else if (!Object.hasOwn(meta, 'params'))
|
|
266
|
+
meta = { ...meta, params: [] };
|
|
267
|
+
const sqlPath = safe(path.join(root, directory, id, 'main.sql'));
|
|
268
|
+
// Metadata-only codegen can run before SQL is authored. The Go
|
|
269
|
+
// project check requires complete declarations before any upload.
|
|
270
|
+
let sql;
|
|
271
|
+
if (fs.existsSync(sqlPath) || bindBatch) {
|
|
272
|
+
sql = fs.readFileSync(sqlPath, 'utf8');
|
|
273
|
+
if (bindBatch)
|
|
274
|
+
localSQLSources[id] =
|
|
275
|
+
'sha256:' + digest(JSON.stringify({ sql, meta }));
|
|
276
|
+
}
|
|
277
|
+
params = meta.params ?? [];
|
|
278
|
+
declared = checkSQLFunctionParameters(params, sql, file);
|
|
275
279
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
280
|
+
else {
|
|
281
|
+
readMutationMetaItem(safe(path.join(root, directory, id, 'meta.json')), root);
|
|
282
|
+
params =
|
|
283
|
+
readJSON(path.join(root, directory, id, 'spec.json')).params ??
|
|
284
|
+
[];
|
|
285
|
+
declared = checkDeclaredParameters(params, {
|
|
286
|
+
label: 'spec.params',
|
|
287
|
+
pointer: '/params',
|
|
288
|
+
file,
|
|
289
|
+
enumType: mutationEnumType,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
if (declared.problems.length) {
|
|
293
|
+
if (type !== 1)
|
|
294
|
+
throw Error(declared.problems.join('; '));
|
|
295
|
+
const advice = declared.hints
|
|
296
|
+
.filter((h) => h.kind === 'parameter_declaration')
|
|
297
|
+
.map((h) => h.message);
|
|
298
|
+
throw Error(`${file}: ${[...declared.problems, ...advice].join(' ')}`);
|
|
299
|
+
}
|
|
300
|
+
functionHints.push(...declared.hints.map((hint) => ({ ...hint, functionId: id })));
|
|
301
|
+
const input = {
|
|
302
|
+
type: 'object',
|
|
303
|
+
properties: Object.fromEntries(params.map((p, index) => {
|
|
304
|
+
return [p.name, parameterSchema(p, type, index)];
|
|
305
|
+
})),
|
|
306
|
+
required: params
|
|
307
|
+
.filter((p) => type === 1 || p.required !== false)
|
|
308
|
+
.map((p) => p.name),
|
|
309
|
+
additionalProperties: false,
|
|
310
|
+
};
|
|
311
|
+
functions.push({ functionId: id, functionType: type, input });
|
|
312
|
+
inputs.push({
|
|
313
|
+
functionId: id,
|
|
314
|
+
functionType: type,
|
|
315
|
+
inputSchema: input,
|
|
316
|
+
parameters: params,
|
|
317
|
+
parameterOptions: Object.fromEntries(params.filter((p) => p.enum).map((p) => [p.name, p.enum])),
|
|
288
318
|
});
|
|
289
319
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
throw Error(declared.problems.join('; '));
|
|
293
|
-
const advice = declared.hints
|
|
294
|
-
.filter((h) => h.kind === 'parameter_declaration')
|
|
295
|
-
.map((h) => h.message);
|
|
296
|
-
throw Error(`${file}: ${[...declared.problems, ...advice].join(' ')}`);
|
|
320
|
+
catch (error) {
|
|
321
|
+
contractFailure(failures, path.join(directory, id), error);
|
|
297
322
|
}
|
|
298
|
-
functionHints.push(...declared.hints.map((hint) => ({ ...hint, functionId: id })));
|
|
299
|
-
const input = {
|
|
300
|
-
type: 'object',
|
|
301
|
-
properties: Object.fromEntries(params.map((p, index) => {
|
|
302
|
-
return [p.name, parameterSchema(p, type, index)];
|
|
303
|
-
})),
|
|
304
|
-
required: params
|
|
305
|
-
.filter((p) => type === 1 || p.required !== false)
|
|
306
|
-
.map((p) => p.name),
|
|
307
|
-
additionalProperties: false,
|
|
308
|
-
};
|
|
309
|
-
functions.push({ functionId: id, functionType: type, input });
|
|
310
|
-
inputs.push({
|
|
311
|
-
functionId: id,
|
|
312
|
-
functionType: type,
|
|
313
|
-
inputSchema: input,
|
|
314
|
-
parameters: params,
|
|
315
|
-
parameterOptions: Object.fromEntries(params.filter((p) => p.enum).map((p) => [p.name, p.enum])),
|
|
316
|
-
});
|
|
317
323
|
}
|
|
318
324
|
}
|
|
319
325
|
}
|
|
326
|
+
// Each Function is checked independently, so one generate run reports every
|
|
327
|
+
// failing Function; a stale manifest stays a single project-wide answer.
|
|
328
|
+
function contractFailure(failures, label, error) {
|
|
329
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
330
|
+
if (message.startsWith('CONTRACT_STALE'))
|
|
331
|
+
throw error;
|
|
332
|
+
failures.push(`${label}: ${message}`);
|
|
333
|
+
}
|
|
334
|
+
function throwContractFailures(failures) {
|
|
335
|
+
if (failures.length === 1)
|
|
336
|
+
throw Error(failures[0]);
|
|
337
|
+
if (failures.length)
|
|
338
|
+
throw Error(`${failures.length} Functions have contract problems; fix all of them, then regenerate contracts:\n` +
|
|
339
|
+
failures
|
|
340
|
+
.map((failure, index) => `${index + 1}. ${failure}`)
|
|
341
|
+
.join('\n'));
|
|
342
|
+
}
|
|
320
343
|
async function isolatedCodegen(input) {
|
|
321
344
|
return runSDKCodegen(root, input, server);
|
|
322
345
|
}
|
|
@@ -377,7 +400,7 @@ export async function runCompiler(request) {
|
|
|
377
400
|
normalizeFunctionInputSchema(schema, file);
|
|
378
401
|
const declared = checkFaaSInputSchemaContract(schema, file);
|
|
379
402
|
if (declared.problems.length)
|
|
380
|
-
throw Error(`${file}: ${declared.problems.join('; ')}. Fix
|
|
403
|
+
throw Error(`${file}: ${declared.problems.join('; ')}. Fix this source and regenerate contracts.`);
|
|
381
404
|
functionHints.push(...declared.hints.map((hint) => ({ ...hint, functionId: id })));
|
|
382
405
|
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
|
383
406
|
if (!ajv.validateSchema(schema))
|
|
@@ -483,120 +506,131 @@ export async function runCompiler(request) {
|
|
|
483
506
|
triggerLocations.length = 0;
|
|
484
507
|
triggerCount = 0;
|
|
485
508
|
const changes = [];
|
|
509
|
+
const failures = [];
|
|
486
510
|
for (const kind of ['functions', 'durable'])
|
|
487
511
|
for (const id of entries(path.join(serverRoot, kind))) {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
512
|
+
try {
|
|
513
|
+
const directory = path.join(serverRoot, kind, id), entry = path.join(directory, 'index.ts');
|
|
514
|
+
if (!fs.existsSync(entry))
|
|
515
|
+
throw Error('Missing Function entry ' + id);
|
|
516
|
+
const metaFile = path.join(directory, 'meta.json');
|
|
517
|
+
const declaredMeta = readJSON(safe(metaFile));
|
|
518
|
+
validateFunctionDescription(declaredMeta.description, declaredMeta.name, metaFile);
|
|
519
|
+
const descriptionHint = functionDescriptionHint(declaredMeta.description, metaFile);
|
|
520
|
+
if (descriptionHint)
|
|
521
|
+
functionHints.push({ ...descriptionHint, functionId: id });
|
|
522
|
+
const decl = definition(entry);
|
|
523
|
+
if (!decl) {
|
|
524
|
+
const meta = readJSON(path.join(directory, 'meta.json'));
|
|
525
|
+
if (kind === 'durable')
|
|
526
|
+
throw Error('Durable entry must use defineDurableFunction: ' + id);
|
|
527
|
+
if (meta.inputSchema) {
|
|
528
|
+
validateFunctionInput(meta.inputSchema, id);
|
|
529
|
+
functions.push({
|
|
530
|
+
functionId: id,
|
|
531
|
+
functionType: 2,
|
|
532
|
+
input: meta.inputSchema,
|
|
533
|
+
});
|
|
534
|
+
inputs.push({
|
|
535
|
+
functionId: id,
|
|
536
|
+
functionType: 2,
|
|
537
|
+
inputSchema: meta.inputSchema,
|
|
538
|
+
parameterOptions: {},
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
if (kind === 'functions')
|
|
544
|
+
generatedContractIds.add(id);
|
|
545
|
+
const converted = await schemas(directory, decl);
|
|
546
|
+
const metaPath = path.join(directory, 'meta.json'), meta = readJSON(metaPath);
|
|
547
|
+
if (kind === 'durable')
|
|
548
|
+
converted.events ??= {};
|
|
549
|
+
if (kind === 'durable' && (!converted.input || !converted.output))
|
|
550
|
+
throw Error('Durable contracts must be representable: ' +
|
|
551
|
+
converted.warnings.join('; '));
|
|
552
|
+
const runtimeOnly = kind !== 'durable' &&
|
|
553
|
+
((write
|
|
554
|
+
? request.runtimeOnly
|
|
555
|
+
: meta.contract?.mode === 'runtime-only') ||
|
|
556
|
+
!converted.input ||
|
|
557
|
+
!converted.output);
|
|
558
|
+
// Only a discovery contract carries an inputSchema the platform
|
|
559
|
+
// checks; runtime-only contracts keep their hash and stay current.
|
|
560
|
+
if (kind === 'functions' && !runtimeOnly)
|
|
561
|
+
inputConstToEnum(converted.input);
|
|
562
|
+
const contract = {
|
|
563
|
+
version: 1,
|
|
564
|
+
generatorVersion: 'lark-cli',
|
|
565
|
+
sdkVersion: null,
|
|
566
|
+
schemaVendor: 'zod',
|
|
567
|
+
schemaPackageVersion: null,
|
|
568
|
+
schemaHash: 'sha256:' + digest(JSON.stringify(converted)),
|
|
569
|
+
fidelity: runtimeOnly ? 'runtime-only' : 'complete',
|
|
570
|
+
mode: runtimeOnly ? 'runtime-only' : 'discovery',
|
|
571
|
+
warnings: converted.warnings,
|
|
572
|
+
};
|
|
573
|
+
const next = { ...meta, contract };
|
|
574
|
+
if (!runtimeOnly) {
|
|
575
|
+
next.inputSchema = converted.input;
|
|
576
|
+
next.outputSchema = converted.output;
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
delete next.inputSchema;
|
|
580
|
+
delete next.outputSchema;
|
|
581
|
+
}
|
|
582
|
+
if (!write &&
|
|
583
|
+
(!equal(meta.inputSchema, next.inputSchema) ||
|
|
584
|
+
!equal(meta.outputSchema, next.outputSchema) ||
|
|
585
|
+
!equal(meta.contract, contract)))
|
|
586
|
+
stale();
|
|
587
|
+
if (kind === 'durable') {
|
|
588
|
+
next.events = converted.events;
|
|
589
|
+
if (!write && !equal(meta.events, next.events))
|
|
590
|
+
stale();
|
|
591
|
+
}
|
|
592
|
+
if (converted.warnings.length)
|
|
593
|
+
process.stderr.write(converted.warnings.join('\n') + '\n');
|
|
500
594
|
if (kind === 'durable')
|
|
501
|
-
|
|
502
|
-
if (
|
|
503
|
-
validateFunctionInput(
|
|
595
|
+
validateTriggers(meta.triggers, converted.input, directory);
|
|
596
|
+
else if (!runtimeOnly)
|
|
597
|
+
validateFunctionInput(converted.input, id, path.join(directory, 'contract.ts'));
|
|
598
|
+
if (write)
|
|
599
|
+
changes.push([metaPath, next]);
|
|
600
|
+
if (kind === 'durable') {
|
|
601
|
+
durable.push({
|
|
602
|
+
functionId: id,
|
|
603
|
+
inputSchema: converted.input,
|
|
604
|
+
outputSchema: converted.output,
|
|
605
|
+
events: converted.events,
|
|
606
|
+
});
|
|
607
|
+
const source = `typeof import(${JSON.stringify(`../../durable/${id}/contract.js`)})`;
|
|
608
|
+
const registryEntry = (source) => `${JSON.stringify(id)}: { input: z.input<${source}[${JSON.stringify(decl.fields.input)}]>; output: z.output<${source}[${JSON.stringify(decl.fields.output)}]>; events: ${decl.fields.events ? `{ [E in keyof ${source}[${JSON.stringify(decl.fields.events)}]]: z.input<${source}[${JSON.stringify(decl.fields.events)}][E]> }` : '{}'} };`;
|
|
609
|
+
durableTypes.push(registryEntry(source));
|
|
610
|
+
durableCommonJSTypes.push(registryEntry(`typeof import(${JSON.stringify(`../../durable/${id}/contract.js`)}, { with: { "resolution-mode": "import" } })`));
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
504
613
|
functions.push({
|
|
505
614
|
functionId: id,
|
|
506
615
|
functionType: 2,
|
|
507
|
-
input:
|
|
616
|
+
input: converted.input ?? {},
|
|
617
|
+
output: converted.output ?? {},
|
|
618
|
+
contract,
|
|
508
619
|
});
|
|
509
620
|
inputs.push({
|
|
510
621
|
functionId: id,
|
|
511
622
|
functionType: 2,
|
|
512
|
-
inputSchema:
|
|
623
|
+
inputSchema: converted.input ?? {},
|
|
513
624
|
parameterOptions: {},
|
|
514
625
|
});
|
|
515
626
|
}
|
|
516
|
-
continue;
|
|
517
|
-
}
|
|
518
|
-
if (kind === 'functions')
|
|
519
|
-
generatedContractIds.add(id);
|
|
520
|
-
const converted = await schemas(directory, decl);
|
|
521
|
-
const metaPath = path.join(directory, 'meta.json'), meta = readJSON(metaPath);
|
|
522
|
-
if (kind === 'durable')
|
|
523
|
-
converted.events ??= {};
|
|
524
|
-
if (kind === 'durable' && (!converted.input || !converted.output))
|
|
525
|
-
throw Error('Durable contracts must be representable: ' +
|
|
526
|
-
converted.warnings.join('; '));
|
|
527
|
-
const runtimeOnly = kind !== 'durable' &&
|
|
528
|
-
((write
|
|
529
|
-
? request.runtimeOnly
|
|
530
|
-
: meta.contract?.mode === 'runtime-only') ||
|
|
531
|
-
!converted.input ||
|
|
532
|
-
!converted.output);
|
|
533
|
-
const contract = {
|
|
534
|
-
version: 1,
|
|
535
|
-
generatorVersion: 'lark-cli',
|
|
536
|
-
sdkVersion: null,
|
|
537
|
-
schemaVendor: 'zod',
|
|
538
|
-
schemaPackageVersion: null,
|
|
539
|
-
schemaHash: 'sha256:' + digest(JSON.stringify(converted)),
|
|
540
|
-
fidelity: runtimeOnly ? 'runtime-only' : 'complete',
|
|
541
|
-
mode: runtimeOnly ? 'runtime-only' : 'discovery',
|
|
542
|
-
warnings: converted.warnings,
|
|
543
|
-
};
|
|
544
|
-
const next = { ...meta, contract };
|
|
545
|
-
if (!runtimeOnly) {
|
|
546
|
-
next.inputSchema = converted.input;
|
|
547
|
-
next.outputSchema = converted.output;
|
|
548
|
-
}
|
|
549
|
-
else {
|
|
550
|
-
delete next.inputSchema;
|
|
551
|
-
delete next.outputSchema;
|
|
552
|
-
}
|
|
553
|
-
if (!write &&
|
|
554
|
-
(!equal(meta.inputSchema, next.inputSchema) ||
|
|
555
|
-
!equal(meta.outputSchema, next.outputSchema) ||
|
|
556
|
-
!equal(meta.contract, contract)))
|
|
557
|
-
stale();
|
|
558
|
-
if (kind === 'durable') {
|
|
559
|
-
next.events = converted.events;
|
|
560
|
-
if (!write && !equal(meta.events, next.events))
|
|
561
|
-
stale();
|
|
562
627
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
if (kind === 'durable')
|
|
566
|
-
validateTriggers(meta.triggers, converted.input, directory);
|
|
567
|
-
else if (!runtimeOnly)
|
|
568
|
-
validateFunctionInput(converted.input, id, path.join(directory, 'contract.ts'));
|
|
569
|
-
if (write)
|
|
570
|
-
changes.push([metaPath, next]);
|
|
571
|
-
if (kind === 'durable') {
|
|
572
|
-
durable.push({
|
|
573
|
-
functionId: id,
|
|
574
|
-
inputSchema: converted.input,
|
|
575
|
-
outputSchema: converted.output,
|
|
576
|
-
events: converted.events,
|
|
577
|
-
});
|
|
578
|
-
const source = `typeof import(${JSON.stringify(`../../durable/${id}/contract.js`)})`;
|
|
579
|
-
const registryEntry = (source) => `${JSON.stringify(id)}: { input: z.input<${source}[${JSON.stringify(decl.fields.input)}]>; output: z.output<${source}[${JSON.stringify(decl.fields.output)}]>; events: ${decl.fields.events ? `{ [E in keyof ${source}[${JSON.stringify(decl.fields.events)}]]: z.input<${source}[${JSON.stringify(decl.fields.events)}][E]> }` : '{}'} };`;
|
|
580
|
-
durableTypes.push(registryEntry(source));
|
|
581
|
-
durableCommonJSTypes.push(registryEntry(`typeof import(${JSON.stringify(`../../durable/${id}/contract.js`)}, { with: { "resolution-mode": "import" } })`));
|
|
582
|
-
}
|
|
583
|
-
else {
|
|
584
|
-
functions.push({
|
|
585
|
-
functionId: id,
|
|
586
|
-
functionType: 2,
|
|
587
|
-
input: converted.input ?? {},
|
|
588
|
-
output: converted.output ?? {},
|
|
589
|
-
contract,
|
|
590
|
-
});
|
|
591
|
-
inputs.push({
|
|
592
|
-
functionId: id,
|
|
593
|
-
functionType: 2,
|
|
594
|
-
inputSchema: converted.input ?? {},
|
|
595
|
-
parameterOptions: {},
|
|
596
|
-
});
|
|
628
|
+
catch (error) {
|
|
629
|
+
contractFailure(failures, path.join('server', kind, id), error);
|
|
597
630
|
}
|
|
598
631
|
}
|
|
599
|
-
collectDatabaseContracts(functions, inputs, !!(request.batchSnapshot || previous));
|
|
632
|
+
collectDatabaseContracts(functions, inputs, !!(request.batchSnapshot || previous), failures);
|
|
633
|
+
throwContractFailures(failures);
|
|
600
634
|
let batchSnapshot;
|
|
601
635
|
if (request.batchSnapshot || previous) {
|
|
602
636
|
const errors = [];
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-base-open/base-database-toolchain",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@lark-base-open/base-database-toolchain",
|
|
9
|
-
"version": "1.5.
|
|
9
|
+
"version": "1.5.1",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@babel/parser": "7.28.5",
|
package/package.json
CHANGED