@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,60 @@
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
+
12
+ ## [1.5.0] - 2026-11-30
13
+
14
+ ### Removed
15
+
16
+ - Remove classic/template v1 project layouts, legacy sql/ and server-functions/ roots, positional Page inputs, and legacyBuild=true from the JSON compiler interface. Use template v2 page/server workspaces with named inputs; existing projects must be migrated before switching to this version.
17
+ - Remove LEGACY_DATABASE_FUNCTIONS_DIRECTORY from the project-layout export.
18
+ - Remove fallback Page helper generation when the project SDK codegen is unavailable. Normal contract generation now reports SDK_CODEGEN_UNAVAILABLE; runtime-only generation can continue without fabricating Page clients.
19
+
20
+ ### Added
21
+
22
+ - Preserve discovered SQL BATCH limits above 200 groups for client generation by a compatible project SDK. Actual invocation limits remain enforced by the installed SDK and platform; SDK 0.10.0 still limits batch clients to 200 groups.
23
+
24
+ ### Fixed
25
+
26
+ - Keep SQL BATCH clients available when discovered limits exceed the installed SDK limits by capping codegen inputs to those limits.
27
+ - Keep Vite configuration and plugin logs out of the development worker JSON protocol, redact pairing tokens across split writes, and bound diagnostics on stderr.
28
+ - Report SQL parameter declaration mismatches with file paths, affected parameters and repair guidance.
29
+ - Validate workspace Function contracts consistently when generating and verifying named Page clients.
30
+
31
+ ### Security
32
+
33
+ - Update ajv from 8.17.1 to 8.20.0 and re2js from 2.8.6 to 2.10.0 to address their published ReDoS advisories.
34
+
35
+ ## [2.0.0] - 2026-11-30 [YANKED]
36
+
37
+ Withdrawn in favor of the 1.x release line. Deprecated on npm; latest restored to 1.4.1.
38
+
39
+ ### Removed
40
+
41
+ - Remove classic/template v1 project layouts, legacy sql/ and server-functions/ roots, positional Page inputs, and legacyBuild=true from the JSON compiler interface. Use template v2 page/server workspaces with named inputs; existing projects must be migrated before switching to this version.
42
+ - Remove LEGACY_DATABASE_FUNCTIONS_DIRECTORY from the project-layout export.
43
+
44
+ ### Added
45
+
46
+ - Preserve discovered SQL BATCH limits above 200 groups for client generation by a compatible project SDK. Actual invocation limits remain enforced by the installed SDK and platform; SDK 0.10.0 still limits batch clients to 200 groups.
47
+
48
+ ### Fixed
49
+
50
+ - Keep Vite configuration and plugin logs out of the development worker JSON protocol, redact pairing tokens across split writes, and bound diagnostics on stderr.
51
+ - Report SQL parameter declaration mismatches with file paths, affected parameters and repair guidance.
52
+ - Validate workspace Function contracts consistently when generating and verifying named Page clients.
53
+
54
+ ### Security
55
+
56
+ - Update ajv and re2js dependencies to address high and critical advisories.
57
+
3
58
  ## [1.4.1] - 2026-11-29
4
59
 
5
60
  ### Fixed
package/README.md CHANGED
@@ -12,6 +12,8 @@ Authentication, platform API calls, project dependency installation, source uplo
12
12
 
13
13
  ## Node API
14
14
 
15
+ Version 1.5.0 requires `database-starter` template version 2 with `page`/`server` workspaces, named Page inputs and `database-functions/`. Migrate older layouts before upgrading; this version does not execute classic/v1 projects or expose `LEGACY_DATABASE_FUNCTIONS_DIRECTORY`. SQL BATCH capabilities above 200 are preserved for a compatible project SDK. Published SDK 0.10.0 still generates batch clients only up to 200 groups; increasing the toolchain version alone does not enable 500-group execution.
16
+
15
17
  ```js
16
18
  import {
17
19
  extractContract,
@@ -44,7 +46,7 @@ Run `base-database-toolchain` with one JSON object on stdin. It exits after one
44
46
  }
45
47
  ```
46
48
 
