@superpanel-sdk/runtime 0.0.1-internal.1 → 0.0.1-internal.2
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/dist/builder/compile/compile-sequence.d.ts +2 -0
- package/dist/builder/compile/compile-sequence.js +4 -3
- package/dist/builder/compile/function-code.d.ts +4 -0
- package/dist/builder/compile/function-code.js +70 -0
- package/dist/builder/compile/registry.d.ts +2 -0
- package/dist/builder/compile/registry.js +9 -3
- package/dist/compute-host/source-compute-host.js +2 -1
- package/dist/fn-context/index.d.ts +1 -0
- package/dist/fn-context/index.js +1 -0
- package/dist/fn-context/system-args.d.ts +6 -0
- package/dist/fn-context/system-args.js +14 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { FuncMap } from '../../core/functions/types.js';
|
|
2
2
|
import type { CompanySchema } from '../../core/slot/schema.js';
|
|
3
3
|
import type { SequenceBuild } from '../types.js';
|
|
4
|
+
/** SequenceBuild / SequenceConfigBuild cache key. Bump when compiled `code` shape changes. */
|
|
5
|
+
export declare function runtimePackageVersion(): string;
|
|
4
6
|
/** Deep-clone company schema with derived computeFn normalized to string names. */
|
|
5
7
|
export declare function snapshotCompanySchema(company: CompanySchema, functions?: FuncMap): CompanySchema;
|
|
6
8
|
export declare function sequenceBuildPath(repoRoot: string, sequenceId: string): string;
|
|
@@ -22,7 +22,8 @@ const FATAL_CODES = new Set([
|
|
|
22
22
|
'id-cannot-ref',
|
|
23
23
|
'reserved-table-name',
|
|
24
24
|
]);
|
|
25
|
-
|
|
25
|
+
/** SequenceBuild / SequenceConfigBuild cache key. Bump when compiled `code` shape changes. */
|
|
26
|
+
export function runtimePackageVersion() {
|
|
26
27
|
const pkgPath = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..', 'package.json');
|
|
27
28
|
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
28
29
|
return pkg.version ?? '0.0.0';
|
|
@@ -85,8 +86,8 @@ export async function compileSequence(repoRoot, sequenceId, options = {}) {
|
|
|
85
86
|
}
|
|
86
87
|
const includeCode = options.includeCode ?? true;
|
|
87
88
|
const [functionsRegistry, caseContextViewEntry] = await Promise.all([
|
|
88
|
-
toFunctionRegistry(functions, { includeCode }),
|
|
89
|
-
toCaseContextViewRegistry(caseContextView, { includeCode }),
|
|
89
|
+
toFunctionRegistry(functions, { includeCode, modulePath: functionsPath }),
|
|
90
|
+
toCaseContextViewRegistry(caseContextView, { includeCode, modulePath: viewPath }),
|
|
90
91
|
]);
|
|
91
92
|
const build = {
|
|
92
93
|
sequenceId,
|
|
@@ -3,4 +3,8 @@
|
|
|
3
3
|
* suitable for QuickJS `eval` / registry `code` fields (minified).
|
|
4
4
|
*/
|
|
5
5
|
export declare function compileFunctionCode(fn: (...args: never[]) => unknown): Promise<string>;
|
|
6
|
+
/** Bundle one registered function with module-local helpers and constants. */
|
|
7
|
+
export declare function compileFunctionModuleCode(modulePath: string, functionName: string): Promise<string>;
|
|
8
|
+
/** Bundle caseContextView with module-local helpers and constants. */
|
|
9
|
+
export declare function compileCaseContextViewModuleCode(modulePath: string): Promise<string>;
|
|
6
10
|
//# sourceMappingURL=function-code.d.ts.map
|
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
import * as esbuild from 'esbuild';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
const RUNTIME_SHIM_NAMESPACE = 'superpanel-runtime-shim';
|
|
4
|
+
const RUNTIME_SHIM = `
|
|
5
|
+
export function defineComputeFunc(main, options) {
|
|
6
|
+
return { kind: 'compute', main, ...options };
|
|
7
|
+
}
|
|
8
|
+
export function defineBoolComputeFunc(main, options) {
|
|
9
|
+
return { kind: 'boolCompute', main, ...options };
|
|
10
|
+
}
|
|
11
|
+
export function defineCustomFunc(main, options) {
|
|
12
|
+
return { kind: 'custom', main, ...options };
|
|
13
|
+
}
|
|
14
|
+
export function defineSystemFunc(main, options) {
|
|
15
|
+
return { kind: 'system', main, ...options };
|
|
16
|
+
}
|
|
17
|
+
export function defineCaseContext(main) {
|
|
18
|
+
return Object.assign(main, { kind: 'caseContextView', main });
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
function runtimeShimPlugin() {
|
|
22
|
+
return {
|
|
23
|
+
name: 'superpanel-runtime-shim',
|
|
24
|
+
setup(build) {
|
|
25
|
+
build.onResolve({ filter: /^@superpanel-sdk\/runtime$/ }, () => ({
|
|
26
|
+
path: 'runtime',
|
|
27
|
+
namespace: RUNTIME_SHIM_NAMESPACE,
|
|
28
|
+
}));
|
|
29
|
+
build.onLoad({ filter: /.*/, namespace: RUNTIME_SHIM_NAMESPACE }, () => ({
|
|
30
|
+
contents: RUNTIME_SHIM,
|
|
31
|
+
loader: 'js',
|
|
32
|
+
}));
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
2
36
|
/**
|
|
3
37
|
* Compile a single function implementation to a standalone JS expression string
|
|
4
38
|
* suitable for QuickJS `eval` / registry `code` fields (minified).
|
|
@@ -27,4 +61,40 @@ export async function compileFunctionCode(fn) {
|
|
|
27
61
|
}
|
|
28
62
|
return text.slice(m[0].length).replace(/;?\s*$/, '');
|
|
29
63
|
}
|
|
64
|
+
async function compileModuleSelection(modulePath, selection) {
|
|
65
|
+
const result = await esbuild.build({
|
|
66
|
+
stdin: {
|
|
67
|
+
contents: `import * as mod from ${JSON.stringify(modulePath)};
|
|
68
|
+
const selected = ${selection};
|
|
69
|
+
export default selected;`,
|
|
70
|
+
resolveDir: path.dirname(modulePath),
|
|
71
|
+
sourcefile: 'superpanel-function-entry.ts',
|
|
72
|
+
loader: 'ts',
|
|
73
|
+
},
|
|
74
|
+
bundle: true,
|
|
75
|
+
write: false,
|
|
76
|
+
platform: 'neutral',
|
|
77
|
+
format: 'iife',
|
|
78
|
+
globalName: '__superpanel_function',
|
|
79
|
+
target: 'es2022',
|
|
80
|
+
minify: true,
|
|
81
|
+
logLevel: 'silent',
|
|
82
|
+
plugins: [runtimeShimPlugin()],
|
|
83
|
+
});
|
|
84
|
+
const output = result.outputFiles[0]?.text.trim();
|
|
85
|
+
if (!output) {
|
|
86
|
+
throw new Error(`Failed to compile function module ${modulePath}`);
|
|
87
|
+
}
|
|
88
|
+
return `(()=>{${output};return __superpanel_function.default})()`;
|
|
89
|
+
}
|
|
90
|
+
/** Bundle one registered function with module-local helpers and constants. */
|
|
91
|
+
export function compileFunctionModuleCode(modulePath, functionName) {
|
|
92
|
+
const registry = `(mod.functions ?? mod.default?.functions ?? mod.default)`;
|
|
93
|
+
return compileModuleSelection(modulePath, `${registry}[${JSON.stringify(functionName)}].main`);
|
|
94
|
+
}
|
|
95
|
+
/** Bundle caseContextView with module-local helpers and constants. */
|
|
96
|
+
export function compileCaseContextViewModuleCode(modulePath) {
|
|
97
|
+
const view = `(mod.caseContextView ?? mod.default?.caseContextView ?? mod.default)`;
|
|
98
|
+
return compileModuleSelection(modulePath, `(${view}.main ?? ${view})`);
|
|
99
|
+
}
|
|
30
100
|
//# sourceMappingURL=function-code.js.map
|
|
@@ -2,6 +2,8 @@ import type { CaseContextViewRegistryEntry, FuncMap, FunctionRegistry } from '..
|
|
|
2
2
|
export type BuildRegistryOptions = {
|
|
3
3
|
/** When false, skip esbuild and omit `code` (local serve overlay). Default true. */
|
|
4
4
|
includeCode?: boolean;
|
|
5
|
+
/** Source module used to bundle module-local helpers and constants. */
|
|
6
|
+
modulePath?: string;
|
|
5
7
|
};
|
|
6
8
|
/**
|
|
7
9
|
* Project author FuncMap → JSON-safe registry.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolveCaseContextViewFn } from '../../core/functions/define/case-context.js';
|
|
2
|
-
import { compileFunctionCode } from './function-code.js';
|
|
2
|
+
import { compileCaseContextViewModuleCode, compileFunctionCode, compileFunctionModuleCode, } from './function-code.js';
|
|
3
3
|
function withCode(entry, code) {
|
|
4
4
|
if (code === undefined)
|
|
5
5
|
return entry;
|
|
@@ -13,7 +13,11 @@ export async function toFunctionRegistry(functions, options = {}) {
|
|
|
13
13
|
const includeCode = options.includeCode ?? true;
|
|
14
14
|
const out = {};
|
|
15
15
|
for (const [name, def] of Object.entries(functions)) {
|
|
16
|
-
const code = includeCode
|
|
16
|
+
const code = includeCode
|
|
17
|
+
? options.modulePath
|
|
18
|
+
? await compileFunctionModuleCode(options.modulePath, name)
|
|
19
|
+
: await compileFunctionCode(def.main)
|
|
20
|
+
: undefined;
|
|
17
21
|
let entry;
|
|
18
22
|
if (def.kind === 'custom') {
|
|
19
23
|
entry = withCode({ kind: 'custom', writes: [] }, code);
|
|
@@ -36,7 +40,9 @@ export async function toCaseContextViewRegistry(view, options = {}) {
|
|
|
36
40
|
if (!(options.includeCode ?? true)) {
|
|
37
41
|
return { kind: 'caseContextView' };
|
|
38
42
|
}
|
|
39
|
-
const code =
|
|
43
|
+
const code = options.modulePath
|
|
44
|
+
? await compileCaseContextViewModuleCode(options.modulePath)
|
|
45
|
+
: await compileFunctionCode(fn);
|
|
40
46
|
return { kind: 'caseContextView', code };
|
|
41
47
|
}
|
|
42
48
|
//# sourceMappingURL=registry.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { resolveCaseContextViewFn } from '../core/functions/define/case-context.js';
|
|
2
2
|
import { buildActionContext } from '../fn-context/build-context.js';
|
|
3
|
+
import { resolveSystemFnParams } from '../fn-context/system-args.js';
|
|
3
4
|
import { createFakeApiHost } from '../fn-context/fake/index.js';
|
|
4
5
|
import { createRpcApiHost } from '../fn-context/rpc/index.js';
|
|
5
6
|
import { makeCtx } from '../fn-context/make-ctx.js';
|
|
@@ -50,7 +51,7 @@ export function createSourceComputeHost(options) {
|
|
|
50
51
|
const fn = def.main;
|
|
51
52
|
return fn(caseContext, ctx);
|
|
52
53
|
}
|
|
53
|
-
const params = (args
|
|
54
|
+
const params = resolveSystemFnParams(args);
|
|
54
55
|
const ctx = await systemContext();
|
|
55
56
|
return def.main({ ...ctx, params });
|
|
56
57
|
},
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { ActionContext, ActionDataSlice, ApiHost, RunScope } from './types.js';
|
|
2
2
|
export { buildActionContext, type BuildActionContextOptions } from './build-context.js';
|
|
3
|
+
export { resolveSystemFnParams } from './system-args.js';
|
|
3
4
|
export { createFakeApiHost, type FakeApiHostOptions } from './fake/index.js';
|
|
4
5
|
export { defaultPlatformApis, emptyIntegration, type PlatformApiOverrides } from './fake/empty-api.js';
|
|
5
6
|
export { createRpcApiHost, REQUEST_ID_HEADER, readRequestIdHeader } from './rpc/index.js';
|
package/dist/fn-context/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { buildActionContext } from './build-context.js';
|
|
2
|
+
export { resolveSystemFnParams } from './system-args.js';
|
|
2
3
|
export { createFakeApiHost } from './fake/index.js';
|
|
3
4
|
export { defaultPlatformApis, emptyIntegration } from './fake/empty-api.js';
|
|
4
5
|
export { createRpcApiHost, REQUEST_ID_HEADER, readRequestIdHeader } from './rpc/index.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `kind: 'system'` — `args[0]` is the params object (empty when omitted).
|
|
3
|
+
* Snapshot projection belongs to compute / custom / caseContextView, not here.
|
|
4
|
+
*/
|
|
5
|
+
export declare function resolveSystemFnParams(args: unknown[]): object;
|
|
6
|
+
//# sourceMappingURL=system-args.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `kind: 'system'` — `args[0]` is the params object (empty when omitted).
|
|
3
|
+
* Snapshot projection belongs to compute / custom / caseContextView, not here.
|
|
4
|
+
*/
|
|
5
|
+
export function resolveSystemFnParams(args) {
|
|
6
|
+
const raw = args[0];
|
|
7
|
+
if (raw == null)
|
|
8
|
+
return {};
|
|
9
|
+
if (typeof raw !== 'object' || Array.isArray(raw)) {
|
|
10
|
+
throw new Error('system function args[0] must be a params object');
|
|
11
|
+
}
|
|
12
|
+
return raw;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=system-args.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export type { CaseContextViewRegistryEntry, ComputeFn, CustomFn, DefinedFunc, Fu
|
|
|
24
24
|
export { toFuncRegistrations } from './core/functions/types.js';
|
|
25
25
|
export { toCaseContextViewRegistry, toFunctionRegistry } from './builder/compile/registry.js';
|
|
26
26
|
export { compileFunctionCode } from './builder/compile/function-code.js';
|
|
27
|
-
export { compileAll, compileSequence, snapshotCompanySchema, type CompileSequenceOptions, type CompileSequenceResult, } from './builder/compile/compile-sequence.js';
|
|
27
|
+
export { compileAll, compileSequence, runtimePackageVersion, snapshotCompanySchema, type CompileSequenceOptions, type CompileSequenceResult, } from './builder/compile/compile-sequence.js';
|
|
28
28
|
export { compileSequenceAgendas, fatalAgendaIssues } from './builder/compile/compile-agenda.js';
|
|
29
29
|
export { loadSequenceCaseContextView, loadSequenceFunctions } from './builder/load.js';
|
|
30
30
|
export { findTsModule } from './builder/paths.js';
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ export { resolveFuncName } from './core/functions/func-ref.js';
|
|
|
14
14
|
export { toFuncRegistrations } from './core/functions/types.js';
|
|
15
15
|
export { toCaseContextViewRegistry, toFunctionRegistry } from './builder/compile/registry.js';
|
|
16
16
|
export { compileFunctionCode } from './builder/compile/function-code.js';
|
|
17
|
-
export { compileAll, compileSequence, snapshotCompanySchema, } from './builder/compile/compile-sequence.js';
|
|
17
|
+
export { compileAll, compileSequence, runtimePackageVersion, snapshotCompanySchema, } from './builder/compile/compile-sequence.js';
|
|
18
18
|
export { compileSequenceAgendas, fatalAgendaIssues } from './builder/compile/compile-agenda.js';
|
|
19
19
|
export { loadSequenceCaseContextView, loadSequenceFunctions } from './builder/load.js';
|
|
20
20
|
export { findTsModule } from './builder/paths.js';
|
package/package.json
CHANGED