@ankhorage/runtime 0.1.1 → 0.2.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.
- package/CHANGELOG.md +10 -0
- package/README.md +20 -5
- package/dist/ManifestContext.d.ts +16 -0
- package/dist/ManifestContext.d.ts.map +1 -0
- package/dist/ManifestContext.js +26 -0
- package/dist/ManifestContext.js.map +1 -0
- package/dist/RuntimeRenderer.d.ts +24 -0
- package/dist/RuntimeRenderer.d.ts.map +1 -0
- package/dist/RuntimeRenderer.js +302 -0
- package/dist/RuntimeRenderer.js.map +1 -0
- package/dist/RuntimeRendererConfig.d.ts +54 -0
- package/dist/RuntimeRendererConfig.d.ts.map +1 -0
- package/dist/RuntimeRendererConfig.js +70 -0
- package/dist/RuntimeRendererConfig.js.map +1 -0
- package/dist/RuntimeScreen.d.ts +11 -0
- package/dist/RuntimeScreen.d.ts.map +1 -0
- package/dist/RuntimeScreen.js +59 -0
- package/dist/RuntimeScreen.js.map +1 -0
- package/dist/appExtensionRegistry.d.ts +3 -0
- package/dist/appExtensionRegistry.d.ts.map +1 -0
- package/dist/appExtensionRegistry.js +2 -0
- package/dist/appExtensionRegistry.js.map +1 -0
- package/dist/componentRegistry.d.ts +4 -0
- package/dist/componentRegistry.d.ts.map +1 -0
- package/dist/componentRegistry.js +6 -0
- package/dist/componentRegistry.js.map +1 -0
- package/dist/index.d.ts +27 -52
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -30
- package/dist/index.js.map +1 -1
- package/dist/readme-usage.js +4 -4
- package/dist/readme-usage.js.map +1 -1
- package/dist/registry.d.ts +7 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +49 -0
- package/dist/registry.js.map +1 -0
- package/dist/rendering.d.ts +17 -0
- package/dist/rendering.d.ts.map +1 -0
- package/dist/rendering.js +24 -0
- package/dist/rendering.js.map +1 -0
- package/dist/runtimeActionRegistry.d.ts +55 -0
- package/dist/runtimeActionRegistry.d.ts.map +1 -0
- package/dist/runtimeActionRegistry.js +323 -0
- package/dist/runtimeActionRegistry.js.map +1 -0
- package/dist/runtimeApiLoaders.d.ts +35 -0
- package/dist/runtimeApiLoaders.d.ts.map +1 -0
- package/dist/runtimeApiLoaders.js +218 -0
- package/dist/runtimeApiLoaders.js.map +1 -0
- package/dist/runtimeBindings.d.ts +52 -0
- package/dist/runtimeBindings.d.ts.map +1 -0
- package/dist/runtimeBindings.js +299 -0
- package/dist/runtimeBindings.js.map +1 -0
- package/dist/runtimeDataSourceOperations.d.ts +8 -0
- package/dist/runtimeDataSourceOperations.d.ts.map +1 -0
- package/dist/runtimeDataSourceOperations.js +58 -0
- package/dist/runtimeDataSourceOperations.js.map +1 -0
- package/dist/runtimeDbPersist.d.ts +34 -0
- package/dist/runtimeDbPersist.d.ts.map +1 -0
- package/dist/runtimeDbPersist.js +73 -0
- package/dist/runtimeDbPersist.js.map +1 -0
- package/dist/runtimeEventExecution.d.ts +11 -0
- package/dist/runtimeEventExecution.d.ts.map +1 -0
- package/dist/runtimeEventExecution.js +17 -0
- package/dist/runtimeEventExecution.js.map +1 -0
- package/dist/runtimeManifest.d.ts +53 -0
- package/dist/runtimeManifest.d.ts.map +1 -0
- package/dist/runtimeManifest.js +31 -0
- package/dist/runtimeManifest.js.map +1 -0
- package/dist/runtimeNodeProps.d.ts +22 -0
- package/dist/runtimeNodeProps.d.ts.map +1 -0
- package/dist/runtimeNodeProps.js +130 -0
- package/dist/runtimeNodeProps.js.map +1 -0
- package/dist/runtimeRepeat.d.ts +27 -0
- package/dist/runtimeRepeat.d.ts.map +1 -0
- package/dist/runtimeRepeat.js +129 -0
- package/dist/runtimeRepeat.js.map +1 -0
- package/dist/runtimeRepeatDiagnostics.d.ts +3 -0
- package/dist/runtimeRepeatDiagnostics.d.ts.map +1 -0
- package/dist/runtimeRepeatDiagnostics.js +14 -0
- package/dist/runtimeRepeatDiagnostics.js.map +1 -0
- package/dist/runtimeRepeatEmptyState.d.ts +7 -0
- package/dist/runtimeRepeatEmptyState.d.ts.map +1 -0
- package/dist/runtimeRepeatEmptyState.js +10 -0
- package/dist/runtimeRepeatEmptyState.js.map +1 -0
- package/dist/runtimeScreenLoaders.d.ts +71 -0
- package/dist/runtimeScreenLoaders.d.ts.map +1 -0
- package/dist/runtimeScreenLoaders.js +309 -0
- package/dist/runtimeScreenLoaders.js.map +1 -0
- package/dist/runtimeStateAdapter.d.ts +6 -0
- package/dist/runtimeStateAdapter.d.ts.map +1 -0
- package/dist/runtimeStateAdapter.js +162 -0
- package/dist/runtimeStateAdapter.js.map +1 -0
- package/package.json +19 -2
- package/paradox/badges/npm.svg +3 -3
- package/paradox/components.md +72 -0
- package/paradox/diagrams/architecture-overview.mmd +135 -1
- package/paradox/diagrams/export-graph.mmd +303 -18
- package/paradox/diagrams/module-relationships.mmd +98 -1
- package/paradox/diagrams/sequences/create-component-event-from-handler-args.mmd +24 -0
- package/paradox/diagrams/sequences/execute-db-persist-action.mmd +16 -0
- package/paradox/diagrams/sequences/merge-runtime-renderer-config.mmd +11 -0
- package/paradox/diagrams/sequences/resolve-db-persist-input.mmd +13 -0
- package/paradox/diagrams/sequences/resolve-runtime-action-payload.mmd +8 -0
- package/paradox/diagrams/sequences/resolve-runtime-action-value.mmd +5 -0
- package/paradox/diagrams/sequences/runtime-renderer-config-provider.mmd +17 -0
- package/paradox/diagrams/sequences/runtime-screen.mmd +17 -0
- package/paradox/diagrams/sequences/use-manifest-context.mmd +5 -0
- package/paradox/diagrams/sequences/use-manifest.mmd +5 -0
- package/paradox/diagrams/sequences/use-optional-manifest-context.mmd +5 -0
- package/paradox/diagrams/sequences/use-runtime-renderer-config.mmd +5 -0
- package/paradox/diagrams/sequences/use-runtime-screen-operation-loaders.mmd +5 -0
- package/paradox/diagrams/sequences/validate-runtime-binding-operation-ref.mmd +8 -0
- package/paradox/diagrams/sequences/wrap-runtime-event-props.mmd +5 -0
- package/paradox/exports.json +3385 -330
- package/paradox/exports.md +1051 -38
- package/paradox/index.html +8244 -413
- package/paradox/paradox.json +10013 -511
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export function createDbPersistActionHandler(args) {
|
|
2
|
+
const { dbAdapter, onResult } = args;
|
|
3
|
+
return async (handlerArgs) => {
|
|
4
|
+
const result = await executeDbPersistAction({ dbAdapter, handlerArgs });
|
|
5
|
+
onResult?.(result);
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export async function executeDbPersistAction(args) {
|
|
9
|
+
const inputResult = resolveDbPersistInput(args.handlerArgs.resolvedPayload);
|
|
10
|
+
if (!inputResult.ok) {
|
|
11
|
+
return inputResult;
|
|
12
|
+
}
|
|
13
|
+
const result = await args.dbAdapter.insert(inputResult.data);
|
|
14
|
+
return {
|
|
15
|
+
ok: true,
|
|
16
|
+
data: {
|
|
17
|
+
input: inputResult.data,
|
|
18
|
+
result,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function resolveDbPersistInput(payload) {
|
|
23
|
+
if (!isRecord(payload)) {
|
|
24
|
+
return createError('invalid_payload', 'db.persist requires a resolved payload object.');
|
|
25
|
+
}
|
|
26
|
+
const { collection } = payload;
|
|
27
|
+
if (typeof collection !== 'string' || collection.trim().length === 0) {
|
|
28
|
+
return createError('missing_collection', 'db.persist requires a non-empty collection.');
|
|
29
|
+
}
|
|
30
|
+
const { values } = payload;
|
|
31
|
+
if (!Array.isArray(values) || values.length === 0) {
|
|
32
|
+
return createError('missing_values', 'db.persist requires at least one value mapping.');
|
|
33
|
+
}
|
|
34
|
+
const record = {};
|
|
35
|
+
for (const value of values) {
|
|
36
|
+
if (!isFieldValueEntry(value)) {
|
|
37
|
+
return createError('invalid_value_mapping', 'db.persist value mappings must resolve to { field, value } entries.');
|
|
38
|
+
}
|
|
39
|
+
if (value.field.trim().length === 0) {
|
|
40
|
+
return createError('invalid_field', 'db.persist value field must be non-empty.');
|
|
41
|
+
}
|
|
42
|
+
record[value.field] = value.value;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
ok: true,
|
|
46
|
+
data: {
|
|
47
|
+
table: collection.trim(),
|
|
48
|
+
values: record,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function createError(code, message) {
|
|
53
|
+
return {
|
|
54
|
+
ok: false,
|
|
55
|
+
error: { code, message },
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function createDbPersistAdapterError(error) {
|
|
59
|
+
return {
|
|
60
|
+
code: error.code,
|
|
61
|
+
message: error.message,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function isFieldValueEntry(value) {
|
|
65
|
+
if (!isRecord(value)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return typeof value.field === 'string' && 'value' in value;
|
|
69
|
+
}
|
|
70
|
+
function isRecord(value) {
|
|
71
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=runtimeDbPersist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeDbPersist.js","sourceRoot":"","sources":["../src/runtimeDbPersist.ts"],"names":[],"mappings":"AAmCA,MAAM,UAAU,4BAA4B,CAAC,IAG5C;IACC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IAErC,OAAO,KAAK,EAAE,WAAW,EAAE,EAAE;QAC3B,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;QACxE,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,IAG5C;IACC,MAAM,WAAW,GAAG,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;IAC5E,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,CAAC;QACpB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C;QAED,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;IACpC,CAAC;IAED,OAAO;QACL,EAAE,EAAE,IAAI;QACR,IAAI,EAAE;YACJ,KAAK,EAAE,UAAU,CAAC,IAAI,EAAE;YACxB,MAAM,EAAE,MAAM;SACf;KACF,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAClB,IAAmC,EACnC,OAAyC;IAEzC,OAAO;QACL,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;KACzB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,KAA4B;IACtE,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACvC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,CAAC;AAC7D,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["import type {\n DbAdapter,\n DbAdapterError,\n DbInsertInput,\n DbRecord,\n DbResult,\n} from '@ankhorage/contracts';\n\nimport type { RuntimeActionHandler, RuntimeActionHandlerArgs } from './RuntimeRendererConfig';\n\nexport interface RuntimeDbPersistResult {\n readonly input: DbInsertInput;\n readonly result: DbResult<DbRecord[]>;\n}\n\nexport interface RuntimeDbPersistError {\n readonly code: string;\n readonly message: string;\n}\n\nexport type RuntimeDbPersistExecutionResult =\n | {\n readonly ok: true;\n readonly data: RuntimeDbPersistResult;\n }\n | {\n readonly ok: false;\n readonly error: RuntimeDbPersistError;\n };\n\ninterface FieldValueEntry {\n readonly field: string;\n readonly value: unknown;\n}\n\nexport function createDbPersistActionHandler(args: {\n readonly dbAdapter: DbAdapter;\n readonly onResult?: (result: RuntimeDbPersistExecutionResult) => void;\n}): RuntimeActionHandler {\n const { dbAdapter, onResult } = args;\n\n return async (handlerArgs) => {\n const result = await executeDbPersistAction({ dbAdapter, handlerArgs });\n onResult?.(result);\n };\n}\n\nexport async function executeDbPersistAction(args: {\n readonly dbAdapter: DbAdapter;\n readonly handlerArgs: RuntimeActionHandlerArgs;\n}): Promise<RuntimeDbPersistExecutionResult> {\n const inputResult = resolveDbPersistInput(args.handlerArgs.resolvedPayload);\n if (!inputResult.ok) {\n return inputResult;\n }\n\n const result = await args.dbAdapter.insert(inputResult.data);\n\n return {\n ok: true,\n data: {\n input: inputResult.data,\n result,\n },\n };\n}\n\nexport function resolveDbPersistInput(payload: object | undefined):\n | {\n readonly ok: true;\n readonly data: DbInsertInput;\n }\n | {\n readonly ok: false;\n readonly error: RuntimeDbPersistError;\n } {\n if (!isRecord(payload)) {\n return createError('invalid_payload', 'db.persist requires a resolved payload object.');\n }\n\n const { collection } = payload;\n if (typeof collection !== 'string' || collection.trim().length === 0) {\n return createError('missing_collection', 'db.persist requires a non-empty collection.');\n }\n\n const { values } = payload;\n if (!Array.isArray(values) || values.length === 0) {\n return createError('missing_values', 'db.persist requires at least one value mapping.');\n }\n\n const record: DbRecord = {};\n for (const value of values) {\n if (!isFieldValueEntry(value)) {\n return createError(\n 'invalid_value_mapping',\n 'db.persist value mappings must resolve to { field, value } entries.',\n );\n }\n\n if (value.field.trim().length === 0) {\n return createError('invalid_field', 'db.persist value field must be non-empty.');\n }\n\n record[value.field] = value.value;\n }\n\n return {\n ok: true,\n data: {\n table: collection.trim(),\n values: record,\n },\n };\n}\n\nfunction createError(\n code: RuntimeDbPersistError['code'],\n message: RuntimeDbPersistError['message'],\n): { readonly ok: false; readonly error: RuntimeDbPersistError } {\n return {\n ok: false,\n error: { code, message },\n };\n}\n\nexport function createDbPersistAdapterError(error: RuntimeDbPersistError): DbAdapterError {\n return {\n code: error.code,\n message: error.message,\n };\n}\n\nfunction isFieldValueEntry(value: unknown): value is FieldValueEntry {\n if (!isRecord(value)) {\n return false;\n }\n\n return typeof value.field === 'string' && 'value' in value;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DataSourceDiagnostic } from '@ankhorage/contracts';
|
|
2
|
+
import { type RuntimeComponentEventDispatchArgs } from './runtimeActionRegistry';
|
|
3
|
+
import type { RuntimeActionHandlers } from './RuntimeRendererConfig';
|
|
4
|
+
export interface RuntimeEventDiagnosticsReporter {
|
|
5
|
+
readonly onDiagnostics?: (diagnostics: readonly DataSourceDiagnostic[]) => void;
|
|
6
|
+
readonly consoleImpl?: Pick<Console, 'error' | 'warn'>;
|
|
7
|
+
}
|
|
8
|
+
export declare function dispatchRuntimeComponentEventWithReporting(args: RuntimeComponentEventDispatchArgs & RuntimeEventDiagnosticsReporter & {
|
|
9
|
+
readonly actionHandlers?: RuntimeActionHandlers;
|
|
10
|
+
}): Promise<readonly DataSourceDiagnostic[]>;
|
|
11
|
+
//# sourceMappingURL=runtimeEventExecution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeEventExecution.d.ts","sourceRoot":"","sources":["../src/runtimeEventExecution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAEL,KAAK,iCAAiC,EACvC,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAErE,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,WAAW,EAAE,SAAS,oBAAoB,EAAE,KAAK,IAAI,CAAC;IAChF,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC;CACxD;AAED,wBAAsB,0CAA0C,CAC9D,IAAI,EAAE,iCAAiC,GACrC,+BAA+B,GAAG;IAChC,QAAQ,CAAC,cAAc,CAAC,EAAE,qBAAqB,CAAC;CACjD,GACF,OAAO,CAAC,SAAS,oBAAoB,EAAE,CAAC,CAmB1C"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { dispatchRuntimeComponentEvent, } from './runtimeActionRegistry';
|
|
2
|
+
export async function dispatchRuntimeComponentEventWithReporting(args) {
|
|
3
|
+
const diagnostics = await dispatchRuntimeComponentEvent(args);
|
|
4
|
+
if (args.onDiagnostics !== undefined) {
|
|
5
|
+
args.onDiagnostics(diagnostics);
|
|
6
|
+
return diagnostics;
|
|
7
|
+
}
|
|
8
|
+
if (diagnostics.length === 0) {
|
|
9
|
+
return diagnostics;
|
|
10
|
+
}
|
|
11
|
+
const report = diagnostics.some((diagnostic) => diagnostic.severity === 'error')
|
|
12
|
+
? args.consoleImpl?.error
|
|
13
|
+
: args.consoleImpl?.warn;
|
|
14
|
+
report?.('[runtime] Event binding diagnostics', diagnostics);
|
|
15
|
+
return diagnostics;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=runtimeEventExecution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeEventExecution.js","sourceRoot":"","sources":["../src/runtimeEventExecution.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,6BAA6B,GAE9B,MAAM,yBAAyB,CAAC;AAQjC,MAAM,CAAC,KAAK,UAAU,0CAA0C,CAC9D,IAGG;IAEH,MAAM,WAAW,GAAG,MAAM,6BAA6B,CAAC,IAAI,CAAC,CAAC;IAE9D,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;QACrC,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAChC,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,KAAK,OAAO,CAAC;QAC9E,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK;QACzB,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC;IAE3B,MAAM,EAAE,CAAC,qCAAqC,EAAE,WAAW,CAAC,CAAC;IAE7D,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import type { DataSourceDiagnostic } from '@ankhorage/contracts';\n\nimport {\n dispatchRuntimeComponentEvent,\n type RuntimeComponentEventDispatchArgs,\n} from './runtimeActionRegistry';\nimport type { RuntimeActionHandlers } from './RuntimeRendererConfig';\n\nexport interface RuntimeEventDiagnosticsReporter {\n readonly onDiagnostics?: (diagnostics: readonly DataSourceDiagnostic[]) => void;\n readonly consoleImpl?: Pick<Console, 'error' | 'warn'>;\n}\n\nexport async function dispatchRuntimeComponentEventWithReporting(\n args: RuntimeComponentEventDispatchArgs &\n RuntimeEventDiagnosticsReporter & {\n readonly actionHandlers?: RuntimeActionHandlers;\n },\n): Promise<readonly DataSourceDiagnostic[]> {\n const diagnostics = await dispatchRuntimeComponentEvent(args);\n\n if (args.onDiagnostics !== undefined) {\n args.onDiagnostics(diagnostics);\n return diagnostics;\n }\n\n if (diagnostics.length === 0) {\n return diagnostics;\n }\n\n const report = diagnostics.some((diagnostic) => diagnostic.severity === 'error')\n ? args.consoleImpl?.error\n : args.consoleImpl?.warn;\n\n report?.('[runtime] Event binding diagnostics', diagnostics);\n\n return diagnostics;\n}\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare const RUNTIME_CAPABILITIES: readonly ["runtime.render", "runtime.actions", "runtime.bindings", "runtime.adapters"];
|
|
2
|
+
export declare const RUNTIME_MANIFEST_KIND = "ankhorage-runtime-manifest";
|
|
3
|
+
export type RuntimeCapability = (typeof RUNTIME_CAPABILITIES)[number];
|
|
4
|
+
export interface RuntimeDiagnostic {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
readonly message: string;
|
|
7
|
+
readonly severity: 'error' | 'info' | 'warning';
|
|
8
|
+
}
|
|
9
|
+
export interface RuntimeManifestConfig {
|
|
10
|
+
readonly appId: string;
|
|
11
|
+
readonly environment?: string;
|
|
12
|
+
readonly values?: Readonly<Record<string, unknown>>;
|
|
13
|
+
}
|
|
14
|
+
export interface RuntimeActionDescriptor<Data = unknown> {
|
|
15
|
+
readonly capability?: RuntimeCapability;
|
|
16
|
+
readonly description?: string;
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly data?: Data;
|
|
19
|
+
}
|
|
20
|
+
export interface RuntimeBindingDescriptor<Value = unknown> {
|
|
21
|
+
readonly actionId?: string;
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly source: string;
|
|
24
|
+
readonly target: string;
|
|
25
|
+
readonly value?: Value;
|
|
26
|
+
}
|
|
27
|
+
export interface RuntimeAdapterDescriptor<Options = unknown> {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly kind: string;
|
|
30
|
+
readonly options?: Options;
|
|
31
|
+
}
|
|
32
|
+
export interface RuntimeManifest {
|
|
33
|
+
readonly actions: readonly RuntimeActionDescriptor[];
|
|
34
|
+
readonly adapters: readonly RuntimeAdapterDescriptor[];
|
|
35
|
+
readonly bindings: readonly RuntimeBindingDescriptor[];
|
|
36
|
+
readonly config: RuntimeManifestConfig;
|
|
37
|
+
readonly diagnostics: readonly RuntimeDiagnostic[];
|
|
38
|
+
readonly kind: typeof RUNTIME_MANIFEST_KIND;
|
|
39
|
+
readonly version: 1;
|
|
40
|
+
}
|
|
41
|
+
export interface RuntimeManifestInput {
|
|
42
|
+
readonly actions?: readonly RuntimeActionDescriptor[];
|
|
43
|
+
readonly adapters?: readonly RuntimeAdapterDescriptor[];
|
|
44
|
+
readonly bindings?: readonly RuntimeBindingDescriptor[];
|
|
45
|
+
readonly config: RuntimeManifestConfig;
|
|
46
|
+
readonly diagnostics?: readonly RuntimeDiagnostic[];
|
|
47
|
+
}
|
|
48
|
+
export declare function defineRuntimeAction<Data = unknown>(action: RuntimeActionDescriptor<Data>): RuntimeActionDescriptor<Data>;
|
|
49
|
+
export declare function defineRuntimeAdapter<Options = unknown>(adapter: RuntimeAdapterDescriptor<Options>): RuntimeAdapterDescriptor<Options>;
|
|
50
|
+
export declare function defineRuntimeBinding<Value = unknown>(binding: RuntimeBindingDescriptor<Value>): RuntimeBindingDescriptor<Value>;
|
|
51
|
+
export declare function createRuntimeManifest(input: RuntimeManifestInput): RuntimeManifest;
|
|
52
|
+
export declare function listRuntimeCapabilities(): readonly RuntimeCapability[];
|
|
53
|
+
//# sourceMappingURL=runtimeManifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeManifest.d.ts","sourceRoot":"","sources":["../src/runtimeManifest.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,wFAKvB,CAAC;AAEX,eAAO,MAAM,qBAAqB,+BAA+B,CAAC;AAElE,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;CACjD;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC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ACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,uBAAuB,EAAE,CAAC;IACtD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,wBAAwB,EAAE,CAAC;IACxD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,wBAAwB,EAAE,CAAC;IACxD,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IACvC,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;CACrD;AAED,wBAAgB,mBAAmB,CAAC,IAAI,GAAG,OAAO,EAChD,MAAM,EAAE,uBAAuB,CAAC,IAAI,CAAC,GACpC,uBAAuB,CAAC,IAAI,CAAC,CAE/B;AAED,wBAAgB,oBAAoB,CAAC,OAAO,GAAG,OAAO,EACpD,OAAO,EAAE,wBAAwB,CAAC,OAAO,CAAC,GACzC,wBAAwB,CAAC,OAAO,CAAC,CAEnC;AAED,wBAAgB,oBAAoB,CAAC,KAAK,GAAG,OAAO,EAClD,OAAO,EAAE,wBAAwB,CAAC,KAAK,CAAC,GACvC,wBAAwB,CAAC,KAAK,CAAC,CAEjC;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,eAAe,CAUlF;AAED,wBAAgB,uBAAuB,IAAI,SAAS,iBAAiB,EAAE,CAEtE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const RUNTIME_CAPABILITIES = [
|
|
2
|
+
'runtime.render',
|
|
3
|
+
'runtime.actions',
|
|
4
|
+
'runtime.bindings',
|
|
5
|
+
'runtime.adapters',
|
|
6
|
+
];
|
|
7
|
+
export const RUNTIME_MANIFEST_KIND = 'ankhorage-runtime-manifest';
|
|
8
|
+
export function defineRuntimeAction(action) {
|
|
9
|
+
return action;
|
|
10
|
+
}
|
|
11
|
+
export function defineRuntimeAdapter(adapter) {
|
|
12
|
+
return adapter;
|
|
13
|
+
}
|
|
14
|
+
export function defineRuntimeBinding(binding) {
|
|
15
|
+
return binding;
|
|
16
|
+
}
|
|
17
|
+
export function createRuntimeManifest(input) {
|
|
18
|
+
return {
|
|
19
|
+
actions: input.actions ?? [],
|
|
20
|
+
adapters: input.adapters ?? [],
|
|
21
|
+
bindings: input.bindings ?? [],
|
|
22
|
+
config: input.config,
|
|
23
|
+
diagnostics: input.diagnostics ?? [],
|
|
24
|
+
kind: RUNTIME_MANIFEST_KIND,
|
|
25
|
+
version: 1,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function listRuntimeCapabilities() {
|
|
29
|
+
return RUNTIME_CAPABILITIES;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=runtimeManifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeManifest.js","sourceRoot":"","sources":["../src/runtimeManifest.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,gBAAgB;IAChB,iBAAiB;IACjB,kBAAkB;IAClB,kBAAkB;CACV,CAAC;AAEX,MAAM,CAAC,MAAM,qBAAqB,GAAG,4BAA4B,CAAC;AAuDlE,MAAM,UAAU,mBAAmB,CACjC,MAAqC;IAErC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,OAA0C;IAE1C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,OAAwC;IAExC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAA2B;IAC/D,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,EAAE;QAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,EAAE;QAC9B,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,EAAE;QAC9B,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,WAAW,EAAE,KAAK,CAAC,WAAW,IAAI,EAAE;QACpC,IAAI,EAAE,qBAAqB;QAC3B,OAAO,EAAE,CAAC;KACX,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB;IACrC,OAAO,oBAAoB,CAAC;AAC9B,CAAC","sourcesContent":["export const RUNTIME_CAPABILITIES = [\n 'runtime.render',\n 'runtime.actions',\n 'runtime.bindings',\n 'runtime.adapters',\n] as const;\n\nexport const RUNTIME_MANIFEST_KIND = 'ankhorage-runtime-manifest';\n\nexport type RuntimeCapability = (typeof RUNTIME_CAPABILITIES)[number];\n\nexport interface RuntimeDiagnostic {\n readonly code: string;\n readonly message: string;\n readonly severity: 'error' | 'info' | 'warning';\n}\n\nexport interface RuntimeManifestConfig {\n readonly appId: string;\n readonly environment?: string;\n readonly values?: Readonly<Record<string, unknown>>;\n}\n\nexport interface RuntimeActionDescriptor<Data = unknown> {\n readonly capability?: RuntimeCapability;\n readonly description?: string;\n readonly id: string;\n readonly data?: Data;\n}\n\nexport interface RuntimeBindingDescriptor<Value = unknown> {\n readonly actionId?: string;\n readonly id: string;\n readonly source: string;\n readonly target: string;\n readonly value?: Value;\n}\n\nexport interface RuntimeAdapterDescriptor<Options = unknown> {\n readonly id: string;\n readonly kind: string;\n readonly options?: Options;\n}\n\nexport interface RuntimeManifest {\n readonly actions: readonly RuntimeActionDescriptor[];\n readonly adapters: readonly RuntimeAdapterDescriptor[];\n readonly bindings: readonly RuntimeBindingDescriptor[];\n readonly config: RuntimeManifestConfig;\n readonly diagnostics: readonly RuntimeDiagnostic[];\n readonly kind: typeof RUNTIME_MANIFEST_KIND;\n readonly version: 1;\n}\n\nexport interface RuntimeManifestInput {\n readonly actions?: readonly RuntimeActionDescriptor[];\n readonly adapters?: readonly RuntimeAdapterDescriptor[];\n readonly bindings?: readonly RuntimeBindingDescriptor[];\n readonly config: RuntimeManifestConfig;\n readonly diagnostics?: readonly RuntimeDiagnostic[];\n}\n\nexport function defineRuntimeAction<Data = unknown>(\n action: RuntimeActionDescriptor<Data>,\n): RuntimeActionDescriptor<Data> {\n return action;\n}\n\nexport function defineRuntimeAdapter<Options = unknown>(\n adapter: RuntimeAdapterDescriptor<Options>,\n): RuntimeAdapterDescriptor<Options> {\n return adapter;\n}\n\nexport function defineRuntimeBinding<Value = unknown>(\n binding: RuntimeBindingDescriptor<Value>,\n): RuntimeBindingDescriptor<Value> {\n return binding;\n}\n\nexport function createRuntimeManifest(input: RuntimeManifestInput): RuntimeManifest {\n return {\n actions: input.actions ?? [],\n adapters: input.adapters ?? [],\n bindings: input.bindings ?? [],\n config: input.config,\n diagnostics: input.diagnostics ?? [],\n kind: RUNTIME_MANIFEST_KIND,\n version: 1,\n };\n}\n\nexport function listRuntimeCapabilities(): readonly RuntimeCapability[] {\n return RUNTIME_CAPABILITIES;\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ComponentDataBindingRegistry, DataSourceRegistry, DbAdapter, DbRealtimeAdapter, StateAdapter, UiNode } from '@ankhorage/contracts';
|
|
2
|
+
import { type RuntimeBindingOperationResultCache } from './runtimeBindings';
|
|
3
|
+
import type { RuntimeAction, RuntimeRendererConfig } from './RuntimeRendererConfig';
|
|
4
|
+
export declare function resolveRuntimeNodeProps(args: {
|
|
5
|
+
node: UiNode;
|
|
6
|
+
resolveNodeProps?: RuntimeRendererConfig['resolveNodeProps'];
|
|
7
|
+
stateAdapter?: StateAdapter;
|
|
8
|
+
dbAdapter?: DbAdapter;
|
|
9
|
+
dbRealtimeAdapter?: DbRealtimeAdapter;
|
|
10
|
+
bindingContext?: Record<string, unknown>;
|
|
11
|
+
dataSources?: DataSourceRegistry;
|
|
12
|
+
dataBindings?: ComponentDataBindingRegistry;
|
|
13
|
+
operationResults?: RuntimeBindingOperationResultCache;
|
|
14
|
+
}): Record<string, unknown>;
|
|
15
|
+
export declare function wrapRuntimeActionProps(args: {
|
|
16
|
+
props: Record<string, unknown>;
|
|
17
|
+
disableActions: boolean;
|
|
18
|
+
handleAction: (action: RuntimeAction) => void;
|
|
19
|
+
actionHandlerCache: WeakMap<object, (...args: unknown[]) => void>;
|
|
20
|
+
functionHandlerCache: WeakMap<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>;
|
|
21
|
+
}): Record<string, unknown>;
|
|
22
|
+
//# sourceMappingURL=runtimeNodeProps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeNodeProps.d.ts","sourceRoot":"","sources":["../src/runtimeNodeProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,kBAAkB,EAClB,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,MAAM,EACP,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAA0B,KAAK,kCAAkC,EAAE,MAAM,mBAAmB,CAAC;AACpG,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAuEpF,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,CAAC,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;IAC7D,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,YAAY,CAAC,EAAE,4BAA4B,CAAC;IAC5C,gBAAgB,CAAC,EAAE,kCAAkC,CAAC;CACvD,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA+B1B;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC3C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,cAAc,EAAE,OAAO,CAAC;IACxB,YAAY,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;IAC9C,kBAAkB,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC,CAAC;IAClE,oBAAoB,EAAE,OAAO,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAAC;CACjG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAqD1B"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { resolveRuntimeBindings } from './runtimeBindings';
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function isPlainObject(value) {
|
|
6
|
+
if (!isRecord(value)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const prototype = Reflect.getPrototypeOf(value);
|
|
10
|
+
return prototype === Object.prototype || prototype === null;
|
|
11
|
+
}
|
|
12
|
+
function hasActionShape(value) {
|
|
13
|
+
return (typeof value === 'object' && value !== null && 'type' in value && typeof value.type === 'string');
|
|
14
|
+
}
|
|
15
|
+
function isCallbackProp(value) {
|
|
16
|
+
return typeof value === 'function';
|
|
17
|
+
}
|
|
18
|
+
function isNonEmptyActionId(value) {
|
|
19
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
20
|
+
}
|
|
21
|
+
function createStringActionPayload(args) {
|
|
22
|
+
if (args.length === 0) {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
const [firstArg] = args;
|
|
26
|
+
if (isPlainObject(firstArg)) {
|
|
27
|
+
return { payload: firstArg };
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
payload: {
|
|
31
|
+
args,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const noopRuntimeActionHandler = () => undefined;
|
|
36
|
+
function resolveImageAssetUrl(value) {
|
|
37
|
+
if (typeof value === 'string') {
|
|
38
|
+
const url = value.trim();
|
|
39
|
+
return url.length ? url : null;
|
|
40
|
+
}
|
|
41
|
+
if (!isRecord(value) || typeof value.kind !== 'string') {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
if (value.kind === 'url' && typeof value.url === 'string') {
|
|
45
|
+
const url = value.url.trim();
|
|
46
|
+
return url.length ? url : null;
|
|
47
|
+
}
|
|
48
|
+
if (value.kind === 'storage' && typeof value.publicUrl === 'string') {
|
|
49
|
+
const publicUrl = value.publicUrl.trim();
|
|
50
|
+
return publicUrl.length ? publicUrl : null;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
export function resolveRuntimeNodeProps(args) {
|
|
55
|
+
const { node, resolveNodeProps } = args;
|
|
56
|
+
const baseProps = {
|
|
57
|
+
testID: node.id,
|
|
58
|
+
...(node.props ?? {}),
|
|
59
|
+
};
|
|
60
|
+
if (node.type === 'Image') {
|
|
61
|
+
const resolvedSource = resolveImageAssetUrl(baseProps.source);
|
|
62
|
+
if (resolvedSource !== null)
|
|
63
|
+
baseProps.source = resolvedSource;
|
|
64
|
+
else
|
|
65
|
+
delete baseProps.source;
|
|
66
|
+
}
|
|
67
|
+
if (node.style) {
|
|
68
|
+
baseProps.style = baseProps.style ? [baseProps.style, node.style] : node.style;
|
|
69
|
+
}
|
|
70
|
+
const bindingResult = resolveRuntimeBindings({
|
|
71
|
+
context: args.bindingContext,
|
|
72
|
+
dataBindings: args.dataBindings,
|
|
73
|
+
dataSources: args.dataSources,
|
|
74
|
+
node,
|
|
75
|
+
operationResults: args.operationResults,
|
|
76
|
+
props: baseProps,
|
|
77
|
+
stateAdapter: args.stateAdapter,
|
|
78
|
+
});
|
|
79
|
+
return resolveNodeProps
|
|
80
|
+
? resolveNodeProps({ node, props: bindingResult.props })
|
|
81
|
+
: bindingResult.props;
|
|
82
|
+
}
|
|
83
|
+
export function wrapRuntimeActionProps(args) {
|
|
84
|
+
const { props, disableActions, handleAction, actionHandlerCache, functionHandlerCache } = args;
|
|
85
|
+
const wrappedProps = { ...props };
|
|
86
|
+
Object.keys(wrappedProps).forEach((key) => {
|
|
87
|
+
if (!key.startsWith('on')) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const value = wrappedProps[key];
|
|
91
|
+
if (disableActions) {
|
|
92
|
+
wrappedProps[key] =
|
|
93
|
+
hasActionShape(value) || isNonEmptyActionId(value) ? noopRuntimeActionHandler : undefined;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (hasActionShape(value)) {
|
|
97
|
+
const actionObject = value;
|
|
98
|
+
let actionHandler = actionHandlerCache.get(actionObject);
|
|
99
|
+
if (!actionHandler) {
|
|
100
|
+
actionHandler = () => {
|
|
101
|
+
handleAction(actionObject);
|
|
102
|
+
};
|
|
103
|
+
actionHandlerCache.set(actionObject, actionHandler);
|
|
104
|
+
}
|
|
105
|
+
wrappedProps[key] = actionHandler;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (isNonEmptyActionId(value)) {
|
|
109
|
+
const actionId = value.trim();
|
|
110
|
+
wrappedProps[key] = (...handlerArgs) => {
|
|
111
|
+
handleAction({
|
|
112
|
+
type: actionId,
|
|
113
|
+
...createStringActionPayload(handlerArgs),
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (isCallbackProp(value)) {
|
|
119
|
+
const handler = value;
|
|
120
|
+
let wrappedHandler = functionHandlerCache.get(handler);
|
|
121
|
+
if (!wrappedHandler) {
|
|
122
|
+
wrappedHandler = (...handlerArgs) => handler(...handlerArgs);
|
|
123
|
+
functionHandlerCache.set(handler, wrappedHandler);
|
|
124
|
+
}
|
|
125
|
+
wrappedProps[key] = wrappedHandler;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return wrappedProps;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=runtimeNod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K,CAAC;YACtB,IAAI,cAAc,GAAG,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACvD,IAAI,CAAC,cAAc,EAAE,CAAC;gBACpB,cAAc,GAAG,CAAC,GAAG,WAAsB,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,CAAC;gBACxE,oBAAoB,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;YACpD,CAAC;YACD,YAAY,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC;QACrC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import type {\n ComponentDataBindingRegistry,\n DataSourceRegistry,\n DbAdapter,\n DbRealtimeAdapter,\n StateAdapter,\n UiNode,\n} from '@ankhorage/contracts';\n\nimport { resolveRuntimeBindings, type RuntimeBindingOperationResultCache } from './runtimeBindings';\nimport type { RuntimeAction, RuntimeRendererConfig } from './RuntimeRendererConfig';\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (!isRecord(value)) {\n return false;\n }\n\n const prototype = Reflect.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction hasActionShape(value: unknown): value is RuntimeAction {\n return (\n typeof value === 'object' && value !== null && 'type' in value && typeof value.type === 'string'\n );\n}\n\nfunction isCallbackProp(value: unknown): value is (...args: unknown[]) => unknown {\n return typeof value === 'function';\n}\n\nfunction isNonEmptyActionId(value: unknown): value is string {\n return typeof value === 'string' && value.trim().length > 0;\n}\n\nfunction createStringActionPayload(args: unknown[]): { payload?: object } {\n if (args.length === 0) {\n return {};\n }\n\n const [firstArg] = args;\n if (isPlainObject(firstArg)) {\n return { payload: firstArg };\n }\n\n return {\n payload: {\n args,\n },\n };\n}\n\nconst noopRuntimeActionHandler = () => undefined;\n\nfunction resolveImageAssetUrl(value: unknown): string | null {\n if (typeof value === 'string') {\n const url = value.trim();\n return url.length ? url : null;\n }\n\n if (!isRecord(value) || typeof value.kind !== 'string') {\n return null;\n }\n\n if (value.kind === 'url' && typeof value.url === 'string') {\n const url = value.url.trim();\n return url.length ? url : null;\n }\n\n if (value.kind === 'storage' && typeof value.publicUrl === 'string') {\n const publicUrl = value.publicUrl.trim();\n return publicUrl.length ? publicUrl : null;\n }\n\n return null;\n}\n\nexport function resolveRuntimeNodeProps(args: {\n node: UiNode;\n resolveNodeProps?: RuntimeRendererConfig['resolveNodeProps'];\n stateAdapter?: StateAdapter;\n dbAdapter?: DbAdapter;\n dbRealtimeAdapter?: DbRealtimeAdapter;\n bindingContext?: Record<string, unknown>;\n dataSources?: DataSourceRegistry;\n dataBindings?: ComponentDataBindingRegistry;\n operationResults?: RuntimeBindingOperationResultCache;\n}): Record<string, unknown> {\n const { node, resolveNodeProps } = args;\n\n const baseProps: Record<string, unknown> = {\n testID: node.id,\n ...(node.props ?? {}),\n };\n\n if (node.type === 'Image') {\n const resolvedSource = resolveImageAssetUrl(baseProps.source);\n if (resolvedSource !== null) baseProps.source = resolvedSource;\n else delete baseProps.source;\n }\n\n if (node.style) {\n baseProps.style = baseProps.style ? [baseProps.style, node.style] : node.style;\n }\n\n const bindingResult = resolveRuntimeBindings({\n context: args.bindingContext,\n dataBindings: args.dataBindings,\n dataSources: args.dataSources,\n node,\n operationResults: args.operationResults,\n props: baseProps,\n stateAdapter: args.stateAdapter,\n });\n\n return resolveNodeProps\n ? resolveNodeProps({ node, props: bindingResult.props })\n : bindingResult.props;\n}\n\nexport function wrapRuntimeActionProps(args: {\n props: Record<string, unknown>;\n disableActions: boolean;\n handleAction: (action: RuntimeAction) => void;\n actionHandlerCache: WeakMap<object, (...args: unknown[]) => void>;\n functionHandlerCache: WeakMap<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>;\n}): Record<string, unknown> {\n const { props, disableActions, handleAction, actionHandlerCache, functionHandlerCache } = args;\n const wrappedProps: Record<string, unknown> = { ...props };\n\n Object.keys(wrappedProps).forEach((key) => {\n if (!key.startsWith('on')) {\n return;\n }\n\n const value = wrappedProps[key];\n\n if (disableActions) {\n wrappedProps[key] =\n hasActionShape(value) || isNonEmptyActionId(value) ? noopRuntimeActionHandler : undefined;\n return;\n }\n\n if (hasActionShape(value)) {\n const actionObject = value;\n let actionHandler = actionHandlerCache.get(actionObject);\n if (!actionHandler) {\n actionHandler = () => {\n handleAction(actionObject);\n };\n actionHandlerCache.set(actionObject, actionHandler);\n }\n wrappedProps[key] = actionHandler;\n return;\n }\n\n if (isNonEmptyActionId(value)) {\n const actionId = value.trim();\n wrappedProps[key] = (...handlerArgs: unknown[]) => {\n handleAction({\n type: actionId,\n ...createStringActionPayload(handlerArgs),\n });\n };\n return;\n }\n\n if (isCallbackProp(value)) {\n const handler = value;\n let wrappedHandler = functionHandlerCache.get(handler);\n if (!wrappedHandler) {\n wrappedHandler = (...handlerArgs: unknown[]) => handler(...handlerArgs);\n functionHandlerCache.set(handler, wrappedHandler);\n }\n wrappedProps[key] = wrappedHandler;\n }\n });\n\n return wrappedProps;\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { BindingValue, DataSourceDiagnostic, UiNode, UiNodeRepeatSpec } from '@ankhorage/contracts';
|
|
2
|
+
import { type RuntimeBindingOperationResultWriter, type RuntimeBindingResolutionContext } from './runtimeBindings';
|
|
3
|
+
export interface RuntimeRepeatResolutionContext extends RuntimeBindingResolutionContext {
|
|
4
|
+
readonly node: UiNode;
|
|
5
|
+
readonly writeOperationResult?: RuntimeBindingOperationResultWriter;
|
|
6
|
+
}
|
|
7
|
+
export interface RuntimeRepeatItemsResult {
|
|
8
|
+
readonly items: readonly BindingValue[];
|
|
9
|
+
readonly diagnostics: readonly DataSourceDiagnostic[];
|
|
10
|
+
}
|
|
11
|
+
export interface RuntimeRepeatItemsSyncResult extends RuntimeRepeatItemsResult {
|
|
12
|
+
readonly status: 'ready' | 'pending';
|
|
13
|
+
}
|
|
14
|
+
export declare function resolveRuntimeRepeatItemsSync(repeat: UiNodeRepeatSpec, context: RuntimeRepeatResolutionContext): RuntimeRepeatItemsSyncResult;
|
|
15
|
+
export declare function resolveRuntimeRepeatItemsAsync(repeat: UiNodeRepeatSpec, context: RuntimeRepeatResolutionContext): Promise<RuntimeRepeatItemsResult>;
|
|
16
|
+
export declare function createRuntimeRepeatBindingContext(args: {
|
|
17
|
+
readonly baseContext?: Record<string, unknown>;
|
|
18
|
+
readonly item: BindingValue;
|
|
19
|
+
readonly itemAlias?: string;
|
|
20
|
+
}): Record<string, unknown>;
|
|
21
|
+
export declare function resolveRuntimeRepeatItemKey(args: {
|
|
22
|
+
readonly item: BindingValue;
|
|
23
|
+
readonly itemAlias?: string;
|
|
24
|
+
readonly index: number;
|
|
25
|
+
readonly keyPath?: string;
|
|
26
|
+
}): string | number;
|
|
27
|
+
//# sourceMappingURL=runtimeRepeat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeRepeat.d.ts","sourceRoot":"","sources":["../src/runtimeRepeat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,MAAM,EACN,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAKL,KAAK,mCAAmC,EACxC,KAAK,+BAA+B,EACrC,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,8BAA+B,SAAQ,+BAA+B;IACrF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,oBAAoB,CAAC,EAAE,mCAAmC,CAAC;CACrE;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;IACxC,QAAQ,CAAC,WAAW,EAAE,SAAS,oBAAoB,EAAE,CAAC;CACvD;AAED,MAAM,WAAW,4BAA6B,SAAQ,wBAAwB;IAC5E,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;CACtC;AAED,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,8BAA8B,GACtC,4BAA4B,CA0C9B;AAED,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,wBAAwB,CAAC,CA4DnC;AAED,wBAAgB,iCAAiC,CAAC,IAAI,EAAE;IACtD,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/C,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAK1B;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE;IAChD,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,MAAM,GAAG,MAAM,CAiBlB"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { applyRuntimeBindingDataPath, createRuntimeBindingOperationKey, resolveRuntimeBindingOperationSelection, resolveRuntimeBindingValueSourceSync, } from './runtimeBindings';
|
|
2
|
+
export function resolveRuntimeRepeatItemsSync(repeat, context) {
|
|
3
|
+
if (repeat.source.kind !== 'operation') {
|
|
4
|
+
const diagnostics = [];
|
|
5
|
+
const resolved = resolveRuntimeBindingValueSourceSync(repeat.source, context, diagnostics);
|
|
6
|
+
return {
|
|
7
|
+
status: 'ready',
|
|
8
|
+
...finalizeRuntimeRepeatItems(repeat, resolved, diagnostics),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
const operationKey = createRuntimeBindingOperationKey(repeat.source.operation);
|
|
12
|
+
const cached = context.operationResults?.[operationKey];
|
|
13
|
+
if (cached !== undefined) {
|
|
14
|
+
return {
|
|
15
|
+
status: 'ready',
|
|
16
|
+
...finalizeRuntimeRepeatItems(repeat, applyRuntimeBindingDataPath(cached, repeat.source.path), []),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (context.executeOperation !== undefined) {
|
|
20
|
+
return {
|
|
21
|
+
status: 'pending',
|
|
22
|
+
items: [],
|
|
23
|
+
diagnostics: [],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
status: 'ready',
|
|
28
|
+
items: [],
|
|
29
|
+
diagnostics: [
|
|
30
|
+
createRepeatDiagnostic(repeat, 'missing-adapter', 'Repeat operation source requires an injected operation executor.'),
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export async function resolveRuntimeRepeatItemsAsync(repeat, context) {
|
|
35
|
+
if (repeat.source.kind !== 'operation') {
|
|
36
|
+
const diagnostics = [];
|
|
37
|
+
const resolved = await Promise.resolve(resolveRuntimeBindingValueSourceSync(repeat.source, context, diagnostics));
|
|
38
|
+
return finalizeRuntimeRepeatItems(repeat, resolved, diagnostics);
|
|
39
|
+
}
|
|
40
|
+
const operationKey = createRuntimeBindingOperationKey(repeat.source.operation);
|
|
41
|
+
const cached = context.operationResults?.[operationKey];
|
|
42
|
+
if (cached !== undefined) {
|
|
43
|
+
return finalizeRuntimeRepeatItems(repeat, applyRuntimeBindingDataPath(cached, repeat.source.path), []);
|
|
44
|
+
}
|
|
45
|
+
if (context.executeOperation === undefined) {
|
|
46
|
+
return {
|
|
47
|
+
items: [],
|
|
48
|
+
diagnostics: [
|
|
49
|
+
createRepeatDiagnostic(repeat, 'missing-adapter', 'Repeat operation source requires an injected operation executor.'),
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const diagnostics = [];
|
|
54
|
+
const selection = resolveRuntimeBindingOperationSelection(repeat.source.operation, context.dataSources, diagnostics);
|
|
55
|
+
if (selection === undefined) {
|
|
56
|
+
return { items: [], diagnostics };
|
|
57
|
+
}
|
|
58
|
+
const result = await context.executeOperation({
|
|
59
|
+
operation: repeat.source.operation,
|
|
60
|
+
dataSource: selection.dataSource,
|
|
61
|
+
endpoint: selection.endpoint,
|
|
62
|
+
node: context.node,
|
|
63
|
+
});
|
|
64
|
+
diagnostics.push(...(result.diagnostics ?? []));
|
|
65
|
+
if (!result.ok) {
|
|
66
|
+
return { items: [], diagnostics };
|
|
67
|
+
}
|
|
68
|
+
context.writeOperationResult?.(operationKey, result.data);
|
|
69
|
+
return finalizeRuntimeRepeatItems(repeat, applyRuntimeBindingDataPath(result.data, repeat.source.path), diagnostics);
|
|
70
|
+
}
|
|
71
|
+
export function createRuntimeRepeatBindingContext(args) {
|
|
72
|
+
return {
|
|
73
|
+
...(args.baseContext ?? {}),
|
|
74
|
+
[args.itemAlias ?? 'item']: args.item,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export function resolveRuntimeRepeatItemKey(args) {
|
|
78
|
+
const explicitKey = readRepeatPrimitive(args.item, args.keyPath ?? 'id');
|
|
79
|
+
if (explicitKey !== undefined) {
|
|
80
|
+
return explicitKey;
|
|
81
|
+
}
|
|
82
|
+
const fallbackId = readRepeatPrimitive(args.item, 'id');
|
|
83
|
+
if (fallbackId !== undefined) {
|
|
84
|
+
return fallbackId;
|
|
85
|
+
}
|
|
86
|
+
const fallbackItemId = readRepeatPrimitive(args.item, 'itemId');
|
|
87
|
+
if (fallbackItemId !== undefined) {
|
|
88
|
+
return fallbackItemId;
|
|
89
|
+
}
|
|
90
|
+
return args.index;
|
|
91
|
+
}
|
|
92
|
+
function finalizeRuntimeRepeatItems(repeat, value, diagnostics) {
|
|
93
|
+
if (Array.isArray(value)) {
|
|
94
|
+
return {
|
|
95
|
+
items: value,
|
|
96
|
+
diagnostics,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
items: [],
|
|
101
|
+
diagnostics: [
|
|
102
|
+
...diagnostics,
|
|
103
|
+
createRepeatDiagnostic(repeat, 'invalid-config', 'Repeat source must resolve to an array.'),
|
|
104
|
+
],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function createRepeatDiagnostic(repeat, code, message) {
|
|
108
|
+
return {
|
|
109
|
+
code,
|
|
110
|
+
dataSourceId: repeat.source.kind === 'operation' ? repeat.source.operation.dataSourceId : undefined,
|
|
111
|
+
endpointId: repeat.source.kind === 'operation' ? repeat.source.operation.endpointId : undefined,
|
|
112
|
+
operationId: repeat.source.kind === 'operation' ? repeat.source.operation.operationId : undefined,
|
|
113
|
+
message,
|
|
114
|
+
severity: 'error',
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function readRepeatPrimitive(value, path) {
|
|
118
|
+
const resolved = path.split('.').reduce((currentValue, part) => {
|
|
119
|
+
if (typeof currentValue !== 'object' || currentValue === null || Array.isArray(currentValue)) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
return currentValue[part];
|
|
123
|
+
}, value);
|
|
124
|
+
if (typeof resolved === 'string' || typeof resolved === 'number') {
|
|
125
|
+
return resolved;
|
|
126
|
+
}
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=runtimeRepeat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeRepeat.js","sourceRoot":"","sources":["../src/runtimeRepeat.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,EAChC,uCAAuC,EACvC,oCAAoC,GAGrC,MAAM,mBAAmB,CAAC;AAgB3B,MAAM,UAAU,6BAA6B,CAC3C,MAAwB,EACxB,OAAuC;IAEvC,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACvC,MAAM,WAAW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,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjE,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type {\n BindingValue,\n DataSourceDiagnostic,\n UiNode,\n UiNodeRepeatSpec,\n} from '@ankhorage/contracts';\n\nimport {\n applyRuntimeBindingDataPath,\n createRuntimeBindingOperationKey,\n resolveRuntimeBindingOperationSelection,\n resolveRuntimeBindingValueSourceSync,\n type RuntimeBindingOperationResultWriter,\n type RuntimeBindingResolutionContext,\n} from './runtimeBindings';\n\nexport interface RuntimeRepeatResolutionContext extends RuntimeBindingResolutionContext {\n readonly node: UiNode;\n readonly writeOperationResult?: RuntimeBindingOperationResultWriter;\n}\n\nexport interface RuntimeRepeatItemsResult {\n readonly items: readonly BindingValue[];\n readonly diagnostics: readonly DataSourceDiagnostic[];\n}\n\nexport interface RuntimeRepeatItemsSyncResult extends RuntimeRepeatItemsResult {\n readonly status: 'ready' | 'pending';\n}\n\nexport function resolveRuntimeRepeatItemsSync(\n repeat: UiNodeRepeatSpec,\n context: RuntimeRepeatResolutionContext,\n): RuntimeRepeatItemsSyncResult {\n if (repeat.source.kind !== 'operation') {\n const diagnostics: DataSourceDiagnostic[] = [];\n const resolved = resolveRuntimeBindingValueSourceSync(repeat.source, context, diagnostics);\n return {\n status: 'ready',\n ...finalizeRuntimeRepeatItems(repeat, resolved, diagnostics),\n };\n }\n\n const operationKey = createRuntimeBindingOperationKey(repeat.source.operation);\n const cached = context.operationResults?.[operationKey];\n if (cached !== undefined) {\n return {\n status: 'ready',\n ...finalizeRuntimeRepeatItems(\n repeat,\n applyRuntimeBindingDataPath(cached, repeat.source.path),\n [],\n ),\n };\n }\n\n if (context.executeOperation !== undefined) {\n return {\n status: 'pending',\n items: [],\n diagnostics: [],\n };\n }\n\n return {\n status: 'ready',\n items: [],\n diagnostics: [\n createRepeatDiagnostic(\n repeat,\n 'missing-adapter',\n 'Repeat operation source requires an injected operation executor.',\n ),\n ],\n };\n}\n\nexport async function resolveRuntimeRepeatItemsAsync(\n repeat: UiNodeRepeatSpec,\n context: RuntimeRepeatResolutionContext,\n): Promise<RuntimeRepeatItemsResult> {\n if (repeat.source.kind !== 'operation') {\n const diagnostics: DataSourceDiagnostic[] = [];\n const resolved = await Promise.resolve(\n resolveRuntimeBindingValueSourceSync(repeat.source, context, diagnostics),\n );\n return finalizeRuntimeRepeatItems(repeat, resolved, diagnostics);\n }\n\n const operationKey = createRuntimeBindingOperationKey(repeat.source.operation);\n const cached = context.operationResults?.[operationKey];\n if (cached !== undefined) {\n return finalizeRuntimeRepeatItems(\n repeat,\n applyRuntimeBindingDataPath(cached, repeat.source.path),\n [],\n );\n }\n\n if (context.executeOperation === undefined) {\n return {\n items: [],\n diagnostics: [\n createRepeatDiagnostic(\n repeat,\n 'missing-adapter',\n 'Repeat operation source requires an injected operation executor.',\n ),\n ],\n };\n }\n\n const diagnostics: DataSourceDiagnostic[] = [];\n const selection = resolveRuntimeBindingOperationSelection(\n repeat.source.operation,\n context.dataSources,\n diagnostics,\n );\n if (selection === undefined) {\n return { items: [], diagnostics };\n }\n\n const result = await context.executeOperation({\n operation: repeat.source.operation,\n dataSource: selection.dataSource,\n endpoint: selection.endpoint,\n node: context.node,\n });\n diagnostics.push(...(result.diagnostics ?? []));\n\n if (!result.ok) {\n return { items: [], diagnostics };\n }\n\n context.writeOperationResult?.(operationKey, result.data);\n return finalizeRuntimeRepeatItems(\n repeat,\n applyRuntimeBindingDataPath(result.data, repeat.source.path),\n diagnostics,\n );\n}\n\nexport function createRuntimeRepeatBindingContext(args: {\n readonly baseContext?: Record<string, unknown>;\n readonly item: BindingValue;\n readonly itemAlias?: string;\n}): Record<string, unknown> {\n return {\n ...(args.baseContext ?? {}),\n [args.itemAlias ?? 'item']: args.item,\n };\n}\n\nexport function resolveRuntimeRepeatItemKey(args: {\n readonly item: BindingValue;\n readonly itemAlias?: string;\n readonly index: number;\n readonly keyPath?: string;\n}): string | number {\n const explicitKey = readRepeatPrimitive(args.item, args.keyPath ?? 'id');\n if (explicitKey !== undefined) {\n return explicitKey;\n }\n\n const fallbackId = readRepeatPrimitive(args.item, 'id');\n if (fallbackId !== undefined) {\n return fallbackId;\n }\n\n const fallbackItemId = readRepeatPrimitive(args.item, 'itemId');\n if (fallbackItemId !== undefined) {\n return fallbackItemId;\n }\n\n return args.index;\n}\n\nfunction finalizeRuntimeRepeatItems(\n repeat: UiNodeRepeatSpec,\n value: BindingValue | undefined,\n diagnostics: readonly DataSourceDiagnostic[],\n): RuntimeRepeatItemsResult {\n if (Array.isArray(value)) {\n return {\n items: value,\n diagnostics,\n };\n }\n\n return {\n items: [],\n diagnostics: [\n ...diagnostics,\n createRepeatDiagnostic(repeat, 'invalid-config', 'Repeat source must resolve to an array.'),\n ],\n };\n}\n\nfunction createRepeatDiagnostic(\n repeat: UiNodeRepeatSpec,\n code: DataSourceDiagnostic['code'],\n message: string,\n): DataSourceDiagnostic {\n return {\n code,\n dataSourceId:\n repeat.source.kind === 'operation' ? repeat.source.operation.dataSourceId : undefined,\n endpointId: repeat.source.kind === 'operation' ? repeat.source.operation.endpointId : undefined,\n operationId:\n repeat.source.kind === 'operation' ? repeat.source.operation.operationId : undefined,\n message,\n severity: 'error',\n };\n}\n\nfunction readRepeatPrimitive(value: BindingValue, path: string): string | number | undefined {\n const resolved = path.split('.').reduce<unknown>((currentValue, part) => {\n if (typeof currentValue !== 'object' || currentValue === null || Array.isArray(currentValue)) {\n return undefined;\n }\n\n return (currentValue as Record<string, unknown>)[part];\n }, value);\n\n if (typeof resolved === 'string' || typeof resolved === 'number') {\n return resolved;\n }\n\n return undefined;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeRepeatDiagnostics.d.ts","sourceRoot":"","sources":["../src/runtimeRepeatDiagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,SAAS,oBAAoB,EAAE,GAC3C,MAAM,CAYR"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function createRepeatDiagnosticsKey(nodeId, diagnostics) {
|
|
2
|
+
return JSON.stringify({
|
|
3
|
+
nodeId,
|
|
4
|
+
diagnostics: diagnostics.map((diagnostic) => ({
|
|
5
|
+
code: diagnostic.code,
|
|
6
|
+
message: diagnostic.message,
|
|
7
|
+
severity: diagnostic.severity,
|
|
8
|
+
dataSourceId: diagnostic.dataSourceId,
|
|
9
|
+
endpointId: diagnostic.endpointId,
|
|
10
|
+
operationId: diagnostic.operationId,
|
|
11
|
+
})),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=runtimeRepeatDiagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeRepeatDiagnostics.js","sourceRoot":"","sources":["../src/runtimeRepeatDiagnostics.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,0BAA0B,CACxC,MAAc,EACd,WAA4C;IAE5C,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,MAAM;QACN,WAAW,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;YAC5C,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,OAAO,EAAE,UAAU,CAAC,OAAO;YAC3B,QAAQ,EAAE,UAAU,CAAC,QAAQ;YAC7B,YAAY,EAAE,UAAU,CAAC,YAAY;YACrC,UAAU,EAAE,UAAU,CAAC,UAAU;YACjC,WAAW,EAAE,UAAU,CAAC,WAAW;SACpC,CAAC,CAAC;KACJ,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { DataSourceDiagnostic } from '@ankhorage/contracts';\n\nexport function createRepeatDiagnosticsKey(\n nodeId: string,\n diagnostics: readonly DataSourceDiagnostic[],\n): string {\n return JSON.stringify({\n nodeId,\n diagnostics: diagnostics.map((diagnostic) => ({\n code: diagnostic.code,\n message: diagnostic.message,\n severity: diagnostic.severity,\n dataSourceId: diagnostic.dataSourceId,\n endpointId: diagnostic.endpointId,\n operationId: diagnostic.operationId,\n })),\n });\n}\n"]}
|