47
- Supported operations: `contracts`, `verify-contracts`, `build`, `build-server`, `durable-dev`, `validate-locks`, `validate-dependencies` and `inspect-page`. `validate-dependencies` requires the caller-provided `dependencyPolicy`; `build-server` skips Page builds. `inputMode`, `runtimeOnly`, `legacyBuild` and `durableDev` select project compatibility options. Page builds remain the caller's responsibility.
49
+ Supported operations: `contracts`, `verify-contracts`, `build`, `build-server`, `durable-dev`, `validate-locks`, `validate-dependencies` and `inspect-page`. `validate-dependencies` requires the caller-provided `dependencyPolicy`; `build-server` skips Page builds. `runtimeOnly` selects runtime metadata generation and `durableDev` carries local debug options. The worker requires template.version 2, page/server workspaces and named Page inputs; legacy server layouts, sql/ directories, legacyBuild=true and positional inputs are rejected before compilation. Page builds remain the caller's responsibility.
48
50
 
49
51
  For SQL batch clients, supply an authenticated, consistently discovered `batchSnapshot` with the siteToken, environment, versionId, skillHash and per-Function detail. The toolchain binds it to the actual project token, `runtimeProfile` (default online), and current local SQL source hashes. Verification reuses that bound observation; edited declarations lose the cached capability until a new discovery. An execution view is provenance, not a future lock. An older SDK can still generate single-call clients and returns a `BATCH_SDK_UNSUPPORTED` warning; no batch types are synthesized.
50
52
 
@@ -52,7 +54,7 @@ Successful contract operations write `lark-site-contract-report.json` under stat
52
54
 
53
55
  Success emits `{"ok":true,"operation":"contracts"}` on stdout. Failure emits a bounded JSON error on stderr and exits nonzero. Callers must not pass access tokens or application secrets to the process. SQL is not executed here; local Timer checks do not establish platform quota or calendar semantics. Durable local execution cannot invoke hosted Functions without a real host context.
54
56
 
55
- For `1.x`, compatible fixes increment patch, compatible features increment minor and incompatible APIs/protocols increment major. Published versions are immutable.
57
+ For stable versions, compatible fixes increment patch, compatible features increment minor and incompatible APIs/protocols increment major. Published versions are immutable.
56
58
 
57
59
  ## Page source inspection
58
60
 
@@ -66,14 +68,18 @@ These results do not prove that initialization executes successfully, that an ex
66
68
 
67
69
  Keep stdin open and send one startup line:
68
70
 
71
+ <!-- prettier-ignore -->
69
72
  ```json
70
73
  {"protocolVersion":1,"workspace":"/absolute/project","port":43100,"hostOrigin":"https://example.test","templateVersion":2}
71
74
  ```
72
75
 
73
76
  Only loopback ports 43100–43109 and an exact HTTPS host origin are accepted. Events on stdout include `snapshot`, `listening`, `ready`, `changed`, `error` and `stopped`, each with `protocolVersion: 1`. `ready` only reports that the SDK observed the local origin; it does not establish authentication or successful application behavior. Tokens are excluded from event payloads and redacted from errors.
74
77
 
78
+ The JSON worker reserves stdout for protocol events. Ordinary console and stream logs from project configuration and plugins are sent to stderr, with pairing tokens redacted across split writes. Diagnostic lines longer than 4,096 characters are omitted; each worker forwards at most 64 KiB plus a truncation notice. Callers should drain stderr separately from stdout. These diagnostics do not authorize publication or change protocol state.
79
+
75
80
  The backend snapshot excludes generated contract projections and observes source declarations, dependencies, bindings and authored Skill metadata. Individual input files are limited to 2 MiB, the tree to 20,000 entries and total content to 64 MiB. Changed-file lists have a byte/count budget; `filesTruncated: true` requires manual review rather than automatic publication. Request a fresh snapshot before a build or remote write:
76
81
 
82
+ <!-- prettier-ignore -->
77
83
  ```json
78
84
  {"protocolVersion":1,"command":"snapshot","requestId":"before-write"}
79
85
  ```
