@lark-base-open/base-database-toolchain 1.4.1 → 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.
@@ -23,8 +23,8 @@ 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, sqlParamSchema as positionalSQLSchema, deriveSQLInputSchema, normalizeFunctionInputSchema, checkFaaSInputSchemaContract, } from './function-schema.js';
27
- import { checkDeclaredParameters, sqlEnumType, mutationEnumType, } from './function-params.js';
26
+ import { namedSQLParamSchema, checkSQLFunctionParameters, normalizeFunctionInputSchema, checkFaaSInputSchemaContract, inputConstToEnum, } from './function-schema.js';
27
+ import { checkDeclaredParameters, mutationEnumType, } from './function-params.js';
28
28
  import { validateFunctionDescription, functionDescriptionHint, } from './function-description.js';
29
29
  import { readMutationMetaItem } from './mutation.js';
30
30
  import { bindFunctionBatchSnapshot, withFunctionBatchCapability, batchClientWarning, } from './function-batch.js';
@@ -32,8 +32,10 @@ export async function runCompiler(request) {
32
32
  if (request.protocolVersion !== 1)
33
33
  throw Error('Unsupported compiler protocol version');
34
34
  if (!path.isAbsolute(request.root) ||
35
- !['server', 'server-functions'].includes(request.server))
36
- throw Error('Invalid compiler project layout');
35
+ request.server !== 'server' ||
36
+ request.legacyBuild === true)
37
+ throw Error('PROJECT_LAYOUT_UNSUPPORTED: compiler requires a version 2 workspace with named inputs');
38
+ projectLayout(request.root);
37
39
  if (request.operation === 'validate-dependencies') {
38
40
  const policy = parsePackageDependencyPolicy(request.dependencyPolicy);
39
41
  validateWorkspacePackageDependencies(request.root, policy);
@@ -42,7 +44,7 @@ export async function runCompiler(request) {
42
44
  }
43
45
  if (request.operation === 'validate-locks') {
44
46
  for (const directory of projectLayout(request.root).dependencies)
45
- validateDependencyLock(path.join(request.root, directory), directory, '10.9.2');
47
+ validateDependencyLock(path.join(request.root, directory), directory, '11.21.3');
46
48
  return;
47
49
  }
48
50
  const triggerIDs = new Set();
@@ -140,11 +142,9 @@ export async function runCompiler(request) {
140
142
  for (const input of [
141
143
  'page',
142
144
  'server',
143
- 'server-functions',
144
145
  'contract',
145
146
  'contracts',
146
147
  'database-functions',
147
- 'sql',
148
148
  'mutations',
149
149
  'ai',
150
150
  'skill',
@@ -241,143 +241,104 @@ export async function runCompiler(request) {
241
241
  schema.description = param.description;
242
242
  return schema;
243
243
  }
244
- function legacyContracts(functions, inputs, bindBatch) {
244
+ function collectDatabaseContracts(functions, inputs, bindBatch, failures) {
245
245
  for (const [directory, type] of [
246
- [
247
- fs.existsSync(path.join(root, 'database-functions'))
248
- ? 'database-functions'
249
- : 'sql',
250
- 1,
251
- ],
246
+ ['database-functions', 1],
252
247
  ['mutations', 5],
253
248
  ]) {
254
249
  for (const id of entries(path.join(root, directory))) {
255
- const metadata = readJSON(path.join(root, directory, id, 'meta.json'));
256
- assertMetadataKeys(type === 1 ? 'sql' : 'mutation', id, metadata);
257
- validateFunctionDescription(metadata.description, metadata.name, path.join(directory, id, 'meta.json'));
258
- const descriptionHint = functionDescriptionHint(metadata.description, path.join(directory, id, 'meta.json'));
259
- if (descriptionHint)
260
- functionHints.push({ ...descriptionHint, functionId: id });
261
- if (type === 1) {
262
- let meta = metadata.meta;
263
- if (meta === undefined)
264
- meta = { params: [] };
265
- else if (!meta || typeof meta !== 'object' || Array.isArray(meta))
266
- throw Error('SQL meta must be an object: ' + id);
267
- else if (!Object.hasOwn(meta, 'params'))
268
- meta = { ...meta, params: [] };
269
- const sqlPath = safe(path.join(root, directory, id, 'main.sql'));
270
- // Metadata-only codegen can run before SQL is authored. The Go
271
- // project check requires complete declarations before any upload.
272
- if (fs.existsSync(sqlPath) || bindBatch) {
273
- const sql = fs.readFileSync(sqlPath, 'utf8');
274
- deriveSQLInputSchema(meta, sql);
275
- if (bindBatch)
276
- localSQLSources[id] =
277
- 'sha256:' + digest(JSON.stringify({ sql, meta }));
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);
279
+ }
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(' ')}`);
278
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])),
318
+ });
279
319
  }
280
- else {
281
- readMutationMetaItem(safe(path.join(root, directory, id, 'meta.json')), root);
320
+ catch (error) {
321
+ contractFailure(failures, path.join(directory, id), error);
282
322
  }
283
- const params = type === 1
284
- ? (metadata.meta?.params ?? [])
285
- : (readJSON(path.join(root, directory, id, 'spec.json')).params ??
286
- []);
287
- const declared = checkDeclaredParameters(params, {
288
- label: type === 1 ? 'meta.params' : 'spec.params',
289
- pointer: type === 1 ? '/meta/params' : '/params',
290
- file: path.join(directory, id, type === 1 ? 'meta.json' : 'spec.json'),
291
- enumType: type === 1 ? sqlEnumType : mutationEnumType,
292
- });
293
- if (declared.problems.length)
294
- throw Error(declared.problems.join('; '));
295
- functionHints.push(...declared.hints.map((hint) => ({ ...hint, functionId: id })));
296
- const input = {
297
- type: 'object',
298
- properties: Object.fromEntries(params.map((p, index) => {
299
- return [p.name, parameterSchema(p, type, index)];
300
- })),
301
- required: params
302
- .filter((p) => type === 1 || p.required !== false)
303
- .map((p) => p.name),
304
- additionalProperties: false,
305
- };
306
- functions.push({ functionId: id, functionType: type, input });
307
- inputs.push({
308
- functionId: id,
309
- functionType: type,
310
- inputSchema: input,
311
- parameters: params,
312
- parameterOptions: Object.fromEntries(params.filter((p) => p.enum).map((p) => [p.name, p.enum])),
313
- });
314
323
  }
315
324
  }
316
325
  }
317
- function sdkAt(directory) {
318
- const file = safe(path.join(directory, 'package.json'));
319
- if (fs.existsSync(file)) {
320
- const manifest = JSON.parse(fs.readFileSync(file, 'utf8'));
321
- if (manifest.dependencies?.['@lark-base-open/base-database-app-sdk'] ||
322
- manifest.devDependencies?.['@lark-base-open/base-database-app-sdk'])
323
- return true;
324
- }
325
- try {
326
- createRequire(file).resolve('@lark-base-open/base-database-app-sdk/page');
327
- return true;
328
- }
329
- catch {
330
- return false;
331
- }
332
- }
333
- function schemaType(schema) {
334
- if (!schema || typeof schema !== 'object')
335
- return 'unknown';
336
- if (Array.isArray(schema.enum))
337
- return schema.enum.map((v) => JSON.stringify(v)).join(' | ') || 'never';
338
- if (schema.anyOf || schema.oneOf)
339
- return (schema.anyOf ?? schema.oneOf).map(schemaType).join(' | ');
340
- if (Array.isArray(schema.type))
341
- return schema.type
342
- .map((type) => schemaType({ ...schema, type }))
343
- .join(' | ');
344
- switch (schema.type) {
345
- case 'string':
346
- case 'boolean':
347
- case 'null':
348
- return schema.type;
349
- case 'integer':
350
- case 'number':
351
- return 'number';
352
- case 'array':
353
- return schema.prefixItems
354
- ? '[' + schema.prefixItems.map(schemaType).join(', ') + ']'
355
- : 'Array<' + schemaType(schema.items) + '>';
356
- case 'object':
357
- return ('{' +
358
- Object.entries(schema.properties ?? {})
359
- .map(([name, value]) => `${JSON.stringify(name)}${schema.required?.includes(name) ? '' : '?'}: ${schemaType(value)}`)
360
- .join('; ') +
361
- '}');
362
- default:
363
- return 'unknown';
364
- }
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}`);
365
333
  }
366
- function writeLegacyInputs(inputs, write) {
367
- const members = inputs.map((item) => {
368
- let schema = item.inputSchema;
369
- if (item.functionType !== 2 && request.inputMode !== 'named')
370
- schema = {
371
- type: 'array',
372
- prefixItems: item.functionType === 1
373
- ? item.parameters.map(positionalSQLSchema)
374
- : Object.values(item.inputSchema.properties ?? {}),
375
- };
376
- return `${JSON.stringify(item.functionId)}: ${schemaType(schema)}`;
377
- });
378
- generatedFile('page/src/lib/database-function-inputs.generated.ts', '// Generated by base-database-toolchain.\nexport type DatabaseFunctionInputMap = {\n' +
379
- members.join(';\n') +
380
- '\n};\n', write);
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'));
381
342
  }
382
343
  async function isolatedCodegen(input) {
383
344
  return runSDKCodegen(root, input, server);
@@ -439,7 +400,7 @@ export async function runCompiler(request) {
439
400
  normalizeFunctionInputSchema(schema, file);
440
401
  const declared = checkFaaSInputSchemaContract(schema, file);
441
402
  if (declared.problems.length)
442
- throw Error(`${file}: ${declared.problems.join('; ')}. Fix descriptions in this source and regenerate contracts.`);
403
+ throw Error(`${file}: ${declared.problems.join('; ')}. Fix this source and regenerate contracts.`);
443
404
  functionHints.push(...declared.hints.map((hint) => ({ ...hint, functionId: id })));
444
405
  const ajv = new Ajv2020({ strict: false, validateFormats: false });
445
406
  if (!ajv.validateSchema(schema))
@@ -545,122 +506,131 @@ export async function runCompiler(request) {
545
506
  triggerLocations.length = 0;
546
507
  triggerCount = 0;
547
508
  const changes = [];
548
- let sdkDeclarations = 0;
509
+ const failures = [];
549
510
  for (const kind of ['functions', 'durable'])
550
511
  for (const id of entries(path.join(serverRoot, kind))) {
551
- const directory = path.join(serverRoot, kind, id), entry = path.join(directory, 'index.ts');
552
- if (!fs.existsSync(entry))
553
- throw Error('Missing Function entry ' + id);
554
- const metaFile = path.join(directory, 'meta.json');
555
- const declaredMeta = readJSON(safe(metaFile));
556
- validateFunctionDescription(declaredMeta.description, declaredMeta.name, metaFile);
557
- const descriptionHint = functionDescriptionHint(declaredMeta.description, metaFile);
558
- if (descriptionHint)
559
- functionHints.push({ ...descriptionHint, functionId: id });
560
- const decl = definition(entry);
561
- if (!decl) {
562
- const meta = readJSON(path.join(directory, 'meta.json'));
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);
563
547
  if (kind === 'durable')
564
- throw Error('Durable entry must use defineDurableFunction: ' + id);
565
- if (meta.inputSchema) {
566
- validateFunctionInput(meta.inputSchema, id);
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');
594
+ if (kind === 'durable')
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 {
567
613
  functions.push({
568
614
  functionId: id,
569
615
  functionType: 2,
570
- input: meta.inputSchema,
616
+ input: converted.input ?? {},
617
+ output: converted.output ?? {},
618
+ contract,
571
619
  });
572
620
  inputs.push({
573
621
  functionId: id,
574
622
  functionType: 2,
575
- inputSchema: meta.inputSchema,
623
+ inputSchema: converted.input ?? {},
576
624
  parameterOptions: {},
577
625
  });
578
626
  }
579
- continue;
580
- }
581
- sdkDeclarations++;
582
- if (kind === 'functions')
583
- generatedContractIds.add(id);
584
- const converted = await schemas(directory, decl);
585
- const metaPath = path.join(directory, 'meta.json'), meta = readJSON(metaPath);
586
- if (kind === 'durable')
587
- converted.events ??= {};
588
- if (kind === 'durable' && (!converted.input || !converted.output))
589
- throw Error('Durable contracts must be representable: ' +
590
- converted.warnings.join('; '));
591
- const runtimeOnly = kind !== 'durable' &&
592
- ((write
593
- ? request.runtimeOnly
594
- : meta.contract?.mode === 'runtime-only') ||
595
- !converted.input ||
596
- !converted.output);
597
- const contract = {
598
- version: 1,
599
- generatorVersion: 'lark-cli',
600
- sdkVersion: null,
601
- schemaVendor: 'zod',
602
- schemaPackageVersion: null,
603
- schemaHash: 'sha256:' + digest(JSON.stringify(converted)),
604
- fidelity: runtimeOnly ? 'runtime-only' : 'complete',
605
- mode: runtimeOnly ? 'runtime-only' : 'discovery',
606
- warnings: converted.warnings,
607
- };
608
- const next = { ...meta, contract };
609
- if (!runtimeOnly) {
610
- next.inputSchema = converted.input;
611
- next.outputSchema = converted.output;
612
- }
613
- else {
614
- delete next.inputSchema;
615
- delete next.outputSchema;
616
- }
617
- if (!write &&
618
- (!equal(meta.inputSchema, next.inputSchema) ||
619
- !equal(meta.outputSchema, next.outputSchema) ||
620
- !equal(meta.contract, contract)))
621
- stale();
622
- if (kind === 'durable') {
623
- next.events = converted.events;
624
- if (!write && !equal(meta.events, next.events))
625
- stale();
626
- }
627
- if (converted.warnings.length)
628
- process.stderr.write(converted.warnings.join('\n') + '\n');
629
- if (kind === 'durable')
630
- validateTriggers(meta.triggers, converted.input, directory);
631
- else if (!runtimeOnly)
632
- validateFunctionInput(converted.input, id, path.join(directory, 'contract.ts'));
633
- if (write)
634
- changes.push([metaPath, next]);
635
- if (kind === 'durable') {
636
- durable.push({
637
- functionId: id,
638
- inputSchema: converted.input,
639
- outputSchema: converted.output,
640
- events: converted.events,
641
- });
642
- const source = `typeof import(${JSON.stringify(`../../durable/${id}/contract.js`)})`;
643
- 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]> }` : '{}'} };`;
644
- durableTypes.push(registryEntry(source));
645
- durableCommonJSTypes.push(registryEntry(`typeof import(${JSON.stringify(`../../durable/${id}/contract.js`)}, { with: { "resolution-mode": "import" } })`));
646
627
  }
647
- else {
648
- functions.push({
649
- functionId: id,
650
- functionType: 2,
651
- input: converted.input ?? {},
652
- output: converted.output ?? {},
653
- contract,
654
- });
655
- inputs.push({
656
- functionId: id,
657
- functionType: 2,
658
- inputSchema: converted.input ?? {},
659
- parameterOptions: {},
660
- });
628
+ catch (error) {
629
+ contractFailure(failures, path.join('server', kind, id), error);
661
630
  }
662
631
  }
663
- legacyContracts(functions, inputs, !!(request.batchSnapshot || previous));
632
+ collectDatabaseContracts(functions, inputs, !!(request.batchSnapshot || previous), failures);
633
+ throwContractFailures(failures);
664
634
  let batchSnapshot;
665
635
  if (request.batchSnapshot || previous) {
666
636
  const errors = [];
@@ -687,7 +657,7 @@ export async function runCompiler(request) {
687
657
  reason: 'Local shape, IDs, static input and map target contracts checked. Source bindings and Owner permissions, source field Schema, condition operators/values, actual map source types, calendar/timezone semantics, platform minimum interval and Trigger quota are checked during deployment. The server validates the final merged Record input at startup; Function server validation does not cover these rules.',
688
658
  });
689
659
  const clientPath = safe('page/src/generated/functions.ts');
690
- const pageSDK = server === 'server' || sdkAt('page');
660
+ const pageSDK = true;
691
661
  const hasFaaS = functions.some((item) => item.functionType === 2);
692
662
  const client = inputs.length > 0 && (hasFaaS || pageSDK);
693
663
  if (fs.existsSync(clientPath) &&
@@ -708,7 +678,7 @@ export async function runCompiler(request) {
708
678
  const generated = {
709
679
  contractFormatVersion: 1,
710
680
  version: 1,
711
- layout: server === 'server' ? 'workspace' : 'classic',
681
+ layout: 'workspace',
712
682
  schemaHash: 'sha256:' + digest(JSON.stringify(functions)),
713
683
  ...(batchSnapshot ? { batchSnapshot } : {}),
714
684
  functions,
@@ -730,12 +700,10 @@ export async function runCompiler(request) {
730
700
  !equal(readJSON(safe(manifest)), generated))
731
701
  stale();
732
702
  if (!resolveSDKCodegenEntry(root, server)) {
733
- if (sdkDeclarations)
734
- throw new SDKCodegenError('SDK_CODEGEN_UNAVAILABLE', 'Cannot resolve the installed SDK codegen entry for this project.');
735
- const warning = batchClientWarning(generated, []);
736
- if (warning)
737
- warnings.push(warning);
738
- writeLegacyInputs(inputs, write);
703
+ if (!request.runtimeOnly)
704
+ throw new SDKCodegenError('SDK_CODEGEN_UNAVAILABLE', 'Cannot resolve the installed SDK codegen entry for this workspace.');
705
+ // Runtime-only generation never fabricates a Page client or substitutes
706
+ // a CLI-maintained helper for the project's SDK code generator.
739
707
  writeJSON(path.join(stateRoot, 'lark-site-contract-report.json'), contractReport(functions, inputs));
740
708
  return;
741
709
  }
@@ -752,42 +720,12 @@ export async function runCompiler(request) {
752
720
  }
753
721
  }
754
722
  const { durable: workflowContracts, ...sdkContracts } = generated;
755
- // The Page SDK client always uses named transport. Classic helper maps
756
- // retain their configured calling convention in a separate generated file.
723
+ // The Page SDK client always uses named transport.
757
724
  const output = await isolatedCodegen({
758
725
  ...sdkContracts,
759
726
  layout: 'workspace',
760
727
  previousAugmentation,
761
728
  });
762
- if (server === 'server-functions') {
763
- const helperInputs = inputs.map((item) => {
764
- if (request.inputMode === 'named' || item.functionType === 2)
765
- return item;
766
- return {
767
- ...item,
768
- inputSchema: {
769
- $schema: 'https://json-schema.org/draft/2020-12/schema',
770
- type: 'array',
771
- prefixItems: item.functionType === 1
772
- ? item.parameters.map(positionalSQLSchema)
773
- : Object.values(item.inputSchema.properties ?? {}),
774
- minItems: item.functionType === 1
775
- ? item.parameters.length
776
- : item.parameters.reduce((last, p, i) => (p.required === false ? last : i + 1), 0),
777
- maxItems: item.parameters.length,
778
- },
779
- };
780
- });
781
- output.push(...(await isolatedCodegen({
782
- ...sdkContracts,
783
- layout: 'classic',
784
- inputs: helperInputs,
785
- functions: [],
786
- client: false,
787
- augmentation: 'none',
788
- previousAugmentation: undefined,
789
- })));
790
- }
791
729
  const warning = batchClientWarning(generated, output);
792
730
  if (warning)
793
731
  warnings.push(warning);
@@ -808,7 +746,7 @@ export async function runCompiler(request) {
808
746
  }
809
747
  writeJSON(path.join(stateRoot, 'lark-site-contract-report.json'), contractReport(functions, inputs));
810
748
  }
811
- function inspectServerEnvironment(built) {
749
+ function inspectServerEnvironment(built, inspectOnly = false) {
812
750
  const environment = new Set();
813
751
  function visit(directory) {
814
752
  if (!fs.existsSync(directory))
@@ -874,6 +812,8 @@ export async function runCompiler(request) {
874
812
  }
875
813
  }
876
814
  visit(serverRoot);
815
+ if (inspectOnly)
816
+ return;
877
817
  writeJSON(path.join(stateRoot, 'lark-site-compiler-report.json'), {
878
818
  environmentVariables: [...environment].sort(),
879
819
  ...(built
@@ -927,8 +867,9 @@ export async function runCompiler(request) {
927
867
  else if (operation === 'build' ||
928
868
  operation === 'build-server' ||
929
869
  operation === 'durable-dev') {
870
+ inspectServerEnvironment(undefined, true);
930
871
  let built;
931
- if (!request.legacyBuild) {
872
+ {
932
873
  const tsc = path.join(path.dirname(requireProject.resolve('typescript/package.json')), 'bin/tsc');
933
874
  if (entries(path.join(serverRoot, 'functions')).length ||
934
875
  entries(path.join(serverRoot, 'durable')).length)
@@ -1,13 +1,8 @@
1
1
  export declare const DATABASE_FUNCTIONS_DIRECTORY = "database-functions";
2
- export declare const LEGACY_DATABASE_FUNCTIONS_DIRECTORY = "sql";
3
- export declare function databaseFunctionsDirectory(workspace: string): typeof DATABASE_FUNCTIONS_DIRECTORY | typeof LEGACY_DATABASE_FUNCTIONS_DIRECTORY | undefined;
4
- export declare function requireDatabaseFunctionsDirectory(workspace: string): typeof DATABASE_FUNCTIONS_DIRECTORY | typeof LEGACY_DATABASE_FUNCTIONS_DIRECTORY;
2
+ export declare function databaseFunctionsDirectory(workspace: string): typeof DATABASE_FUNCTIONS_DIRECTORY | undefined;
3
+ export declare function requireDatabaseFunctionsDirectory(workspace: string): typeof DATABASE_FUNCTIONS_DIRECTORY;
5
4
  /** Explicit configuration selects the layout; dependencies never select it. */
6
5
  export declare function projectLayout(workspace: string): {
7
- version: 1;
8
- server: string;
9
- dependencies: string[];
10
- } | {
11
6
  version: 2;
12
7
  server: string;
13
8
  dependencies: string[];