@lark-base-open/base-database-toolchain 1.2.0 → 1.3.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 +27 -0
- package/README.md +7 -1
- package/bin/base-database-toolchain.mjs +13 -1
- package/dist/app-builder/core.d.mts +4 -0
- package/dist/app-builder/core.mjs +736 -110
- package/dist/app-builder/package.json +1 -1
- package/dist/data/config-schema.json +95 -0
- package/dist/dependency-policy.d.ts +13 -0
- package/dist/dependency-policy.js +187 -0
- package/dist/dev-worker.mjs +27 -21
- package/dist/function-description.d.ts +12 -0
- package/dist/function-description.js +38 -0
- package/dist/function-params.d.ts +50 -0
- package/dist/function-params.js +157 -0
- package/dist/function-schema.d.ts +35 -0
- package/dist/function-schema.js +490 -0
- package/dist/go-adapter.d.mts +1 -1
- package/dist/go-adapter.mjs +299 -225
- package/dist/mutation-schema.d.ts +151 -0
- package/dist/mutation-schema.js +158 -0
- package/dist/mutation.d.ts +12 -0
- package/dist/mutation.js +145 -0
- package/dist/npm-policy.d.ts +16 -0
- package/dist/npm-policy.js +193 -0
- package/dist/page-link-guard.js +3 -2
- package/dist/project-contract.d.ts +2 -0
- package/dist/project-contract.js +38 -0
- package/dist/project-layout.d.ts +15 -0
- package/dist/project-layout.js +89 -0
- package/dist/source-archive-inputs.d.ts +13 -0
- package/dist/source-archive-inputs.js +105 -0
- package/npm-shrinkwrap.json +13 -3
- package/package.json +15 -2
package/dist/page-link-guard.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
-
import { extname, join, relative } from 'node:path';
|
|
2
|
+
import { extname, join, relative, sep } from 'node:path';
|
|
3
3
|
import { parse } from '@babel/parser';
|
|
4
4
|
const channelPackage = '@lark-base-open/base-site-channel';
|
|
5
5
|
const extensions = new Set(['.ts', '.tsx', '.js', '.jsx']);
|
|
@@ -80,6 +80,7 @@ export function checkLinkGuard(workspace) {
|
|
|
80
80
|
guards.add(specifier.local.name);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
+
const file = relative(workspace, path).split(sep).join('/');
|
|
83
84
|
walk(source.program, (node) => {
|
|
84
85
|
if (node.type === 'CallExpression' ||
|
|
85
86
|
node.type === 'OptionalCallExpression') {
|
|
@@ -118,7 +119,7 @@ export function checkLinkGuard(workspace) {
|
|
|
118
119
|
// Every parsed source node has a location; metadata nodes are not visited.
|
|
119
120
|
const loc = node.loc;
|
|
120
121
|
locations.push({
|
|
121
|
-
file
|
|
122
|
+
file,
|
|
122
123
|
line: loc.start.line,
|
|
123
124
|
column: loc.start.column + 1,
|
|
124
125
|
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join, dirname } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import Ajv2020 from 'ajv/dist/2020.js';
|
|
5
|
+
import { parseProjectConfig } from './app-builder/core.mjs';
|
|
6
|
+
const CONFIG_FILE_NAME = 'base-database.jsonc';
|
|
7
|
+
const schema = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), 'data/config-schema.json'), 'utf8'));
|
|
8
|
+
const validate = new Ajv2020({ allErrors: true }).compile(schema);
|
|
9
|
+
/** Only portable, non-identity project contracts may survive source archive recovery. */
|
|
10
|
+
export function readPortableProjectContract(workspace) {
|
|
11
|
+
const path = join(workspace, CONFIG_FILE_NAME);
|
|
12
|
+
let source;
|
|
13
|
+
try {
|
|
14
|
+
source = readFileSync(path, 'utf8');
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT')
|
|
18
|
+
return {};
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
const raw = parseProjectConfig(source, path);
|
|
22
|
+
const contract = {
|
|
23
|
+
...(raw.template === undefined ? {} : { template: raw.template }),
|
|
24
|
+
...(raw.functionInputs === undefined
|
|
25
|
+
? {}
|
|
26
|
+
: { functionInputs: raw.functionInputs }),
|
|
27
|
+
...(raw.managedAgentDocs === undefined
|
|
28
|
+
? {}
|
|
29
|
+
: { managedAgentDocs: raw.managedAgentDocs }),
|
|
30
|
+
};
|
|
31
|
+
if (!validate({
|
|
32
|
+
configVersion: raw.configVersion === undefined ? 1 : raw.configVersion,
|
|
33
|
+
appToken: 'restored-project',
|
|
34
|
+
...contract,
|
|
35
|
+
}))
|
|
36
|
+
throw new Error(`Invalid source project contract: ${validate.errors?.map((error) => `${error.instancePath} ${error.message}`).join('; ')}`);
|
|
37
|
+
return contract;
|
|
38
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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;
|
|
5
|
+
/** Explicit configuration selects the layout; dependencies never select it. */
|
|
6
|
+
export declare function projectLayout(workspace: string): {
|
|
7
|
+
version: 1;
|
|
8
|
+
server: string;
|
|
9
|
+
dependencies: string[];
|
|
10
|
+
} | {
|
|
11
|
+
version: 2;
|
|
12
|
+
server: string;
|
|
13
|
+
dependencies: string[];
|
|
14
|
+
};
|
|
15
|
+
export declare function serverDirectory(workspace: string): string;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { parseProjectConfig } from './app-builder/core.mjs';
|
|
2
|
+
import { existsSync, readFileSync, lstatSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
export const DATABASE_FUNCTIONS_DIRECTORY = 'database-functions';
|
|
5
|
+
export const LEGACY_DATABASE_FUNCTIONS_DIRECTORY = 'sql';
|
|
6
|
+
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;
|
|
17
|
+
}
|
|
18
|
+
export function requireDatabaseFunctionsDirectory(workspace) {
|
|
19
|
+
const directory = databaseFunctionsDirectory(workspace);
|
|
20
|
+
if (!directory) {
|
|
21
|
+
throw new Error(`Required project directory is missing: ${DATABASE_FUNCTIONS_DIRECTORY}`);
|
|
22
|
+
}
|
|
23
|
+
return directory;
|
|
24
|
+
}
|
|
25
|
+
/** Explicit configuration selects the layout; dependencies never select it. */
|
|
26
|
+
export function projectLayout(workspace) {
|
|
27
|
+
const configPath = join(workspace, 'base-database.jsonc');
|
|
28
|
+
const config = existsSync(configPath)
|
|
29
|
+
? parseProjectConfig(readFileSync(configPath, 'utf8'), configPath)
|
|
30
|
+
: {};
|
|
31
|
+
const version = config?.template === undefined ? 1 : config.template?.version;
|
|
32
|
+
const fail = (message) => {
|
|
33
|
+
throw new Error(`TEMPLATE_LAYOUT_CONFLICT: ${message}`);
|
|
34
|
+
};
|
|
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
|
+
}
|
|
50
|
+
if (existsSync(join(workspace, 'server-functions')))
|
|
51
|
+
fail('Template 2 cannot contain server-functions/');
|
|
52
|
+
for (const directory of ['page', 'server']) {
|
|
53
|
+
if (!existsSync(join(workspace, directory)) ||
|
|
54
|
+
!lstatSync(join(workspace, directory)).isDirectory())
|
|
55
|
+
fail(`Missing or non-regular ${directory}/`);
|
|
56
|
+
for (const lock of [
|
|
57
|
+
'package-lock.json',
|
|
58
|
+
'npm-shrinkwrap.json',
|
|
59
|
+
'pnpm-lock.yaml',
|
|
60
|
+
'yarn.lock',
|
|
61
|
+
])
|
|
62
|
+
if (existsSync(join(workspace, directory, lock)))
|
|
63
|
+
fail(`Nested lock: ${directory}/${lock}`);
|
|
64
|
+
}
|
|
65
|
+
for (const lock of ['npm-shrinkwrap.json', 'pnpm-lock.yaml', 'yarn.lock'])
|
|
66
|
+
if (existsSync(join(workspace, lock)))
|
|
67
|
+
fail(`Template 2 requires a single package-lock.json: ${lock}`);
|
|
68
|
+
let manifest;
|
|
69
|
+
try {
|
|
70
|
+
manifest = JSON.parse(readFileSync(join(workspace, 'package.json'), 'utf8'));
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return fail('Missing or invalid root package.json');
|
|
74
|
+
}
|
|
75
|
+
if (!Array.isArray(manifest.workspaces) ||
|
|
76
|
+
JSON.stringify(manifest.workspaces.slice().sort()) !==
|
|
77
|
+
'["page","server"]' ||
|
|
78
|
+
manifest.type !== 'module' ||
|
|
79
|
+
manifest.private !== true)
|
|
80
|
+
fail('Root must be private ESM with workspaces [page, server]');
|
|
81
|
+
return {
|
|
82
|
+
version: 2,
|
|
83
|
+
server: 'server',
|
|
84
|
+
dependencies: ['.'],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export function serverDirectory(workspace) {
|
|
88
|
+
return projectLayout(workspace).server;
|
|
89
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const SOURCE_ARCHIVE_IGNORES: string[];
|
|
2
|
+
export declare const SOURCE_ARCHIVE_SKIPS: string[];
|
|
3
|
+
export declare function sourceArchiveEntryIgnored(name: string, directory: boolean): boolean;
|
|
4
|
+
export declare const SOURCE_DIRECTORIES: string[];
|
|
5
|
+
export declare const SOURCE_ROOT_FILES: string[];
|
|
6
|
+
export declare function sourceArchiveRoots(workspace: string): {
|
|
7
|
+
source: string;
|
|
8
|
+
prefix: string;
|
|
9
|
+
}[];
|
|
10
|
+
export declare function sourceArchiveRootFiles(workspace: string): string[];
|
|
11
|
+
export declare const LEGACY_SOURCE_ROOT_FILES: string[];
|
|
12
|
+
export declare function legacySourceRootFiles(workspace: string): string[];
|
|
13
|
+
export declare function sourceArchiveConfig(workspace: string): string;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { lstatSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { readPortableProjectContract } from './project-contract.js';
|
|
4
|
+
import { DATABASE_FUNCTIONS_DIRECTORY, databaseFunctionsDirectory, serverDirectory, } from './project-layout.js';
|
|
5
|
+
const excludedDirectories = new Set([
|
|
6
|
+
'node_modules',
|
|
7
|
+
'dist',
|
|
8
|
+
'.cache',
|
|
9
|
+
'.git',
|
|
10
|
+
'.base-database-cli',
|
|
11
|
+
'.npm',
|
|
12
|
+
'.pnpm-store',
|
|
13
|
+
'coverage',
|
|
14
|
+
'.aws',
|
|
15
|
+
'.ssh',
|
|
16
|
+
]);
|
|
17
|
+
const excludedNames = new Set([
|
|
18
|
+
'.DS_Store',
|
|
19
|
+
'.env',
|
|
20
|
+
'.npmrc',
|
|
21
|
+
'.yarnrc',
|
|
22
|
+
'.yarnrc.yml',
|
|
23
|
+
'.pnpmrc',
|
|
24
|
+
'.netrc',
|
|
25
|
+
]);
|
|
26
|
+
const excludedPrefixes = ['.env.'];
|
|
27
|
+
const excludedSuffixes = ['.pem', '.key'];
|
|
28
|
+
// Both preflight traversal and archiver globs derive their exclusions here.
|
|
29
|
+
const excludedPathPatterns = [
|
|
30
|
+
...[...excludedNames].map((name) => `**/${name}`),
|
|
31
|
+
...excludedPrefixes.map((prefix) => `**/${prefix}*`),
|
|
32
|
+
...excludedSuffixes.map((suffix) => `**/*${suffix}`),
|
|
33
|
+
];
|
|
34
|
+
export const SOURCE_ARCHIVE_IGNORES = [
|
|
35
|
+
...[...excludedDirectories].map((name) => `**/${name}/**`),
|
|
36
|
+
...excludedPathPatterns,
|
|
37
|
+
];
|
|
38
|
+
export const SOURCE_ARCHIVE_SKIPS = [
|
|
39
|
+
...[...excludedDirectories].map((name) => `**/${name}`),
|
|
40
|
+
...excludedPathPatterns,
|
|
41
|
+
];
|
|
42
|
+
export function sourceArchiveEntryIgnored(name, directory) {
|
|
43
|
+
return ((directory && excludedDirectories.has(name)) ||
|
|
44
|
+
excludedNames.has(name) ||
|
|
45
|
+
excludedPrefixes.some((prefix) => name.startsWith(prefix)) ||
|
|
46
|
+
excludedSuffixes.some((suffix) => name.endsWith(suffix)));
|
|
47
|
+
}
|
|
48
|
+
export const SOURCE_DIRECTORIES = [
|
|
49
|
+
'page',
|
|
50
|
+
'server-functions',
|
|
51
|
+
'server',
|
|
52
|
+
'mutations',
|
|
53
|
+
'skill',
|
|
54
|
+
'ai',
|
|
55
|
+
DATABASE_FUNCTIONS_DIRECTORY,
|
|
56
|
+
'sql',
|
|
57
|
+
];
|
|
58
|
+
// Read existing snapshots without expanding the format 1 writer scope.
|
|
59
|
+
export const SOURCE_ROOT_FILES = [
|
|
60
|
+
'base-app.config.ts',
|
|
61
|
+
'README.md',
|
|
62
|
+
'agent-tools.json',
|
|
63
|
+
'package.json',
|
|
64
|
+
'package-lock.json',
|
|
65
|
+
'pnpm-lock.yaml',
|
|
66
|
+
'pnpm-workspace.yaml',
|
|
67
|
+
'yarn.lock',
|
|
68
|
+
'tsconfig.json',
|
|
69
|
+
];
|
|
70
|
+
export function sourceArchiveRoots(workspace) {
|
|
71
|
+
// Check before layout discovery: existsSync would hide dangling links, and
|
|
72
|
+
// using a source root as a glob cwd would otherwise follow directory links.
|
|
73
|
+
for (const source of SOURCE_DIRECTORIES) {
|
|
74
|
+
const info = lstatSync(join(workspace, source), { throwIfNoEntry: false });
|
|
75
|
+
if (info && !info.isDirectory())
|
|
76
|
+
throw new Error(`Project ${source}/ must be a directory`);
|
|
77
|
+
}
|
|
78
|
+
const databaseFunctions = databaseFunctionsDirectory(workspace);
|
|
79
|
+
return [
|
|
80
|
+
...['page', serverDirectory(workspace), 'mutations', 'ai', 'skill'].map((source) => ({ source, prefix: source })),
|
|
81
|
+
...(databaseFunctions
|
|
82
|
+
? [{ source: databaseFunctions, prefix: DATABASE_FUNCTIONS_DIRECTORY }]
|
|
83
|
+
: []),
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
export function sourceArchiveRootFiles(workspace) {
|
|
87
|
+
return legacySourceRootFiles(workspace);
|
|
88
|
+
}
|
|
89
|
+
export const LEGACY_SOURCE_ROOT_FILES = [
|
|
90
|
+
'base-app.config.ts',
|
|
91
|
+
'README.md',
|
|
92
|
+
'agent-tools.json',
|
|
93
|
+
];
|
|
94
|
+
// Old archives did not collect all root files. Absence outside this scope is not deletion.
|
|
95
|
+
export function legacySourceRootFiles(workspace) {
|
|
96
|
+
return [
|
|
97
|
+
...LEGACY_SOURCE_ROOT_FILES,
|
|
98
|
+
...(serverDirectory(workspace) === 'server'
|
|
99
|
+
? ['package.json', 'package-lock.json']
|
|
100
|
+
: []),
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
export function sourceArchiveConfig(workspace) {
|
|
104
|
+
return (JSON.stringify({ configVersion: 1, ...readPortableProjectContract(workspace) }, null, 2) + '\n');
|
|
105
|
+
}
|
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.3.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.
|
|
9
|
+
"version": "1.3.1",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@babel/parser": "7.28.5",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"ajv": "8.17.1",
|
|
15
15
|
"esbuild": "0.28.2",
|
|
16
16
|
"jsonc-parser": "3.3.1",
|
|
17
|
-
"parse5": "7.3.0"
|
|
17
|
+
"parse5": "7.3.0",
|
|
18
|
+
"re2js": "2.8.6"
|
|
18
19
|
},
|
|
19
20
|
"bin": {
|
|
20
21
|
"base-database-dev": "bin/base-database-dev.mjs",
|
|
@@ -1138,6 +1139,15 @@
|
|
|
1138
1139
|
"integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
|
|
1139
1140
|
"license": "ISC"
|
|
1140
1141
|
},
|
|
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==",
|
|
1146
|
+
"license": "MIT",
|
|
1147
|
+
"engines": {
|
|
1148
|
+
"node": ">=18.0.0"
|
|
1149
|
+
}
|
|
1150
|
+
},
|
|
1141
1151
|
"node_modules/require-from-string": {
|
|
1142
1152
|
"version": "2.0.2",
|
|
1143
1153
|
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-base-open/base-database-toolchain",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Shared local development toolchain for Base Database application CLIs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -52,6 +52,18 @@
|
|
|
52
52
|
"./development": {
|
|
53
53
|
"types": "./dist/development.d.ts",
|
|
54
54
|
"import": "./dist/development.js"
|
|
55
|
+
},
|
|
56
|
+
"./dependency-policy": {
|
|
57
|
+
"types": "./dist/dependency-policy.d.ts",
|
|
58
|
+
"import": "./dist/dependency-policy.js"
|
|
59
|
+
},
|
|
60
|
+
"./project-layout": {
|
|
61
|
+
"types": "./dist/project-layout.d.ts",
|
|
62
|
+
"import": "./dist/project-layout.js"
|
|
63
|
+
},
|
|
64
|
+
"./source-archive-inputs": {
|
|
65
|
+
"types": "./dist/source-archive-inputs.d.ts",
|
|
66
|
+
"import": "./dist/source-archive-inputs.js"
|
|
55
67
|
}
|
|
56
68
|
},
|
|
57
69
|
"files": [
|
|
@@ -80,7 +92,8 @@
|
|
|
80
92
|
"ajv": "8.17.1",
|
|
81
93
|
"esbuild": "0.28.2",
|
|
82
94
|
"jsonc-parser": "3.3.1",
|
|
83
|
-
"parse5": "7.3.0"
|
|
95
|
+
"parse5": "7.3.0",
|
|
96
|
+
"re2js": "2.8.6"
|
|
84
97
|
},
|
|
85
98
|
"devDependencies": {
|
|
86
99
|
"typescript": "7.0.2",
|