@@ -10,6 +10,7 @@ const ALLOWED = new Set([
10
10
  'lazy',
11
11
  'literal',
12
12
  'never',
13
+ 'null',
13
14
  'nullable',
14
15
  'number',
15
16
  'object',
@@ -5,7 +5,8 @@
5
5
  "additionalProperties": false,
6
6
  "required": [
7
7
  "configVersion",
8
- "appToken"
8
+ "appToken",
9
+ "template"
9
10
  ],
10
11
  "properties": {
11
12
  "$schema": {
@@ -45,13 +46,10 @@
45
46
  "const": "database-starter"
46
47
  },
47
48
  "version": {
48
- "enum": [
49
- 1,
50
- 2
51
- ]
49
+ "const": 2
52
50
  }
53
51
  },
54
- "description": "Starter layout version. Omitted in legacy database-starter version 1 projects."
52
+ "description": "Workspace starter layout; only version 2 is supported."
55
53
  },
56
54
  "managedAgentDocs": {
57
55
  "type": "boolean",
@@ -59,37 +57,8 @@
59
57
  "description": "Maintain the base-app managed section in AGENTS.md and the CLAUDE.md reference. Set false to opt out."
60
58
  },
61
59
  "functionInputs": {
62
- "enum": [
63
- "named",
64
- "positional"
65
- ],
66
- "description": "Classic Page/helper input contract; defaults to positional when omitted. Workspace and SDK clients use named inputs."
67
- }
68
- },
69
- "allOf": [
70
- {
71
- "if": {
72
- "required": [
73
- "template"
74
- ],
75
- "properties": {
76
- "template": {
77
- "properties": {
78
- "version": {
79
- "const": 2
80
- }
81
- },
82
- "type": "object"
83
- }
84
- }
85
- },
86
- "then": {
87
- "properties": {
88
- "functionInputs": {
89
- "const": "named"
90
- }
91
- }
92
- }
60
+ "const": "named",
61
+ "description": "Workspace Page and SDK clients use named inputs."
93
62
  }
94
- ]
63
+ }
95
64
  }
@@ -0,0 +1,4 @@
1
+ export declare function isolateDevelopmentDiagnostics(token: any): {
2
+ emit: (value: any) => boolean;
3
+ flush: () => void;
4
+ };
@@ -0,0 +1,73 @@
1
+ import { StringDecoder } from 'node:string_decoder';
2
+ import { redactPairing } from './dev-redaction.js';
3
+ // The worker owns stdout as NDJSON. Project configuration and plugins share the
4
+ // process, so logLevel: silent alone cannot keep their console/direct writes out.
5
+ export function isolateDevelopmentDiagnostics(token) {
6
+ const protocolWrite = process.stdout.write.bind(process.stdout);
7
+ const diagnosticWrite = process.stderr.write.bind(process.stderr);
8
+ const lineLimit = 4096;
9
+ const outputLimit = 64 * 1024;
10
+ let written = 0;
11
+ let suppressed = false;
12
+ const output = (line) => {
13
+ if (suppressed)
14
+ return;
15
+ const safe = redactPairing(line, token) + '\n';
16
+ const size = Buffer.byteLength(safe);
17
+ if (written + size > outputLimit) {
18
+ suppressed = true;
19
+ diagnosticWrite('[development logs truncated]\n');
20
+ return;
21
+ }
22
+ written += size;
23
+ diagnosticWrite(safe);
24
+ };
25
+ const streams = [];
26
+ for (const stream of [process.stdout, process.stderr]) {
27
+ const decoder = new StringDecoder('utf8');
28
+ let pending = '';
29
+ let omitted = false;
30
+ const flushLine = () => {
31
+ output(omitted ? '[development log line omitted: too long]' : pending);
32
+ pending = '';
33
+ omitted = false;
34
+ };
35
+ const accept = (text) => {
36
+ for (const [index, part] of text.split('\n').entries()) {
37
+ if (index)
38
+ flushLine();
39
+ if (!omitted) {
40
+ if (pending.length + part.length > lineLimit) {
41
+ pending = '';
42
+ omitted = true;
43
+ }
44
+ else
45
+ pending += part;
46
+ }
47
+ }
48
+ };
49
+ stream.write = (chunk, encoding, callback) => {
50
+ const done = typeof encoding === 'function' ? encoding : callback;
51
+ const buffer = Buffer.isBuffer(chunk)
52
+ ? chunk
53
+ : Buffer.from(chunk, typeof encoding === 'string' ? encoding : undefined);
54
+ accept(decoder.write(buffer));
55
+ if (typeof done === 'function')
56
+ queueMicrotask(done);
57
+ // Diagnostics are bounded and excess output is dropped rather than
58
+ // applying backpressure to the control protocol or retaining more data.
59
+ return true;
60
+ };
61
+ streams.push(() => {
62
+ accept(decoder.end());
63
+ if (pending || omitted)
64
+ flushLine();
65
+ });
66
+ }
67
+ const flush = () => streams.forEach((finish) => finish());
68
+ process.once('exit', flush);
69
+ return {
70
+ emit: (value) => protocolWrite(JSON.stringify(value) + '\n'),
71
+ flush,
72
+ };
73
+ }
@@ -5,10 +5,12 @@ import { startVite } from './dev-vite-server.js';
5
5
  import { watchSnapshot, changedFiles, snapshotFingerprint, } from './dev-snapshot.js';
