@lark-base-open/base-database-toolchain 0.0.0-stage → 1.1.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +6 -0
  3. package/README.md +82 -2
  4. package/bin/base-database-dev.mjs +4 -0
  5. package/bin/base-database-toolchain.mjs +22 -0
  6. package/dist/app-builder/core.d.mts +37 -0
  7. package/dist/app-builder/core.mjs +716 -0
  8. package/dist/app-builder/package.json +1 -0
  9. package/dist/app-builder/schema.d.ts +3 -0
  10. package/dist/app-builder/schema.js +71 -0
  11. package/dist/contract-conversion.d.ts +41 -0
  12. package/dist/contract-conversion.js +116 -0
  13. package/dist/contract-extractor.d.ts +23 -0
  14. package/dist/contract-extractor.js +245 -0
  15. package/dist/data/development-pairing.json +11 -0
  16. package/dist/data/template-hmr-scripts.json +9 -0
  17. package/dist/dependency-inputs.d.ts +3 -0
  18. package/dist/dependency-inputs.js +18 -0
  19. package/dist/dev-ipc-worker.d.ts +1 -0
  20. package/dist/dev-ipc-worker.js +35 -0
  21. package/dist/dev-redaction.d.ts +1 -0
  22. package/dist/dev-redaction.js +3 -0
  23. package/dist/dev-snapshot.d.ts +3 -0
  24. package/dist/dev-snapshot.js +98 -0
  25. package/dist/dev-vite-server.d.ts +14 -0
  26. package/dist/dev-vite-server.js +213 -0
  27. package/dist/dev-worker.d.mts +1 -0
  28. package/dist/dev-worker.mjs +134 -0
  29. package/dist/development-pairing.generated.d.ts +11 -0
  30. package/dist/development-pairing.generated.js +12 -0
  31. package/dist/development.d.ts +6 -0
  32. package/dist/development.js +6 -0
  33. package/dist/durable-runner.d.ts +102 -0
  34. package/dist/durable-runner.js +128 -0
  35. package/dist/function-batch.d.ts +48 -0
  36. package/dist/function-batch.js +99 -0
  37. package/dist/go-adapter.d.mts +11 -0
  38. package/dist/go-adapter.mjs +847 -0
  39. package/dist/index.d.ts +8 -0
  40. package/dist/index.js +8 -0
  41. package/dist/page-bootstrap.d.ts +3 -0
  42. package/dist/page-bootstrap.js +178 -0
  43. package/dist/page-inspection.d.ts +11 -0
  44. package/dist/page-inspection.js +49 -0
  45. package/dist/page-link-guard.d.ts +12 -0
  46. package/dist/page-link-guard.js +137 -0
  47. package/dist/sdk-codegen.d.ts +16 -0
  48. package/dist/sdk-codegen.js +208 -0
  49. package/dist/trigger-validation.d.ts +75 -0
  50. package/dist/trigger-validation.js +73 -0
  51. package/npm-shrinkwrap.json +1193 -0
  52. package/package.json +87 -4
