@vortexm/vjt 0.1.12 → 0.1.13
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/index.js +87 -21
- package/dist/lib/references.d.ts +4 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4274,30 +4274,89 @@ var ReferenceRuntime = class {
|
|
|
4274
4274
|
constructor(host) {
|
|
4275
4275
|
this.host = host;
|
|
4276
4276
|
}
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
return currentValue;
|
|
4277
|
+
resolveScopedRootReference(scope, path, currentValue, responseValue, inputValue) {
|
|
4278
|
+
if (scope === "current") {
|
|
4279
|
+
if (path.length === 0) {
|
|
4280
|
+
return currentValue;
|
|
4281
|
+
}
|
|
4282
|
+
return this.resolveCurrentReference(path.join("."), currentValue);
|
|
4283
4283
|
}
|
|
4284
|
-
if (
|
|
4285
|
-
return inputValue;
|
|
4284
|
+
if (scope === "input") {
|
|
4285
|
+
return path.length === 0 ? inputValue : readPath(inputValue, path);
|
|
4286
4286
|
}
|
|
4287
|
-
if (
|
|
4288
|
-
return responseValue;
|
|
4287
|
+
if (scope === "message" || scope === "response") {
|
|
4288
|
+
return path.length === 0 ? responseValue : readPath(responseValue, path);
|
|
4289
4289
|
}
|
|
4290
|
-
if (
|
|
4291
|
-
return
|
|
4290
|
+
if (path.length === 0) {
|
|
4291
|
+
return this.host.getVarsSnapshot();
|
|
4292
4292
|
}
|
|
4293
|
-
|
|
4294
|
-
|
|
4293
|
+
return this.readVarReference(path.join("."));
|
|
4294
|
+
}
|
|
4295
|
+
readVarReference(path) {
|
|
4296
|
+
const [rootKey, ...rest] = path.split(".").filter(Boolean);
|
|
4297
|
+
if (!rootKey) {
|
|
4298
|
+
return void 0;
|
|
4295
4299
|
}
|
|
4296
|
-
|
|
4297
|
-
|
|
4300
|
+
const rootValue = this.host.getVarValue(rootKey);
|
|
4301
|
+
if (rest.length === 0) {
|
|
4302
|
+
return rootValue;
|
|
4298
4303
|
}
|
|
4299
|
-
|
|
4300
|
-
|
|
4304
|
+
return readPath(rootValue, rest);
|
|
4305
|
+
}
|
|
4306
|
+
writeVarReference(path, value) {
|
|
4307
|
+
const [rootKey, ...rest] = path.split(".").filter(Boolean);
|
|
4308
|
+
if (!rootKey) {
|
|
4309
|
+
return;
|
|
4310
|
+
}
|
|
4311
|
+
if (rest.length === 0) {
|
|
4312
|
+
this.host.setVarValue(rootKey, value);
|
|
4313
|
+
return;
|
|
4314
|
+
}
|
|
4315
|
+
const currentRoot = this.host.getVarValue(rootKey);
|
|
4316
|
+
const nextRoot = isPlainObject2(currentRoot) ? structuredClone(currentRoot) : {};
|
|
4317
|
+
if (writePath(nextRoot, rest, value)) {
|
|
4318
|
+
this.host.setVarValue(rootKey, nextRoot);
|
|
4319
|
+
}
|
|
4320
|
+
}
|
|
4321
|
+
isEmptyReference(reference, currentValue, responseValue, inputValue) {
|
|
4322
|
+
return isReferenceValueEmpty(this.resolveReference(reference, currentValue, responseValue, inputValue));
|
|
4323
|
+
}
|
|
4324
|
+
resolveReference(reference, currentValue, responseValue, inputValue = currentValue) {
|
|
4325
|
+
if (reference === "current" || reference.startsWith("current.")) {
|
|
4326
|
+
return this.resolveScopedRootReference(
|
|
4327
|
+
"current",
|
|
4328
|
+
reference === "current" ? [] : reference.slice(8).split(".").filter(Boolean),
|
|
4329
|
+
currentValue,
|
|
4330
|
+
responseValue,
|
|
4331
|
+
inputValue
|
|
4332
|
+
);
|
|
4333
|
+
}
|
|
4334
|
+
if (reference === "input" || reference.startsWith("input.")) {
|
|
4335
|
+
return this.resolveScopedRootReference(
|
|
4336
|
+
"input",
|
|
4337
|
+
reference === "input" ? [] : reference.slice(6).split(".").filter(Boolean),
|
|
4338
|
+
currentValue,
|
|
4339
|
+
responseValue,
|
|
4340
|
+
inputValue
|
|
4341
|
+
);
|
|
4342
|
+
}
|
|
4343
|
+
if (reference === "message" || reference.startsWith("message.")) {
|
|
4344
|
+
return this.resolveScopedRootReference(
|
|
4345
|
+
"message",
|
|
4346
|
+
reference === "message" ? [] : reference.slice(8).split(".").filter(Boolean),
|
|
4347
|
+
currentValue,
|
|
4348
|
+
responseValue,
|
|
4349
|
+
inputValue
|
|
4350
|
+
);
|
|
4351
|
+
}
|
|
4352
|
+
if (reference === "response" || reference.startsWith("response.")) {
|
|
4353
|
+
return this.resolveScopedRootReference(
|
|
4354
|
+
"response",
|
|
4355
|
+
reference === "response" ? [] : reference.slice(9).split(".").filter(Boolean),
|
|
4356
|
+
currentValue,
|
|
4357
|
+
responseValue,
|
|
4358
|
+
inputValue
|
|
4359
|
+
);
|
|
4301
4360
|
}
|
|
4302
4361
|
if (reference.startsWith("cookies.")) {
|
|
4303
4362
|
return getCookieValue(reference.slice(8));
|
|
@@ -4308,8 +4367,14 @@ var ReferenceRuntime = class {
|
|
|
4308
4367
|
if (reference.startsWith("url.")) {
|
|
4309
4368
|
return getUrlParamValue(reference.slice(4));
|
|
4310
4369
|
}
|
|
4311
|
-
if (reference.startsWith("vars.")) {
|
|
4312
|
-
return this.
|
|
4370
|
+
if (reference === "vars" || reference.startsWith("vars.")) {
|
|
4371
|
+
return this.resolveScopedRootReference(
|
|
4372
|
+
"vars",
|
|
4373
|
+
reference === "vars" ? [] : reference.slice(5).split(".").filter(Boolean),
|
|
4374
|
+
currentValue,
|
|
4375
|
+
responseValue,
|
|
4376
|
+
inputValue
|
|
4377
|
+
);
|
|
4313
4378
|
}
|
|
4314
4379
|
const [widgetId, ...rest] = reference.split(".");
|
|
4315
4380
|
const state = this.host.stateById.get(widgetId);
|
|
@@ -4448,7 +4513,7 @@ var ReferenceRuntime = class {
|
|
|
4448
4513
|
return;
|
|
4449
4514
|
}
|
|
4450
4515
|
if (reference.startsWith("vars.")) {
|
|
4451
|
-
this.
|
|
4516
|
+
this.writeVarReference(reference.slice(5), inputValue);
|
|
4452
4517
|
return;
|
|
4453
4518
|
}
|
|
4454
4519
|
const [widgetId, ...rest] = reference.split(".");
|
|
@@ -7475,6 +7540,7 @@ var RuntimeRenderer = class {
|
|
|
7475
7540
|
}
|
|
7476
7541
|
},
|
|
7477
7542
|
getVarValue: (name) => this.vars.get(name),
|
|
7543
|
+
getVarsSnapshot: () => Object.fromEntries(this.vars.entries()),
|
|
7478
7544
|
setVarValue: (name, value) => {
|
|
7479
7545
|
this.vars.set(name, value);
|
|
7480
7546
|
},
|
package/dist/lib/references.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ type ReferenceRuntimeHost = {
|
|
|
8
8
|
getAppValue: (name: string) => unknown;
|
|
9
9
|
setAppValue: (name: string, value: unknown) => void;
|
|
10
10
|
getVarValue: (name: string) => unknown;
|
|
11
|
+
getVarsSnapshot: () => Record<string, unknown>;
|
|
11
12
|
setVarValue: (name: string, value: unknown) => void;
|
|
12
13
|
ensureWidgetState: (node: DescriptionNode, key: string) => WidgetState;
|
|
13
14
|
resolveItemNodeKey: (node: DescriptionNode, listKey: string, index: number, fallbackPath: string) => string;
|
|
@@ -16,6 +17,9 @@ type ReferenceRuntimeHost = {
|
|
|
16
17
|
export declare class ReferenceRuntime {
|
|
17
18
|
private readonly host;
|
|
18
19
|
constructor(host: ReferenceRuntimeHost);
|
|
20
|
+
private resolveScopedRootReference;
|
|
21
|
+
private readVarReference;
|
|
22
|
+
private writeVarReference;
|
|
19
23
|
isEmptyReference(reference: string, currentValue: unknown, responseValue: unknown, inputValue?: unknown): boolean;
|
|
20
24
|
resolveReference(reference: string, currentValue: unknown, responseValue: unknown, inputValue?: unknown): unknown;
|
|
21
25
|
resolveCurrentReference(reference: string, currentValue: unknown): unknown;
|