@next-core/runtime 1.32.0 → 1.33.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.
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getRealValue = getRealValue;
|
|
7
|
+
var _cook = require("@next-core/cook");
|
|
8
|
+
var _inject = require("@next-core/inject");
|
|
9
|
+
var _general = require("@next-core/utils/general");
|
|
10
|
+
var _index = require("./index.js");
|
|
11
|
+
var _Runtime = require("./internal/Runtime.js");
|
|
12
|
+
var _evaluate = require("./internal/compute/evaluate.js");
|
|
13
|
+
var _markAsComputed = require("./internal/compute/markAsComputed.js");
|
|
14
|
+
/**
|
|
15
|
+
* An equivalent of `computeRealValue` but for external usages, with no custom
|
|
16
|
+
* context or options.
|
|
17
|
+
*
|
|
18
|
+
* @param value - Any value which may contains evaluations or placeholders.
|
|
19
|
+
* @returns Computed real value.
|
|
20
|
+
*/
|
|
21
|
+
function getRealValue(value, {
|
|
22
|
+
useRealTimeQuery
|
|
23
|
+
} = {}) {
|
|
24
|
+
const ctx = {
|
|
25
|
+
...(0, _Runtime._internalApiGetRuntimeContext)()
|
|
26
|
+
};
|
|
27
|
+
if (useRealTimeQuery) {
|
|
28
|
+
ctx.query = new URLSearchParams((0, _index.getHistory)().location.search);
|
|
29
|
+
}
|
|
30
|
+
const compute = data => {
|
|
31
|
+
if (typeof data === "string") {
|
|
32
|
+
if ((0, _cook.isEvaluable)(data)) {
|
|
33
|
+
const result = (0, _evaluate.evaluate)(data, ctx);
|
|
34
|
+
(0, _markAsComputed.markAsComputed)(result);
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
return (0, _inject.inject)(data, ctx);
|
|
38
|
+
}
|
|
39
|
+
if (!(0, _general.isObject)(data) || (0, _markAsComputed.hasBeenComputed)(value)) {
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(data)) {
|
|
43
|
+
return data.map(v => compute(v));
|
|
44
|
+
}
|
|
45
|
+
return Object.fromEntries(Object.entries(data).map(([k, v]) => [compute(k), compute(v)]));
|
|
46
|
+
};
|
|
47
|
+
return compute(value);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=getRealValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRealValue.js","names":["_cook","require","_inject","_general","_index","_Runtime","_evaluate","_markAsComputed","getRealValue","value","useRealTimeQuery","ctx","_internalApiGetRuntimeContext","query","URLSearchParams","getHistory","location","search","compute","data","isEvaluable","result","evaluate","markAsComputed","inject","isObject","hasBeenComputed","Array","isArray","map","v","Object","fromEntries","entries","k"],"sources":["../../src/getRealValue.ts"],"sourcesContent":["import { isEvaluable } from \"@next-core/cook\";\nimport { inject } from \"@next-core/inject\";\nimport { isObject } from \"@next-core/utils/general\";\nimport { getHistory } from \"./index.js\";\nimport { _internalApiGetRuntimeContext } from \"./internal/Runtime.js\";\nimport { evaluate } from \"./internal/compute/evaluate.js\";\nimport type { RuntimeContext } from \"./internal/interfaces.js\";\nimport {\n hasBeenComputed,\n markAsComputed,\n} from \"./internal/compute/markAsComputed.js\";\n\n/**\n * An equivalent of `computeRealValue` but for external usages, with no custom\n * context or options.\n *\n * @param value - Any value which may contains evaluations or placeholders.\n * @returns Computed real value.\n */\nexport function getRealValue(\n value: unknown,\n {\n useRealTimeQuery,\n }: {\n useRealTimeQuery?: boolean;\n } = {}\n): unknown {\n const ctx: RuntimeContext = {\n ..._internalApiGetRuntimeContext()!,\n };\n if (useRealTimeQuery) {\n ctx.query = new URLSearchParams(getHistory().location.search);\n }\n\n const compute = (data: unknown): unknown => {\n if (typeof data === \"string\") {\n if (isEvaluable(data)) {\n const result = evaluate(data, ctx);\n markAsComputed(result);\n return result;\n }\n return inject(data, ctx);\n }\n\n if (!isObject(data) || hasBeenComputed(value)) {\n return data;\n }\n\n if (Array.isArray(data)) {\n return data.map((v) => compute(v));\n }\n\n return Object.fromEntries(\n Object.entries(data).map(([k, v]) => [compute(k), compute(v)])\n );\n };\n\n return compute(value);\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AAEA,IAAAM,eAAA,GAAAN,OAAA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASO,YAAYA,CAC1BC,KAAc,EACd;EACEC;AAGF,CAAC,GAAG,CAAC,CAAC,EACG;EACT,MAAMC,GAAmB,GAAG;IAC1B,GAAG,IAAAC,sCAA6B,EAAC;EACnC,CAAC;EACD,IAAIF,gBAAgB,EAAE;IACpBC,GAAG,CAACE,KAAK,GAAG,IAAIC,eAAe,CAAC,IAAAC,iBAAU,EAAC,CAAC,CAACC,QAAQ,CAACC,MAAM,CAAC;EAC/D;EAEA,MAAMC,OAAO,GAAIC,IAAa,IAAc;IAC1C,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MAC5B,IAAI,IAAAC,iBAAW,EAACD,IAAI,CAAC,EAAE;QACrB,MAAME,MAAM,GAAG,IAAAC,kBAAQ,EAACH,IAAI,EAAER,GAAG,CAAC;QAClC,IAAAY,8BAAc,EAACF,MAAM,CAAC;QACtB,OAAOA,MAAM;MACf;MACA,OAAO,IAAAG,cAAM,EAACL,IAAI,EAAER,GAAG,CAAC;IAC1B;IAEA,IAAI,CAAC,IAAAc,iBAAQ,EAACN,IAAI,CAAC,IAAI,IAAAO,+BAAe,EAACjB,KAAK,CAAC,EAAE;MAC7C,OAAOU,IAAI;IACb;IAEA,IAAIQ,KAAK,CAACC,OAAO,CAACT,IAAI,CAAC,EAAE;MACvB,OAAOA,IAAI,CAACU,GAAG,CAAEC,CAAC,IAAKZ,OAAO,CAACY,CAAC,CAAC,CAAC;IACpC;IAEA,OAAOC,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACd,IAAI,CAAC,CAACU,GAAG,CAAC,CAAC,CAACK,CAAC,EAAEJ,CAAC,CAAC,KAAK,CAACZ,OAAO,CAACgB,CAAC,CAAC,EAAEhB,OAAO,CAACY,CAAC,CAAC,CAAC,CAC/D,CAAC;EACH,CAAC;EAED,OAAOZ,OAAO,CAACT,KAAK,CAAC;AACvB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
|
+
import { isEvaluable } from "@next-core/cook";
|
|
3
|
+
import { inject } from "@next-core/inject";
|
|
4
|
+
import { isObject } from "@next-core/utils/general";
|
|
5
|
+
import { getHistory } from "./index.js";
|
|
6
|
+
import { _internalApiGetRuntimeContext } from "./internal/Runtime.js";
|
|
7
|
+
import { evaluate } from "./internal/compute/evaluate.js";
|
|
8
|
+
import { hasBeenComputed, markAsComputed } from "./internal/compute/markAsComputed.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An equivalent of `computeRealValue` but for external usages, with no custom
|
|
12
|
+
* context or options.
|
|
13
|
+
*
|
|
14
|
+
* @param value - Any value which may contains evaluations or placeholders.
|
|
15
|
+
* @returns Computed real value.
|
|
16
|
+
*/
|
|
17
|
+
export function getRealValue(value) {
|
|
18
|
+
var {
|
|
19
|
+
useRealTimeQuery
|
|
20
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
21
|
+
var ctx = _objectSpread({}, _internalApiGetRuntimeContext());
|
|
22
|
+
if (useRealTimeQuery) {
|
|
23
|
+
ctx.query = new URLSearchParams(getHistory().location.search);
|
|
24
|
+
}
|
|
25
|
+
var compute = data => {
|
|
26
|
+
if (typeof data === "string") {
|
|
27
|
+
if (isEvaluable(data)) {
|
|
28
|
+
var result = evaluate(data, ctx);
|
|
29
|
+
markAsComputed(result);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
return inject(data, ctx);
|
|
33
|
+
}
|
|
34
|
+
if (!isObject(data) || hasBeenComputed(value)) {
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
if (Array.isArray(data)) {
|
|
38
|
+
return data.map(v => compute(v));
|
|
39
|
+
}
|
|
40
|
+
return Object.fromEntries(Object.entries(data).map(_ref => {
|
|
41
|
+
var [k, v] = _ref;
|
|
42
|
+
return [compute(k), compute(v)];
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
45
|
+
return compute(value);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=getRealValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRealValue.js","names":["isEvaluable","inject","isObject","getHistory","_internalApiGetRuntimeContext","evaluate","hasBeenComputed","markAsComputed","getRealValue","value","useRealTimeQuery","arguments","length","undefined","ctx","_objectSpread","query","URLSearchParams","location","search","compute","data","result","Array","isArray","map","v","Object","fromEntries","entries","_ref","k"],"sources":["../../src/getRealValue.ts"],"sourcesContent":["import { isEvaluable } from \"@next-core/cook\";\nimport { inject } from \"@next-core/inject\";\nimport { isObject } from \"@next-core/utils/general\";\nimport { getHistory } from \"./index.js\";\nimport { _internalApiGetRuntimeContext } from \"./internal/Runtime.js\";\nimport { evaluate } from \"./internal/compute/evaluate.js\";\nimport type { RuntimeContext } from \"./internal/interfaces.js\";\nimport {\n hasBeenComputed,\n markAsComputed,\n} from \"./internal/compute/markAsComputed.js\";\n\n/**\n * An equivalent of `computeRealValue` but for external usages, with no custom\n * context or options.\n *\n * @param value - Any value which may contains evaluations or placeholders.\n * @returns Computed real value.\n */\nexport function getRealValue(\n value: unknown,\n {\n useRealTimeQuery,\n }: {\n useRealTimeQuery?: boolean;\n } = {}\n): unknown {\n const ctx: RuntimeContext = {\n ..._internalApiGetRuntimeContext()!,\n };\n if (useRealTimeQuery) {\n ctx.query = new URLSearchParams(getHistory().location.search);\n }\n\n const compute = (data: unknown): unknown => {\n if (typeof data === \"string\") {\n if (isEvaluable(data)) {\n const result = evaluate(data, ctx);\n markAsComputed(result);\n return result;\n }\n return inject(data, ctx);\n }\n\n if (!isObject(data) || hasBeenComputed(value)) {\n return data;\n }\n\n if (Array.isArray(data)) {\n return data.map((v) => compute(v));\n }\n\n return Object.fromEntries(\n Object.entries(data).map(([k, v]) => [compute(k), compute(v)])\n );\n };\n\n return compute(value);\n}\n"],"mappings":";AAAA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,QAAQ,QAAQ,0BAA0B;AACnD,SAASC,UAAU,QAAQ,YAAY;AACvC,SAASC,6BAA6B,QAAQ,uBAAuB;AACrE,SAASC,QAAQ,QAAQ,gCAAgC;AAEzD,SACEC,eAAe,EACfC,cAAc,QACT,sCAAsC;;AAE7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAC1BC,KAAc,EAML;EAAA,IALT;IACEC;EAGF,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEN,IAAMG,GAAmB,GAAAC,aAAA,KACpBX,6BAA6B,CAAC,CAAC,CACnC;EACD,IAAIM,gBAAgB,EAAE;IACpBI,GAAG,CAACE,KAAK,GAAG,IAAIC,eAAe,CAACd,UAAU,CAAC,CAAC,CAACe,QAAQ,CAACC,MAAM,CAAC;EAC/D;EAEA,IAAMC,OAAO,GAAIC,IAAa,IAAc;IAC1C,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MAC5B,IAAIrB,WAAW,CAACqB,IAAI,CAAC,EAAE;QACrB,IAAMC,MAAM,GAAGjB,QAAQ,CAACgB,IAAI,EAAEP,GAAG,CAAC;QAClCP,cAAc,CAACe,MAAM,CAAC;QACtB,OAAOA,MAAM;MACf;MACA,OAAOrB,MAAM,CAACoB,IAAI,EAAEP,GAAG,CAAC;IAC1B;IAEA,IAAI,CAACZ,QAAQ,CAACmB,IAAI,CAAC,IAAIf,eAAe,CAACG,KAAK,CAAC,EAAE;MAC7C,OAAOY,IAAI;IACb;IAEA,IAAIE,KAAK,CAACC,OAAO,CAACH,IAAI,CAAC,EAAE;MACvB,OAAOA,IAAI,CAACI,GAAG,CAAEC,CAAC,IAAKN,OAAO,CAACM,CAAC,CAAC,CAAC;IACpC;IAEA,OAAOC,MAAM,CAACC,WAAW,CACvBD,MAAM,CAACE,OAAO,CAACR,IAAI,CAAC,CAACI,GAAG,CAACK,IAAA;MAAA,IAAC,CAACC,CAAC,EAAEL,CAAC,CAAC,GAAAI,IAAA;MAAA,OAAK,CAACV,OAAO,CAACW,CAAC,CAAC,EAAEX,OAAO,CAACM,CAAC,CAAC,CAAC;IAAA,EAC/D,CAAC;EACH,CAAC;EAED,OAAON,OAAO,CAACX,KAAK,CAAC;AACvB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An equivalent of `computeRealValue` but for external usages, with no custom
|
|
3
|
+
* context or options.
|
|
4
|
+
*
|
|
5
|
+
* @param value - Any value which may contains evaluations or placeholders.
|
|
6
|
+
* @returns Computed real value.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getRealValue(value: unknown, { useRealTimeQuery, }?: {
|
|
9
|
+
useRealTimeQuery?: boolean;
|
|
10
|
+
}): unknown;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/runtime",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.33.0",
|
|
4
4
|
"homepage": "https://github.com/easyops-cn/next-core/tree/v3/packages/runtime",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"repository": {
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"@next-core/build-next-libs": "^1.0.13",
|
|
67
67
|
"@next-core/test-next": "^1.0.16"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "8164eedf2e6cb4fb2e8c766a197e733e3787da2f"
|
|
70
70
|
}
|