@@ -0,0 +1 @@
1
+ {"type":"module","version":"1.0.7"}
@@ -0,0 +1,3 @@
1
+ /** Schema keywords are interpreted only at schema locations; property names and instance data are not keywords. */
2
+ export declare function walkSchemaNodes(value: unknown, visit: (schema: Record<string, unknown>) => void): void;
3
+ export declare function validateFullSchema(value: unknown): asserts value is Record<string, unknown>;
@@ -0,0 +1,71 @@
1
+ /** Schema keywords are interpreted only at schema locations; property names and instance data are not keywords. */
2
+ export function walkSchemaNodes(value, visit) {
3
+ if (!value || typeof value !== 'object' || Array.isArray(value))
4
+ return;
5
+ const schema = value;
6
+ visit(schema);
7
+ for (const key of [
8
+ 'properties',
9
+ 'patternProperties',
10
+ '$defs',
11
+ 'definitions',
12
+ 'dependentSchemas',
13
+ ]) {
14
+ const map = schema[key];
15
+ if (map && typeof map === 'object' && !Array.isArray(map))
16
+ for (const child of Object.values(map))
17
+ walkSchemaNodes(child, visit);
18
+ }
19
+ for (const key of [
20
+ 'items',
21
+ 'additionalItems',
22
+ 'additionalProperties',
23
+ 'unevaluatedProperties',
24
+ 'unevaluatedItems',
25
+ 'contains',
26
+ 'propertyNames',
27
+ 'not',
28
+ 'if',
29
+ 'then',
30
+ 'else',
31
+ ]) {
32
+ const child = schema[key];
33
+ if (Array.isArray(child))
34
+ child.forEach((v) => walkSchemaNodes(v, visit));
35
+ else
36
+ walkSchemaNodes(child, visit);
37
+ }
38
+ for (const key of ['allOf', 'anyOf', 'oneOf', 'prefixItems'])
39
+ if (Array.isArray(schema[key]))
40
+ schema[key].forEach((v) => walkSchemaNodes(v, visit));
41
+ const dependencies = schema.dependencies;
42
+ if (dependencies &&
43
+ typeof dependencies === 'object' &&
44
+ !Array.isArray(dependencies))
45
+ for (const child of Object.values(dependencies))
46
+ if (!Array.isArray(child))
47
+ walkSchemaNodes(child, visit);
48
+ }
49
+ export function validateFullSchema(value) {
50
+ if (!value ||
51
+ typeof value !== 'object' ||
52
+ Array.isArray(value) ||
53
+ Buffer.byteLength(JSON.stringify(value)) > 32768)
54
+ throw new Error('CONTRACT_SCHEMA_BUDGET');
55
+ let nodes = 0;
56
+ const budget = (v, depth) => {
57
+ if (!v || typeof v !== 'object')
58
+ return;
59
+ if (++nodes > 256 || depth > 16)
60
+ throw new Error('CONTRACT_SCHEMA_BUDGET');
61
+ Object.values(v).forEach((child) => budget(child, depth + 1));
62
+ };
63
+ budget(value, 0);
64
+ walkSchemaNodes(value, (schema) => {
65
+ if (Object.hasOwn(schema, '$ref') &&
66
+ (typeof schema.$ref !== 'string' || !schema.$ref.startsWith('#/')))
67
+ throw new Error('CONTRACT_EXTERNAL_REF');
68
+ if (['$id', '$dynamicRef', '$recursiveRef', 'tsType', 'tsEnumNames'].some((key) => Object.hasOwn(schema, key)))
69
+ throw new Error('CONTRACT_EXTERNAL_REF');
70
+ });
71
+ }
@@ -0,0 +1,41 @@
1
+ export interface ConvertedContract {
2
+ input?: Record<string, unknown>;
3
+ output?: Record<string, unknown>;
4
+ warnings: string[];
5
+ events?: Record<string, Record<string, unknown>>;
6
+ }
7
+ interface RuntimeSchema {
8
+ _zod?: {
9
+ def: {
10
+ type: string;
11
+ coerce?: boolean;
12
+ out?: RuntimeSchema;
13
+ checks?: RuntimeSchema[];
14
+ check?: string;
15
+ pattern?: RegExp;
16
+ };
17
+ };
18
+ }
19
+ interface LoadedContractSchemas {
20
+ input?: RuntimeSchema;
21
+ output?: RuntimeSchema;
22
+ events?: Record<string, RuntimeSchema>;
23
+ z: {
24
+ toJSONSchema(schema: RuntimeSchema, options: {
25
+ target: string;
26
+ io: 'input' | 'output';
27
+ unrepresentable: (value: {
28
+ path: (string | number)[];
29
+ }) => string;
30
+ override: (value: {
31
+ zodSchema: RuntimeSchema;
32
+ path: (string | number)[];
33
+ }) => void;
34
+ }): Record<string, unknown>;
35
+ };
36
+ }
37
+ export declare function convertLoadedContract(schemas: LoadedContractSchemas, context: {
38
+ functionId: string;
39
+ displayPath: string;
40
+ }): ConvertedContract;
41
+ export {};
@@ -0,0 +1,116 @@
1
+ class RegexFlagsError extends Error {
2
+ }
3
+ const ALLOWED = new Set([
4
+ 'any',
5
+ 'array',
6
+ 'boolean',
7
+ 'default',
8
+ 'enum',
9
+ 'intersection',
10
+ 'lazy',
11
+ 'literal',
12
+ 'never',
13
+ 'nullable',
14
+ 'number',
15
+ 'object',
16
+ 'optional',
17
+ 'readonly',
18
+ 'record',
19
+ 'string',
20
+ 'tuple',
21
+ 'union',
22
+ 'unknown',
23
+ ]);
24
+ export function convertLoadedContract(schemas, context) {
25
+ const result = { warnings: [] };
26
+ let runtimeOnly = false;
27
+ for (const direction of ['input', 'output']) {
28
+ if (!schemas[direction]?._zod) {
29
+ throw new Error(`Export "${direction}" must be a Zod schema`);
30
+ }
31
+ let schemaPath = direction;
32
+ try {
33
+ result[direction] = schemas.z.toJSONSchema(schemas[direction], {
34
+ target: 'draft-2020-12',
35
+ io: direction,
36
+ unrepresentable: ({ path }) => {
37
+ schemaPath = [direction, ...path].join('.');
38
+ return 'throw';
39
+ },
40
+ override: ({ zodSchema, path }) => {
41
+ const def = zodSchema._zod.def;
42
+ const patterns = [
43
+ def,
44
+ ...(def.checks ?? []).map((check) => check._zod?.def),
45
+ ];
46
+ if (patterns.some((check) => check?.pattern?.flags)) {
47
+ throw new RegexFlagsError(`${context.functionId}: ${[direction, ...path].join('.')}: regex flags cannot be preserved in JSON Schema; rewrite as a flag-independent RE2 expression or remove the regex`);
48
+ }
49
+ if (def.type === 'pipe' && def.out?._zod?.def.type === 'transform') {
50
+ schemaPath = [direction, ...path].join('.');
51
+ throw new Error('Transforms cannot be represented in JSON Schema');
52
+ }
53
+ if (direction === 'input' && def.coerce === true) {
54
+ schemaPath = [direction, ...path].join('.');
55
+ throw new Error('Coercion cannot be represented in an input JSON Schema');
56
+ }
57
+ if (direction === 'input' && def.type === 'pipe') {
58
+ schemaPath = [direction, ...path].join('.');
59
+ throw new Error('Pipes cannot be represented in an input JSON Schema');
60
+ }
61
+ const checks = def.checks ?? [];
62
+ if (checks.some((check) => check._zod?.def.check === 'custom')) {
63
+ schemaPath = [direction, ...path].join('.');
64
+ throw new Error('Custom refinements cannot be represented in JSON Schema');
65
+ }
66
+ if (direction === 'input' &&
67
+ checks.some((check) => check._zod?.def.check === 'overwrite')) {
68
+ schemaPath = [direction, ...path].join('.');
69
+ throw new Error('Input overwrites cannot be represented in JSON Schema');
70
+ }
71
+ if (def.type !== 'pipe' && !ALLOWED.has(def.type)) {
72
+ schemaPath = [direction, ...path].join('.');
73
+ throw new Error(`Zod type "${def.type}" cannot be represented in a JSON Schema`);
74
+ }
75
+ },
76
+ });
77
+ }
78
+ catch (error) {
79
+ if (error instanceof RegexFlagsError)
80
+ throw error;
81
+ const reason = error instanceof Error ? error.message : String(error);
82
+ const fix = /transform/i.test(reason)
83
+ ? `Remove .transform() from the ${direction} schema and convert the value inside the handler`
84
+ : /refinement/i.test(reason)
85
+ ? `Move custom .refine()/.superRefine() validation into the handler`
86
+ : /coercion/i.test(reason)
87
+ ? `Remove z.coerce from the input schema, declare the JSON type the caller sends and convert inside the handler`
88
+ : /pipes/i.test(reason)
89
+ ? `Remove .pipe()/z.preprocess() from the input schema and validate or convert the value inside the handler`
90
+ : /overwrite/i.test(reason)
91
+ ? `Remove input normalization such as .trim(), .toLowerCase(), .toUpperCase() or .overwrite(), and normalize inside the handler`
92
+ : `Replace the unrepresentable Zod declaration with ordinary JSON-compatible types and convert or validate the value inside the handler`;
93
+ runtimeOnly = true;
94
+ result.warnings.push(`Function "${context.functionId}" at ${context.displayPath}, schema ${schemaPath}: ${reason}. Runtime-only contract. Fix: ${fix}, then run contracts generate.`);
95
+ }
96
+ }
97
+ if (runtimeOnly) {
98
+ delete result.input;
99
+ delete result.output;
100
+ }
101
+ if (schemas.events !== undefined) {
102
+ if (!schemas.events ||
103
+ typeof schemas.events !== 'object' ||
104
+ Array.isArray(schemas.events))
105
+ throw new Error('DURABLE_EVENTS_INVALID: events must be an object of Zod schemas');
106
+ result.events = Object.fromEntries(Object.entries(schemas.events).map(([name, schema]) => {
107
+ if (!/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(name))
108
+ throw new Error(`DURABLE_EVENT_NAME_INVALID: ${name}`);
109
+ const event = convertLoadedContract({ input: schema, output: schema, z: schemas.z }, context);
110
+ if (!event.input)
111
+ throw new Error(`DURABLE_EVENT_SCHEMA_UNSUPPORTED: ${name}: ${event.warnings.join('; ')}`);
112
+ return [name, event.input];
113
+ }));
114
+ }
115
+ return result;
116
+ }
@@ -0,0 +1,23 @@
1
+ import { parse } from '@babel/parser';
2
+ import type { ConvertedContract } from './contract-conversion.js';
3
+ export type { ConvertedContract } from './contract-conversion.js';
4
+ export declare const SERVER_SDK = "@lark-base-open/base-database-app-sdk/server";
5
+ export interface ContractEntry {
6
+ entry: string;
7
+ input: string;
8
+ output: string;
9
+ events?: string;
10
+ durable?: boolean;
11
+ schemaPackageVersion: string;
12
+ sdkVersion: string;
13
+ }
14
+ export interface AstNode {
15
+ type: string;
16
+ [key: string]: unknown;
17
+ }
18
+ export declare function node(value: unknown): value is AstNode;
19
+ export declare function walkAst(value: unknown, visit: (node: AstNode) => void): void;
20
+ export declare function parseModule(path: string): ReturnType<typeof parse>;
21
+ export declare function usesDefineFunction(entry: string): boolean;
22
+ export declare function extractContract(entry: string, durable?: boolean): ContractEntry;
23
+ export declare function convertContract(entry: ContractEntry): Promise<ConvertedContract>;
@@ -0,0 +1,245 @@
1
+ import { defineFunctionCall, isDefineFunctionSource, } from './app-builder/core.mjs';
2
+ import { existsSync, readFileSync, mkdtempSync, rmSync } from 'node:fs';
3
+ import { basename, dirname, join, relative, resolve } from 'node:path';
4
+ import { createRequire } from 'node:module';
5
+ import { execFileSync } from 'node:child_process';
6
+ import { parse } from '@babel/parser';
7
+ import { build } from 'esbuild';
8
+ import { tmpdir } from 'node:os';
9
+ import { fileURLToPath, pathToFileURL } from 'node:url';
10
+ import { validateFullSchema } from './app-builder/schema.js';
11
+ export const SERVER_SDK = '@lark-base-open/base-database-app-sdk/server';
12
+ export function node(value) {
13
+ return (!!value &&
14
+ typeof value === 'object' &&
15
+ typeof value.type === 'string');
16
+ }
17
+ export function walkAst(value, visit) {
18
+ if (!node(value))
19
+ return;
20
+ visit(value);
21
+ for (const [key, child] of Object.entries(value)) {
22
+ if (key.includes('omment') || key === 'loc' || key === 'tokens')
23
+ continue;
24
+ if (Array.isArray(child))
25
+ child.forEach((v) => walkAst(v, visit));
26
+ else if (node(child))
27
+ walkAst(child, visit);
28
+ }
29
+ }
30
+ export function parseModule(path) {
31
+ return parse(readFileSync(path, 'utf8'), {
32
+ sourceType: 'module',
33
+ plugins: ['typescript', 'jsx'],
34
+ });
35
+ }
36
+ function importedName(s) {
37
+ return s.imported?.name ?? s.imported?.value;
38
+ }
39
+ export function usesDefineFunction(entry) {
40
+ if (!existsSync(entry))
41
+ return false;
42
+ return isDefineFunctionSource(readFileSync(entry, 'utf8'));
43
+ }
44
+ function fail() {
45
+ throw new Error('Expected input and output schemas imported from ./contract');
46
+ }
47
+ function keyOf(value) {
48
+ return node(value) && value.type === 'Identifier'
49
+ ? String(value.name)
50
+ : node(value) && value.type === 'StringLiteral'
51
+ ? String(value.value)
52
+ : undefined;
53
+ }
54
+ export function extractContract(entry, durable = false) {
55
+ try {
56
+ return readContractEntry(entry, durable);
57
+ }
58
+ catch (error) {
59
+ throw new Error(`Cannot extract contract for function "${basename(dirname(entry))}" at ${entry}: ${error instanceof Error ? error.message : String(error)}. Fix: Import the input and output schemas from ./contract, correct the reported syntax or dependency error, then run contracts generate.`);
60
+ }
61
+ }
62
+ function readContractEntry(entry, durable) {
63
+ const ast = parseModule(entry);
64
+ const imports = new Map();
65
+ for (const s of ast.program.body) {
66
+ if (s.type !== 'ImportDeclaration' || s.importKind === 'type')
67
+ continue;
68
+ for (const b of s.specifiers) {
69
+ if (b.type === 'ImportSpecifier' && b.importKind !== 'type')
70
+ imports.set(b.local.name, {
71
+ from: s.source.value,
72
+ name: importedName(b),
73
+ });
74
+ }
75
+ }
76
+ const call = defineFunctionCall(ast, durable ? 'defineDurableFunction' : 'defineFunction');
77
+ if (!call ||
78
+ call.arguments.length !== 1 ||
79
+ call.arguments[0]?.type !== 'ObjectExpression')
80
+ fail();
81
+ const paths = {};
82
+ for (const p of call.arguments[0].properties) {
83
+ if (p.type === 'SpreadElement')
84
+ fail();
85
+ if (p.type === 'ObjectProperty' &&
86
+ !p.computed &&
87
+ (durable ? ['input', 'output', 'events'] : ['input', 'output']).includes(keyOf(p.key))) {
88
+ if (p.value.type !== 'Identifier')
89
+ fail();
90
+ const binding = imports.get(p.value.name);
91
+ if (!binding)
92
+ fail();
93
+ paths[keyOf(p.key)] = binding;
94
+ }
95
+ }
96
+ if (!paths.input ||
97
+ !paths.output ||
98
+ paths.input.from !== paths.output.from ||
99
+ !/^\.\/contract(?:\.ts|\.js)?$/.test(paths.input.from) ||
100
+ (durable && paths.events && paths.events.from !== paths.input.from))
101
+ fail();
102
+ const contract = join(dirname(entry), 'contract.ts');
103
+ if (!existsSync(contract))
104
+ fail();
105
+ const project = resolve(dirname(entry), '../..');
106
+ const req = createRequire(join(project, 'package.json'));
107
+ const pkgPath = req.resolve('zod/package.json');
108
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
109
+ const sdkEntry = req.resolve(SERVER_SDK);
110
+ let sdkRoot = dirname(sdkEntry);
111
+ while (!existsSync(join(sdkRoot, 'package.json'))) {
112
+ const parent = dirname(sdkRoot);
113
+ if (parent === sdkRoot)
114
+ fail();
115
+ sdkRoot = parent;
116
+ }
117
+ const sdk = JSON.parse(readFileSync(join(sdkRoot, 'package.json'), 'utf8'));
118
+ return {
119
+ entry: contract,
120
+ input: paths.input.name,
121
+ output: paths.output.name,
122
+ ...(durable
123
+ ? {
124
+ durable: true,
125
+ ...(paths.events ? { events: paths.events.name } : {}),
126
+ }
127
+ : {}),
128
+ schemaPackageVersion: pkg.version,
129
+ sdkVersion: sdk.version,
130
+ };
131
+ }
132
+ export async function convertContract(entry) {
133
+ const temp = mkdtempSync(join(tmpdir(), 'base-contract-'));
134
+ const functionId = basename(dirname(entry.entry));
135
+ try {
136
+ const bundle = join(temp, 'schema.mjs');
137
+ await build({
138
+ stdin: {
139
+ contents: `export { ${entry.input} as input, ${entry.output} as output${entry.events ? `, ${entry.events} as events` : ''} } from ${JSON.stringify(entry.entry)}; export { z } from 'zod';`,
140
+ resolveDir: dirname(entry.entry),
141
+ loader: 'ts',
142
+ },
143
+ bundle: true,
144
+ drop: ['console'],
145
+ platform: 'node',
146
+ format: 'esm',
147
+ outfile: bundle,
148
+ logLevel: 'silent',
149
+ banner: {
150
+ js: "import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);",
151
+ },
152
+ });
153
+ const resultPath = join(temp, 'result.json');
154
+ const worker = join(temp, 'worker.mjs');
155
+ const moduleDirectory = dirname(fileURLToPath(import.meta.url));
156
+ const converterModule = [
157
+ join(moduleDirectory, 'contract-conversion.js'),
158
+ join(moduleDirectory, 'contract-conversion.ts'),
159
+ ].find((path) => existsSync(path));
160
+ if (!converterModule) {
161
+ throw new Error('Contract conversion module is unavailable');
162
+ }
163
+ await build({
164
+ stdin: {
165
+ contents: `
166
+ import { writeFileSync } from 'node:fs';
167
+ import { convertLoadedContract } from ${JSON.stringify(converterModule)};
168
+ globalThis.fetch = () => { throw new Error('NETWORK_DISABLED'); };
169
+ globalThis.WebSocket = undefined;
170
+ const [schemaURL, resultPath, functionId, displayPath] = process.argv.slice(2);
171
+ let envelope;
172
+ try {
173
+ const schemas = await import(schemaURL);
174
+ envelope = { ok: true, result: convertLoadedContract(schemas, { functionId, displayPath }) };
175
+ } catch (error) {
176
+ envelope = { ok: false, message: String(error?.message ?? error).slice(0, 4096) };
177
+ }
178
+ writeFileSync(resultPath, JSON.stringify(envelope), { flag: 'wx' });
179
+ process.exit(0);
180
+ `,
181
+ resolveDir: moduleDirectory,
182
+ loader: 'js',
183
+ },
184
+ bundle: true,
185
+ platform: 'node',
186
+ format: 'esm',
187
+ outfile: worker,
188
+ logLevel: 'silent',
189
+ });
190
+ const displayPath = relative(resolve(dirname(entry.entry), '../../..'), entry.entry);
191
+ try {
192
+ execFileSync(process.execPath, [
193
+ '--max-old-space-size=128',
194
+ worker,
195
+ pathToFileURL(bundle).href,
196
+ resultPath,
197
+ functionId,
198
+ displayPath,
199
+ ], {
200
+ cwd: temp,
201
+ env: {},
202
+ timeout: 5000,
203
+ killSignal: 'SIGKILL',
204
+ stdio: ['ignore', 'ignore', 'ignore'],
205
+ });
206
+ }
207
+ catch {
208
+ throw new Error('Contract worker failed, timed out, or exited early');
209
+ }
210
+ if (!existsSync(resultPath)) {
211
+ throw new Error('Contract worker returned no result');
212
+ }
213
+ const envelope = JSON.parse(readFileSync(resultPath, 'utf8'));
214
+ if (!envelope.ok || !envelope.result) {
215
+ throw new Error(envelope.message ?? 'Contract worker failed');
216
+ }
217
+ const result = envelope.result;
218
+ for (const direction of ['input', 'output']) {
219
+ if (!result[direction])
220
+ continue;
221
+ try {
222
+ validateFullSchema(result[direction]);
223
+ }
224
+ catch (error) {
225
+ delete result[direction];
226
+ result.warnings.push(`CONTRACT_${direction.toUpperCase()}_SCHEMA_UNSUPPORTED:${error instanceof Error && /^CONTRACT_[A-Z_]+$/.test(error.message) ? error.message : 'CONTRACT_SCHEMA_UNSUPPORTED'}`);
227
+ }
228
+ }
229
+ if (entry.durable) {
230
+ if (!entry.events)
231
+ result.events = {};
232
+ if (!result.input || !result.output || !result.events)
233
+ throw new Error('DURABLE_CONTRACT_UNSUPPORTED: input, output and events must be representable as JSON Schema');
234
+ for (const schema of Object.values(result.events))
235
+ validateFullSchema(schema);
236
+ }
237
+ return result;
238
+ }
239
+ catch (error) {
240
+ throw new Error(`Cannot extract contract for function "${functionId}" at ${entry.entry}: ${error instanceof Error ? error.message : String(error)}. Fix: Correct the reported syntax, import or schema export in this file, install any missing dependency, then run contracts generate.`);
241
+ }
242
+ finally {
243
+ rmSync(temp, { recursive: true, force: true });
244
+ }
245
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "tokenEnv": "BASE_APP_DEV_PAIRING_TOKEN",
3
+ "endpoint": "/__base_app/dev-pair",
4
+ "proofPrefix": "base-app-dev-pair.v1",
5
+ "pairApi": "site.v1.development.pair",
6
+ "pairedEvent": "site.v1.development.paired",
7
+ "host": "127.0.0.1",
8
+ "portMin": 43100,
9
+ "portMax": 43109,
10
+ "secretBytes": 32
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "scripts": [
4
+ {
5
+ "sha256": "6e07b18ba1e30eca8bcaf3c99393e174d404d43e3f3ae31568d0075473d6bee2",
6
+ "code": "\n if (import.meta.hot?.on) {\n import.meta.hot.on('vite:error', (error) => {\n if (error.err) {\n console.error(\n [error.err.message, error.err.frame].filter(Boolean).join('\\n'),\n )\n }\n })\n }\n "
7
+ }
8
+ ]
9
+ }
@@ -0,0 +1,3 @@
1
+ export declare const DEPENDENCY_INPUTS: readonly ['package.json', 'package-lock.json', 'npm-shrinkwrap.json', 'pnpm-lock.yaml', 'yarn.lock', '.npmrc', '.yarnrc', '.yarnrc.yml'];
2
+ export declare function isDependencyInput(path: string): boolean;
3
+ export declare function blocksAutomaticPreview(path: string): boolean;
@@ -0,0 +1,18 @@
1
+ export const DEPENDENCY_INPUTS = [
2
+ 'package.json',
3
+ 'package-lock.json',
4
+ 'npm-shrinkwrap.json',
5
+ 'pnpm-lock.yaml',
6
+ 'yarn.lock',
7
+ '.npmrc',
8
+ '.yarnrc',
9
+ '.yarnrc.yml',
10
+ ];
11
+ export function isDependencyInput(path) {
12
+ return DEPENDENCY_INPUTS.includes(path.replaceAll('\\', '/').split('/').at(-1));
13
+ }
14
+ export function blocksAutomaticPreview(path) {
15
+ const normalized = path.replaceAll('\\', '/');
16
+ return (isDependencyInput(normalized) ||
17
+ !/^(server|server-functions|contract|contracts)\//.test(normalized));
18
+ }
@@ -0,0 +1 @@
1
+ export declare function runViteIPCWorker(sdkMissingMessage?: () => string): void;
@@ -0,0 +1,35 @@
1
+ import { startVite } from './dev-vite-server.js';
2
+ import { DEVELOPMENT_PAIRING } from './development-pairing.generated.js';
3
+ import { redactPairing } from './dev-redaction.js';
4
+ export function runViteIPCWorker(sdkMissingMessage) {
5
+ if (!process.send)
6
+ return;
7
+ let server;
8
+ let stopping = false;
9
+ const stop = async () => {
10
+ if (stopping)
11
+ return;
12
+ stopping = true;
13
+ await server?.close();
14
+ process.exit(0);
15
+ };
16
+ process.on('SIGTERM', stop);
17
+ process.on('SIGINT', stop);
18
+ process.on('disconnect', stop);
19
+ process.once('message', async (input) => {
20
+ try {
21
+ server = await startVite(input, undefined, sdkMissingMessage);
22
+ if (stopping)
23
+ await server.close();
24
+ }
25
+ catch (error) {
26
+ process.send?.({
27
+ event: 'error',
28
+ code: error.code,
29
+ message: redactPairing(error.message, process.env[DEVELOPMENT_PAIRING.tokenEnv]),
30
+ });
31
+ process.exitCode = 1;
32
+ process.disconnect();
33
+ }
34
+ });
35
+ }
@@ -0,0 +1 @@
1
+ export declare function redactPairing(value: string, token?: string): string;
@@ -0,0 +1,3 @@
1
+ export function redactPairing(value, token) {
2
+ return (token ? value.replaceAll(token, '[REDACTED]') : value).replace(/#t=[^\s"\\]*/g, '#t=[REDACTED]');
3
+ }
@@ -0,0 +1,3 @@
1
+ export declare function watchSnapshot(workspace: string): Map<string, string>;
2
+ export declare function changedFiles(a: Map<string, string>, b: Map<string, string>): string[];
3
+ export declare function snapshotFingerprint(snapshot: Map<string, string>): string;