6
6
  import { DEVELOPMENT_PAIRING as protocol } from './development-pairing.generated.js';
7
7
  import { redactPairing } from './dev-redaction.js';
8
+ import { isolateDevelopmentDiagnostics } from './dev-diagnostics.mjs';
8
9
  export function runDevelopmentWorker() {
9
10
  const token = process.env[protocol.tokenEnv];
11
+ const diagnostics = isolateDevelopmentDiagnostics(token);
10
12
  const redact = (value) => redactPairing(String(value), token).slice(0, 4096);
11
- const emit = (value) => process.stdout.write(JSON.stringify({ protocolVersion: 1, ...value }) + '\n');
13
+ const emit = (value) => diagnostics.emit({ protocolVersion: 1, ...value });
12
14
  let server;
13
15
  let started = false;
14
16
  let stopping = false;
@@ -51,6 +53,7 @@ export function runDevelopmentWorker() {
51
53
  process.stdin.pause();
52
54
  await startup.catch(() => { });
53
55
  await server?.close();
56
+ diagnostics.flush();
54
57
  emit({ event: 'stopped' });
55
58
  process.exit(code);
56
59
  }
@@ -25,7 +25,10 @@ export interface BoundFunctionBatchSnapshot extends FunctionBatchSnapshot {
25
25
  runtimeProfile: string;
26
26
  localSources: Record<string, string>;
27
27
  }
28
- /** Closed published contract; generated types never establish runtime permission. */
28
+ /** Closed published contract; generated types never establish runtime permission.
29
+ * Limits above the current backend ceiling are not rejected here: SDK codegen caps them to the
30
+ * installed SDK, and devcenter, the Page SDK and the backend enforce group counts, so raising the
31
+ * backend limit later does not require a CLI release. */
29
32
  export declare function normalizeDMLBatchCapability(functionType: number, capability: unknown): DMLBatchCapability | undefined;
30
33
  /** Execution provenance describes the observed provider view, not a future lock. */
31
34
  export declare function normalizeFunctionExecutionSnapshot(value: unknown, environment: 'preview' | 'prod'): FunctionExecutionSnapshot | undefined;
@@ -1,7 +1,10 @@
1
1
  function record(value) {
2
2
  return !!value && typeof value === 'object' && !Array.isArray(value);
3
3
  }
4
- /** Closed published contract; generated types never establish runtime permission. */
4
+ /** Closed published contract; generated types never establish runtime permission.
5
+ * Limits above the current backend ceiling are not rejected here: SDK codegen caps them to the
6
+ * installed SDK, and devcenter, the Page SDK and the backend enforce group counts, so raising the
7
+ * backend limit later does not require a CLI release. */
5
8
  export function normalizeDMLBatchCapability(functionType, capability) {
6
9
  if (functionType !== 1 || !record(capability))
7
10
  return;
@@ -10,10 +13,8 @@ export function normalizeDMLBatchCapability(functionType, capability) {
10
13
  capability.maxRowsPerGroup !== 1 ||
11
14
  !Number.isSafeInteger(capability.maxGroups) ||
12
15
  capability.maxGroups < 1 ||
13
- capability.maxGroups > 200 ||
14
16
  !Number.isSafeInteger(capability.maxTotalRows) ||
15
- capability.maxTotalRows < 1 ||
16
- capability.maxTotalRows > 200)
17
+ capability.maxTotalRows < 1)
17
18
  return;
18
19
  return {
19
20
  version: 1,
@@ -8,7 +8,7 @@ export declare const AGENT_TOOL_DESIGN_REFERENCE = "references/agent-tool-design
8
8
  export declare const PARAMETER_NAME_PATTERN: RegExp;
9
9
  export declare const MAX_PARAMETER_DESCRIPTION = 500;
10
10
  export declare const SHORT_DESCRIPTION_THRESHOLD = 8;
11
- export type FunctionHintKind = 'short_description' | 'binding' | 'enum_unchecked' | 'function_description';
11
+ export type FunctionHintKind = 'short_description' | 'binding' | 'enum_unchecked' | 'function_description' | 'parameter_declaration';
12
12
  /** One non-blocking authoring hint; local hints and service `results[].hints[]` share this shape. */
13
13
  export interface FunctionHint {
14
14
  functionId?: string;
@@ -41,7 +41,7 @@ export function shortDescriptionHint(path, subject) {
41
41
  */
42
42
  export function checkParameterDescription(description, label, path, result) {
43
43
  if (typeof description !== 'string' || description.trim() === '') {
44
- result.problems.push(`${label}.description is required and must be a non-blank string`);
44
+ result.problems.push(`${label}.description is required and must be a non-blank string; describe its business meaning in 1 to ${MAX_PARAMETER_DESCRIPTION} characters`);
45
45
  return;
46
46
  }
47
47
  if (codePoints(description) > MAX_PARAMETER_DESCRIPTION) {
@@ -75,7 +75,7 @@ export function checkDeclaredParameters(params, options) {
75
75
  result.problems.push(`${label}.name must match ${PARAMETER_NAME_PATTERN.source}`);
76
76
  }
77
77
  else if (names.has(name)) {
78
- result.problems.push(`${label}.name duplicates ${JSON.stringify(name)}; names must be unique within one Function`);
78
+ result.problems.push(`${label}.name duplicates ${JSON.stringify(name)}; rename this entry so each position has a unique name within the Function`);
79
79
  }
80
80
  else {
81
81
  names.add(name);
@@ -84,11 +84,16 @@ export function checkDeclaredParameters(params, options) {
84
84
  if (param.enum === undefined)
85
85
  return;
86
86
  const values = param.enum;
87
+ const type = options.enumType(param);
88
+ const example = type === 'integer' || type === 'number'
89
+ ? '[1, 2]'
90
+ : type === 'boolean'
91
+ ? '[true, false]'
92
+ : '["open", "closed"]';
87
93
  if (!Array.isArray(values) || values.length === 0) {
88
- result.problems.push(`${label}.enum must be a non-empty array`);
94
+ result.problems.push(`${label}.enum must be a non-empty array; ${type ? `use a JSON ${type} array such as ${example}` : 'omit enum for an unsupported kind'}`);
89
95
  return;
90
96
  }
91
- const type = options.enumType(param);
92
97
  if (!type) {
93
98
  result.problems.push(`${label}.enum is only supported for string, integer, number or boolean kinds (kind ${JSON.stringify(param.kind)})`);
94
99
  return;
@@ -104,7 +109,7 @@ export function checkDeclaredParameters(params, options) {
104
109
  return;
105
110
  }
106
111
  if (!enumValueMatches(value, type)) {
107
- result.problems.push(`${valueLabel} must be a JSON ${type} to match kind ${JSON.stringify(param.kind)}`);
112
+ result.problems.push(`${valueLabel} must be a JSON ${type} to match kind ${JSON.stringify(param.kind)}; use values such as ${example}`);
108
113
  return;
109
114
  }
110
115
  if (typeof value === 'string' &&
@@ -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[];
@@ -20,6 +21,10 @@ export declare function sqlParamSchema(param: SQLParamMeta, index: number): {
20
21
  };
21
22
  /** Named-route declaration projection; mirrors the server's nullable/range/enum semantics. */
22
23
  export declare function namedSQLParamSchema(param: Record<string, unknown>, index: number): Record<string, unknown>;
24
+ /** Authoring diagnostics for the named SQL contract. Metadata-only codegen may
25
+ * run before main.sql exists, in which case there are no placeholders to check.
26
+ */
27
+ export declare function checkSQLFunctionParameters(params: unknown, sql: string | undefined, file: string): DeclaredParameterResult;
23
28
  /**
24
29
  * Local Page input contract for the positional `invoke_function` route.
25
30
  * It is never uploaded: the service renders the Agent-facing named-object