@lark-base-open/base-database-toolchain 1.3.1 → 1.4.0
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 +17 -0
- package/dist/function-metadata-keys.d.ts +1 -0
- package/dist/function-metadata-keys.js +47 -0
- package/dist/function-schema.js +22 -9
- package/dist/go-adapter.mjs +88 -10
- package/dist/mutation.js +3 -4
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.4.0] - 2026-11-26
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Support exclusive numeric bounds in Function input schemas, including Zod positive, negative, greater-than and less-than constraints.
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Generate complete typed Page clients for projects that declare only SQL Functions.
|
|
12
|
+
- Preserve classic named or positional helper types while using named inputs for Page SDK clients.
|
|
13
|
+
- Preserve recognized FunctionInputMap augmentations referenced by explicit TypeScript file lists during contract regeneration.
|
|
14
|
+
- Remove obsolete generated Page clients after their final Function declaration is removed.
|
|
15
|
+
- Refuse to overwrite unrecognized, author-owned functions.ts files during contract generation.
|
|
16
|
+
- Reject unsupported SQL and Mutation metadata fields with field paths and actionable diagnostics.
|
|
17
|
+
- Identify stale generated files and direct callers to contracts generate.
|
|
18
|
+
- Keep empty generated input maps compilable when the Page SDK is installed.
|
|
19
|
+
|
|
3
20
|
## [1.3.1] - 2026-11-25
|
|
4
21
|
|
|
5
22
|
### Fixed
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function assertMetadataKeys(type: 'sql' | 'mutation', functionId: string, manifest: Record<string, unknown>): void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Mirrors storedMetaWire / SQLParameterDeclaration in DevCenter. Mutation
|
|
2
|
+
// parameters belong to spec.json and follow mutationSchema instead.
|
|
3
|
+
export function assertMetadataKeys(type, functionId, manifest) {
|
|
4
|
+
const checkKeys = (object, parent, supported) => {
|
|
5
|
+
for (const key of Object.keys(object)) {
|
|
6
|
+
if (supported.includes(key))
|
|
7
|
+
continue;
|
|
8
|
+
const path = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key)
|
|
9
|
+
? [parent, key].filter(Boolean).join('.')
|
|
10
|
+
: `${parent}[${JSON.stringify(key)}]`;
|
|
11
|
+
let hint = '';
|
|
12
|
+
if (!parent && key === 'params' && type === 'sql')
|
|
13
|
+
hint = ' Declare parameters in meta.params.';
|
|
14
|
+
else if (type === 'mutation' && (key === 'params' || key === 'meta'))
|
|
15
|
+
hint = ' Declare parameters in spec.json under params.';
|
|
16
|
+
else if (!parent && key === 'inputSchema' && type === 'sql')
|
|
17
|
+
hint =
|
|
18
|
+
' Database Function inputSchema is derived from meta.params and must not be set.';
|
|
19
|
+
else if (parent.startsWith('meta.params[') && key === 'required')
|
|
20
|
+
hint =
|
|
21
|
+
' Supply every parameter. Omit nullable or set it to true to allow a null value.';
|
|
22
|
+
throw new Error(`Invalid function metadata at ${functionId}: ${path} is not a supported key. Supported keys: ${supported.join(', ')}.${hint}`);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
if (type === 'mutation') {
|
|
26
|
+
checkKeys(manifest, '', ['name', 'description']);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
checkKeys(manifest, '', ['name', 'description', 'meta']);
|
|
30
|
+
const meta = manifest.meta;
|
|
31
|
+
if (!meta || typeof meta !== 'object' || Array.isArray(meta))
|
|
32
|
+
return;
|
|
33
|
+
checkKeys(meta, 'meta', ['params']);
|
|
34
|
+
if ('params' in meta && Array.isArray(meta.params))
|
|
35
|
+
meta.params.forEach((param, index) => {
|
|
36
|
+
if (param && typeof param === 'object' && !Array.isArray(param))
|
|
37
|
+
checkKeys(param, `meta.params[${index}]`, [
|
|
38
|
+
'name',
|
|
39
|
+
'kind',
|
|
40
|
+
'description',
|
|
41
|
+
'enum',
|
|
42
|
+
'nullable',
|
|
43
|
+
'minimum',
|
|
44
|
+
'maximum',
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
}
|
package/dist/function-schema.js
CHANGED
|
@@ -13,6 +13,12 @@ const ALLOWED_TYPES = new Set([
|
|
|
13
13
|
'boolean',
|
|
14
14
|
'null',
|
|
15
15
|
]);
|
|
16
|
+
const NUMBER_KEYWORDS = [
|
|
17
|
+
'minimum',
|
|
18
|
+
'maximum',
|
|
19
|
+
'exclusiveMinimum',
|
|
20
|
+
'exclusiveMaximum',
|
|
21
|
+
];
|
|
16
22
|
const ALLOWED_KEYWORDS = new Set([
|
|
17
23
|
'$schema',
|
|
18
24
|
'type',
|
|
@@ -25,8 +31,7 @@ const ALLOWED_KEYWORDS = new Set([
|
|
|
25
31
|
'minItems',
|
|
26
32
|
'maxItems',
|
|
27
33
|
'enum',
|
|
28
|
-
|
|
29
|
-
'maximum',
|
|
34
|
+
...NUMBER_KEYWORDS,
|
|
30
35
|
'minLength',
|
|
31
36
|
'maxLength',
|
|
32
37
|
'oneOf',
|
|
@@ -147,7 +152,6 @@ function validateSchemaNode(value, path, depth, state) {
|
|
|
147
152
|
const objectKeywords = ['properties', 'required', 'additionalProperties'];
|
|
148
153
|
const arrayKeywords = ['items', 'prefixItems', 'minItems', 'maxItems'];
|
|
149
154
|
const stringKeywords = ['minLength', 'maxLength', 'pattern'];
|
|
150
|
-
const numberKeywords = ['minimum', 'maximum'];
|
|
151
155
|
for (const key of objectKeywords) {
|
|
152
156
|
if (value[key] !== undefined && !types.includes('object')) {
|
|
153
157
|
schemaError(path, `${key} requires type object`);
|
|
@@ -163,7 +167,7 @@ function validateSchemaNode(value, path, depth, state) {
|
|
|
163
167
|
schemaError(path, `${key} requires type string`);
|
|
164
168
|
}
|
|
165
169
|
}
|
|
166
|
-
for (const key of
|
|
170
|
+
for (const key of NUMBER_KEYWORDS) {
|
|
167
171
|
if (value[key] !== undefined &&
|
|
168
172
|
!types.includes('integer') &&
|
|
169
173
|
!types.includes('number')) {
|
|
@@ -211,7 +215,7 @@ function validateSchemaNode(value, path, depth, state) {
|
|
|
211
215
|
for (const key of ['minItems', 'maxItems', 'minLength', 'maxLength']) {
|
|
212
216
|
validateNonNegativeInteger(value, key, path);
|
|
213
217
|
}
|
|
214
|
-
for (const key of
|
|
218
|
+
for (const key of NUMBER_KEYWORDS) {
|
|
215
219
|
const number = value[key];
|
|
216
220
|
if (number !== undefined &&
|
|
217
221
|
(typeof number !== 'number' || !Number.isFinite(number))) {
|
|
@@ -221,6 +225,7 @@ function validateSchemaNode(value, path, depth, state) {
|
|
|
221
225
|
for (const [minimumKey, maximumKey] of [
|
|
222
226
|
['minItems', 'maxItems'],
|
|
223
227
|
['minLength', 'maxLength'],
|
|
228
|
+
['minimum', 'maximum'],
|
|
224
229
|
]) {
|
|
225
230
|
const minimum = value[minimumKey];
|
|
226
231
|
const maximum = value[maximumKey];
|
|
@@ -230,10 +235,18 @@ function validateSchemaNode(value, path, depth, state) {
|
|
|
230
235
|
schemaError(path, `${minimumKey} cannot exceed ${maximumKey}`);
|
|
231
236
|
}
|
|
232
237
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
238
|
+
for (const [lowerKey, upperKey] of [
|
|
239
|
+
['exclusiveMinimum', 'exclusiveMaximum'],
|
|
240
|
+
['exclusiveMinimum', 'maximum'],
|
|
241
|
+
['minimum', 'exclusiveMaximum'],
|
|
242
|
+
]) {
|
|
243
|
+
const lower = value[lowerKey];
|
|
244
|
+
const upper = value[upperKey];
|
|
245
|
+
if (typeof lower === 'number' &&
|
|
246
|
+
typeof upper === 'number' &&
|
|
247
|
+
lower >= upper) {
|
|
248
|
+
schemaError(path, `${lowerKey} must be less than ${upperKey}`);
|
|
249
|
+
}
|
|
237
250
|
}
|
|
238
251
|
}
|
|
239
252
|
export function normalizeFunctionInputSchema(value, source) {
|
package/dist/go-adapter.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertMetadataKeys } from './function-metadata-keys.js';
|
|
1
2
|
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
2
3
|
// SPDX-License-Identifier: MIT
|
|
3
4
|
// This worker compiles application TypeScript and schemas. All API requests,
|
|
@@ -59,6 +60,7 @@ export async function runCompiler(request) {
|
|
|
59
60
|
const requireProject = createRequire(path.join(serverRoot, 'package.json'));
|
|
60
61
|
let collectWrites = operation === 'contracts';
|
|
61
62
|
const pendingWrites = new Map();
|
|
63
|
+
const pendingRemovals = new Set();
|
|
62
64
|
const generatedFiles = [];
|
|
63
65
|
const generatedContractIds = new Set();
|
|
64
66
|
function contractReport(functions, inputs) {
|
|
@@ -251,6 +253,7 @@ export async function runCompiler(request) {
|
|
|
251
253
|
]) {
|
|
252
254
|
for (const id of entries(path.join(root, directory))) {
|
|
253
255
|
const metadata = readJSON(path.join(root, directory, id, 'meta.json'));
|
|
256
|
+
assertMetadataKeys(type === 1 ? 'sql' : 'mutation', id, metadata);
|
|
254
257
|
validateFunctionDescription(metadata.description, metadata.name, path.join(directory, id, 'meta.json'));
|
|
255
258
|
const descriptionHint = functionDescriptionHint(metadata.description, path.join(directory, id, 'meta.json'));
|
|
256
259
|
if (descriptionHint)
|
|
@@ -311,6 +314,22 @@ export async function runCompiler(request) {
|
|
|
311
314
|
}
|
|
312
315
|
}
|
|
313
316
|
}
|
|
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
|
+
}
|
|
314
333
|
function schemaType(schema) {
|
|
315
334
|
if (!schema || typeof schema !== 'object')
|
|
316
335
|
return 'unknown';
|
|
@@ -478,7 +497,7 @@ export async function runCompiler(request) {
|
|
|
478
497
|
}
|
|
479
498
|
}
|
|
480
499
|
function stale() {
|
|
481
|
-
throw Error('CONTRACT_STALE:
|
|
500
|
+
throw Error('CONTRACT_STALE: run contracts generate with the current CLI');
|
|
482
501
|
}
|
|
483
502
|
function equal(a, b) {
|
|
484
503
|
const canonical = (value) => Array.isArray(value)
|
|
@@ -495,7 +514,9 @@ export async function runCompiler(request) {
|
|
|
495
514
|
save(file, content);
|
|
496
515
|
else if (!fs.existsSync(safe(file)) ||
|
|
497
516
|
fs.readFileSync(safe(file), 'utf8') !== content)
|
|
498
|
-
|
|
517
|
+
throw Error('CONTRACT_STALE: ' +
|
|
518
|
+
path.relative(root, safe(file)) +
|
|
519
|
+
' differs; run contracts generate with the current CLI');
|
|
499
520
|
}
|
|
500
521
|
async function contracts(write) {
|
|
501
522
|
const manifest = path.join(serverRoot, 'contracts.generated.json');
|
|
@@ -665,8 +686,21 @@ export async function runCompiler(request) {
|
|
|
665
686
|
locations: triggerLocations,
|
|
666
687
|
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.',
|
|
667
688
|
});
|
|
668
|
-
const
|
|
669
|
-
|
|
689
|
+
const clientPath = safe('page/src/generated/functions.ts');
|
|
690
|
+
const pageSDK = server === 'server' || sdkAt('page');
|
|
691
|
+
const hasFaaS = functions.some((item) => item.functionType === 2);
|
|
692
|
+
const client = inputs.length > 0 && (hasFaaS || pageSDK);
|
|
693
|
+
if (fs.existsSync(clientPath) &&
|
|
694
|
+
!fs
|
|
695
|
+
.readFileSync(clientPath, 'utf8')
|
|
696
|
+
.startsWith('/* Generated by base-database-cli. Runtime validation remains authoritative. */'))
|
|
697
|
+
throw Error('FUNCTION_INPUT_MODULE_CONFLICT: unrecognized functions.ts; review it before regenerating');
|
|
698
|
+
if (!client && fs.existsSync(clientPath)) {
|
|
699
|
+
if (!write)
|
|
700
|
+
stale();
|
|
701
|
+
pendingRemovals.add(clientPath);
|
|
702
|
+
generatedFiles.push('page/src/generated/functions.ts');
|
|
703
|
+
}
|
|
670
704
|
const augmentationPath = safe('page/src/lib/function-input-map.generated.ts');
|
|
671
705
|
const previousAugmentation = fs.existsSync(augmentationPath)
|
|
672
706
|
? fs.readFileSync(augmentationPath, 'utf8')
|
|
@@ -681,11 +715,11 @@ export async function runCompiler(request) {
|
|
|
681
715
|
...(durable.length ? { durable } : {}),
|
|
682
716
|
inputs,
|
|
683
717
|
client,
|
|
684
|
-
augmentation:
|
|
685
|
-
?
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
718
|
+
augmentation: previousAugmentation === undefined
|
|
719
|
+
? 'none'
|
|
720
|
+
: hasFaaS
|
|
721
|
+
? 'client'
|
|
722
|
+
: 'compat',
|
|
689
723
|
};
|
|
690
724
|
if (write)
|
|
691
725
|
for (const [file, data] of changes)
|
|
@@ -718,17 +752,59 @@ export async function runCompiler(request) {
|
|
|
718
752
|
}
|
|
719
753
|
}
|
|
720
754
|
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.
|
|
721
757
|
const output = await isolatedCodegen({
|
|
722
758
|
...sdkContracts,
|
|
759
|
+
layout: 'workspace',
|
|
723
760
|
previousAugmentation,
|
|
724
761
|
});
|
|
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
|
+
}
|
|
725
791
|
const warning = batchClientWarning(generated, output);
|
|
726
792
|
if (warning)
|
|
727
793
|
warnings.push(warning);
|
|
728
794
|
for (const file of output) {
|
|
729
795
|
if (typeof file.path !== 'string' || typeof file.content !== 'string')
|
|
730
796
|
throw Error('Invalid SDK codegen result');
|
|
731
|
-
|
|
797
|
+
let content = file.content;
|
|
798
|
+
if (!inputs.length &&
|
|
799
|
+
pageSDK &&
|
|
800
|
+
[
|
|
801
|
+
'function-inputs.ts',
|
|
802
|
+
'database-function-inputs.generated.ts',
|
|
803
|
+
].includes(path.basename(file.path)) &&
|
|
804
|
+
!content.includes("from '@lark-base-open/base-database-app-sdk/page'"))
|
|
805
|
+
content +=
|
|
806
|
+
"\nimport type {} from '@lark-base-open/base-database-app-sdk/page';\n";
|
|
807
|
+
generatedFile(file.path, content, write);
|
|
732
808
|
}
|
|
733
809
|
writeJSON(path.join(stateRoot, 'lark-site-contract-report.json'), contractReport(functions, inputs));
|
|
734
810
|
}
|
|
@@ -914,6 +990,8 @@ export async function runCompiler(request) {
|
|
|
914
990
|
collectWrites = false;
|
|
915
991
|
for (const [file, content] of pendingWrites)
|
|
916
992
|
save(file, content);
|
|
993
|
+
for (const file of pendingRemovals)
|
|
994
|
+
fs.unlinkSync(safe(file));
|
|
917
995
|
}
|
|
918
996
|
return { ok: true, operation, ...(warnings.length ? { warnings } : {}) };
|
|
919
997
|
}
|
package/dist/mutation.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertMetadataKeys } from './function-metadata-keys.js';
|
|
1
2
|
import { readFileSync } from 'node:fs';
|
|
2
3
|
import { basename, dirname, join } from 'node:path';
|
|
3
4
|
import { Ajv } from 'ajv';
|
|
@@ -111,12 +112,10 @@ export function validateMutationDefinition(definition, { requireParameterContrac
|
|
|
111
112
|
}
|
|
112
113
|
export function readMutationMetaItem(path, workspace, enforceDescription = true) {
|
|
113
114
|
const meta = readMutationJSON(path);
|
|
114
|
-
if (!meta ||
|
|
115
|
-
typeof meta !== 'object' ||
|
|
116
|
-
Array.isArray(meta) ||
|
|
117
|
-
Object.keys(meta).some((key) => !['name', 'description'].includes(key)))
|
|
115
|
+
if (!meta || typeof meta !== 'object' || Array.isArray(meta))
|
|
118
116
|
throw new Error(`Invalid Mutation meta: ${path}`);
|
|
119
117
|
const functionId = basename(dirname(path));
|
|
118
|
+
assertMetadataKeys('mutation', functionId, meta);
|
|
120
119
|
if (!/^[A-Za-z0-9_-]{1,64}$/.test(functionId))
|
|
121
120
|
throw new Error(`Invalid Function ID: ${functionId}`);
|
|
122
121
|
if (typeof meta.name !== 'string' || !meta.name || [...meta.name].length > 64)
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-base-open/base-database-toolchain",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
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.
|
|
9
|
+
"version": "1.4.0",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@babel/parser": "7.28.5",
|
package/package.json
CHANGED