@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.
@@ -2,24 +2,17 @@ import { parseProjectConfig } from './app-builder/core.mjs';
2
2
  import { existsSync, readFileSync, lstatSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
4
  export const DATABASE_FUNCTIONS_DIRECTORY = 'database-functions';
5
- export const LEGACY_DATABASE_FUNCTIONS_DIRECTORY = 'sql';
6
5
  export function databaseFunctionsDirectory(workspace) {
7
- const canonical = existsSync(join(workspace, DATABASE_FUNCTIONS_DIRECTORY));
8
- const legacy = existsSync(join(workspace, LEGACY_DATABASE_FUNCTIONS_DIRECTORY));
9
- if (canonical && legacy) {
10
- throw new Error(`Project cannot contain both ${DATABASE_FUNCTIONS_DIRECTORY}/ and legacy ${LEGACY_DATABASE_FUNCTIONS_DIRECTORY}/ directories`);
11
- }
12
- if (canonical)
13
- return DATABASE_FUNCTIONS_DIRECTORY;
14
- if (legacy)
15
- return LEGACY_DATABASE_FUNCTIONS_DIRECTORY;
16
- return undefined;
6
+ if (existsSync(join(workspace, 'sql')))
7
+ throw new Error('PROJECT_LAYOUT_UNSUPPORTED: sql/ is not supported; use database-functions/');
8
+ return existsSync(join(workspace, DATABASE_FUNCTIONS_DIRECTORY))
9
+ ? DATABASE_FUNCTIONS_DIRECTORY
10
+ : undefined;
17
11
  }
18
12
  export function requireDatabaseFunctionsDirectory(workspace) {
19
13
  const directory = databaseFunctionsDirectory(workspace);
20
- if (!directory) {
14
+ if (!directory)
21
15
  throw new Error(`Required project directory is missing: ${DATABASE_FUNCTIONS_DIRECTORY}`);
22
- }
23
16
  return directory;
24
17
  }
25
18
  /** Explicit configuration selects the layout; dependencies never select it. */
@@ -28,25 +21,15 @@ export function projectLayout(workspace) {
28
21
  const config = existsSync(configPath)
29
22
  ? parseProjectConfig(readFileSync(configPath, 'utf8'), configPath)
30
23
  : {};
31
- const version = config?.template === undefined ? 1 : config.template?.version;
32
24
  const fail = (message) => {
33
25
  throw new Error(`TEMPLATE_LAYOUT_CONFLICT: ${message}`);
34
26
  };
35
- if (version !== 1 && version !== 2)
36
- fail(`Unsupported template version ${String(version)}`);
37
- if (version === 1) {
38
- if (existsSync(join(workspace, 'server')))
39
- fail('Template 1 cannot contain server/');
40
- const rootManifest = join(workspace, 'package.json');
41
- if (existsSync(rootManifest) &&
42
- JSON.parse(readFileSync(rootManifest, 'utf8')).workspaces)
43
- fail('Template 1 cannot contain root workspaces');
44
- return {
45
- version: 1,
46
- server: 'server-functions',
47
- dependencies: ['page', 'server-functions'],
48
- };
49
- }
27
+ if (config?.template?.version !== 2 ||
28
+ config.template.name !== 'database-starter')
29
+ fail('PROJECT_LAYOUT_UNSUPPORTED: only template.version 2 workspace projects are supported');
30
+ if (config.functionInputs !== undefined && config.functionInputs !== 'named')
31
+ fail('PROJECT_LAYOUT_UNSUPPORTED: workspace clients require named inputs');
32
+ databaseFunctionsDirectory(workspace);
50
33
  if (existsSync(join(workspace, 'server-functions')))
51
34
  fail('Template 2 cannot contain server-functions/');
52
35
  for (const directory of ['page', 'server']) {
@@ -21,28 +21,17 @@ export class SDKCodegenError extends Error {
21
21
  };
22
22
  }
23
23
  }
24
- function dependencyRecovery(root) {
25
- const layout = {
26
- version: existsSync(join(root, 'server')) ? 2 : 1,
27
- dependencies: ['page', 'server-functions'],
28
- };
29
- const install = layout.version === 2
30
- ? 'npm ci'
31
- : layout.dependencies
32
- .map((directory) => `npm ci --prefix ${directory}`)
33
- .join('; ');
24
+ function dependencyRecovery() {
34
25
  return [
35
- `From the project root, restore dependencies from the existing manifests and lockfiles: ${install}. Keep the declared SDK version unchanged.`,
26
+ `From the project root, restore dependencies from the existing manifests and lockfiles: npm ci. Keep the declared SDK version unchanged.`,
36
27
  'If dependencies are already installed but the SDK lacks codegen, keep the current SDK and upgrade only with user authorization; follow its Migration instructions.',
37
28
  'Once codegen is available, use the same CLI and environment to run contracts generate, then check --json.',
38
29
  ];
39
30
  }
40
- function unavailable(root, missingExport = false) {
31
+ function unavailable(_root, missingExport = false) {
41
32
  throw new SDKCodegenError('SDK_CODEGEN_UNAVAILABLE', missingExport
42
33
  ? 'The installed SDK codegen does not export generateFunctionClients.'
43
- : 'Cannot resolve the installed SDK codegen entry. Project dependencies may not be installed, or the installed SDK may not provide codegen.', missingExport
44
- ? dependencyRecovery(root).slice(1)
45
- : dependencyRecovery(root));
34
+ : 'Cannot resolve the installed SDK codegen entry. Project dependencies may not be installed, or the installed SDK may not provide codegen.', missingExport ? dependencyRecovery().slice(1) : dependencyRecovery());
46
35
  }
47
36
  // Node 24 removed the experimental spelling; early Node 22 releases only have it.
48
37
  const permissionFlag = process.allowedNodeEnvironmentFlags.has('--permission')
@@ -50,6 +39,12 @@ const permissionFlag = process.allowedNodeEnvironmentFlags.has('--permission')
50
39
  : '--experimental-permission';
51
40
  /** Resolve/snapshot reads package bytes only; project modules execute only in the restricted child. */
52
41
  export function runSDKCodegen(root, data, server = 'server') {
42
+ if (server !== 'server' ||
43
+ (data &&
44
+ typeof data === 'object' &&
45
+ 'layout' in data &&
46
+ data.layout !== 'workspace'))
47
+ throw new SDKCodegenError('PROJECT_LAYOUT_UNSUPPORTED', 'Code generation requires named workspace contracts.');
53
48
  const entry = resolveSDKCodegenEntry(root, server);
54
49
  if (!entry)
55
50
  unavailable(root);
@@ -75,6 +70,17 @@ globalThis.WebSocket = undefined;
75
70
  const input = JSON.parse(require('node:fs').readFileSync(__dirname + '/input.json','utf8'));
76
71
  const sdk = require('@lark-base-open/base-database-app-sdk/codegen');
77
72
  if (typeof sdk.generateFunctionClients !== 'function') throw Object.assign(new Error('SDK codegen export missing'),{code:'SDK_CODEGEN_UNAVAILABLE'});
73
+ // SDKs without DML_BATCH_LIMITS accept at most 200 groups at codegen and at runtime;
74
+ // cap the published value to the installed SDK so a raised backend limit keeps its batch clients.
75
+ const declared = sdk.DML_BATCH_LIMITS;
76
+ const limit = key => declared && Number.isSafeInteger(declared[key]) && declared[key] >= 1 ? declared[key] : 200;
77
+ for (const list of ['functions','inputs']) if (Array.isArray(input[list])) input[list] = input[list].map(fn => {
78
+ const c = fn && fn.batchCapability;
79
+ if (!c || typeof c !== 'object' || Array.isArray(c)) return fn;
80
+ const next = {...c};
81
+ for (const key of ['maxGroups','maxTotalRows']) if (Number.isSafeInteger(next[key]) && next[key] > limit(key)) next[key] = limit(key);
82
+ return {...fn, batchCapability: next};
83
+ });
78
84
  const files = await sdk.generateFunctionClients(input);
79
85
  process.stdout.write(JSON.stringify({ok:true,files}));
80
86
  } catch (error) {
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@lark-base-open/base-database-toolchain",
3
- "version": "1.4.1",
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.4.1",
9
+ "version": "1.5.1",
10
10
  "license": "SEE LICENSE IN LICENSE",
11
11
  "dependencies": {
12
12
  "@babel/parser": "7.28.5",
13
13
  "@babel/traverse": "7.28.5",
14
- "ajv": "8.17.1",
14
+ "ajv": "8.20.0",
15
15
  "esbuild": "0.28.2",
16
16
  "jsonc-parser": "3.3.1",
17
17
  "parse5": "7.3.0",
18
- "re2js": "2.8.6"
18
+ "re2js": "2.10.0"
19
19
  },
20
20
  "bin": {
21
21
  "base-database-dev": "bin/base-database-dev.mjs",
@@ -978,9 +978,9 @@
978
978
  }
979
979
  },
980
980
  "node_modules/ajv": {
981
- "version": "8.17.1",
982
- "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz",
983
- "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
981
+ "version": "8.20.0",
982
+ "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz",
983
+ "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==",
984
984
  "license": "MIT",
985
985
  "dependencies": {
986
986
  "fast-deep-equal": "^3.1.3",
@@ -1140,12 +1140,12 @@
1140
1140
  "license": "ISC"
1141
1141
  },
1142
1142
  "node_modules/re2js": {
1143
- "version": "2.8.6",
1144
- "resolved": "https://registry.npmjs.org/re2js/-/re2js-2.8.6.tgz",
1145
- "integrity": "sha512-xLgQil4kIUCrAzVk9fRSkxkFNwmygLFjVxXrLc65aE1F0+Zsb8rxumFBy4XKyvgMCTL6kilDq3EZ0piE2dP/Dg==",
1143
+ "version": "2.10.0",
1144
+ "resolved": "https://registry.npmjs.org/re2js/-/re2js-2.10.0.tgz",
1145
+ "integrity": "sha512-/P6FNnLbHjXJMRF1dPoZoVTyHvFcuVhbDpzml9DPMlbeErYlZ18GueAaG9GhYhAm/9AN7i7Y6crmDrLX0DeJ4Q==",
1146
1146
  "license": "MIT",
1147
1147
  "engines": {
1148
- "node": ">=18.0.0"
1148
+ "node": ">=20.0.0"
1149
1149
  }
1150
1150
  },
1151
1151
  "node_modules/require-from-string": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-base-open/base-database-toolchain",
3
- "version": "1.4.1",
3
+ "version": "1.5.1",
4
4
  "description": "Shared local development toolchain for Base Database application CLIs",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -89,11 +89,11 @@
89
89
  "dependencies": {
90
90
  "@babel/parser": "7.28.5",
91
91
  "@babel/traverse": "7.28.5",
92
- "ajv": "8.17.1",
92
+ "ajv": "8.20.0",
93
93
  "esbuild": "0.28.2",
94
94
  "jsonc-parser": "3.3.1",
95
95
  "parse5": "7.3.0",
96
- "re2js": "2.8.6"
96
+ "re2js": "2.10.0"
97
97
  },
98
98
  "devDependencies": {
99
99
  "typescript": "7.0.2",