@next-core/runtime 1.57.4 → 1.58.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/dist/cjs/StoryboardFunctionRegistry.js +62 -45
- package/dist/cjs/StoryboardFunctionRegistry.js.map +1 -1
- package/dist/cjs/internal/Renderer.js +4 -0
- package/dist/cjs/internal/Renderer.js.map +1 -1
- package/dist/cjs/internal/compute/getGeneralGlobals.js.map +1 -1
- package/dist/esm/StoryboardFunctionRegistry.js +62 -45
- package/dist/esm/StoryboardFunctionRegistry.js.map +1 -1
- package/dist/esm/internal/Renderer.js +4 -0
- package/dist/esm/internal/Renderer.js.map +1 -1
- package/dist/esm/internal/compute/getGeneralGlobals.js.map +1 -1
- package/dist/types/StoryboardFunctionRegistry.d.ts +4 -3
- package/dist/types/internal/compute/getGeneralGlobals.d.ts +1 -1
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getGeneralGlobals.js","names":["_lodash","require","_i18n","_WidgetI18n","_proxyFactories","_themeAndMode","_getBasePath","_registerAppI18n","_Runtime","getGeneralGlobals","attemptToVisitGlobals","options","globalVariables","variableName","variable","getIndividualGlobal","undefined","collectCoverage","widgetId","widgetVersion","app","appendI18nNamespace","storyboardFunctions","isStoryboardFunction","_hooks$images","_hooks$images2","_hooks$checkPermissio","getBasePath","replace","fakeImageFactory","hooks","images","widgetImagesFactory","imagesFactory","id","isBuildPush","currentVersion","identity","widgetI18nFactory","i18n","getFixedT","getI18nNamespace","filter","Boolean","fakeI18nText","i18nText","getReadOnlyProxy","check","fakeCheckPermissions","checkPermissions","getTheme","getCssPropertyValue","console","href","origin","host","hostname","location","data","en","get","name"],"sources":["../../../../src/internal/compute/getGeneralGlobals.ts"],"sourcesContent":["import { identity } from \"lodash\";\nimport type { MicroApp } from \"@next-core/types\";\nimport { i18n, i18nText } from \"@next-core/i18n\";\nimport { widgetI18nFactory } from \"./WidgetI18n.js\";\nimport { getReadOnlyProxy } from \"../proxyFactories.js\";\nimport { getCssPropertyValue, getTheme } from \"../../themeAndMode.js\";\nimport { getBasePath } from \"../../getBasePath.js\";\nimport { getI18nNamespace } from \"../registerAppI18n.js\";\nimport { ImagesFactory, hooks } from \"../Runtime.js\";\n\nexport interface GeneralGlobalsOptions {\n collectCoverage?: unknown;\n widgetId?: string;\n widgetVersion?: string;\n app?: PartialMicroApp;\n appendI18nNamespace?: string;\n storyboardFunctions?: unknown;\n isStoryboardFunction?: boolean;\n}\n\nexport type PartialMicroApp = Pick<MicroApp, \"id\" | \"isBuildPush\">;\n\n// `GeneralGlobals` are globals which are page-state-agnostic,\n// thus they can be used both in storyboard expressions and functions.\nexport function getGeneralGlobals(\n attemptToVisitGlobals: Set<string
|
|
1
|
+
{"version":3,"file":"getGeneralGlobals.js","names":["_lodash","require","_i18n","_WidgetI18n","_proxyFactories","_themeAndMode","_getBasePath","_registerAppI18n","_Runtime","getGeneralGlobals","attemptToVisitGlobals","options","globalVariables","variableName","variable","getIndividualGlobal","undefined","collectCoverage","widgetId","widgetVersion","app","appendI18nNamespace","storyboardFunctions","isStoryboardFunction","_hooks$images","_hooks$images2","_hooks$checkPermissio","getBasePath","replace","fakeImageFactory","hooks","images","widgetImagesFactory","imagesFactory","id","isBuildPush","currentVersion","identity","widgetI18nFactory","i18n","getFixedT","getI18nNamespace","filter","Boolean","fakeI18nText","i18nText","getReadOnlyProxy","check","fakeCheckPermissions","checkPermissions","getTheme","getCssPropertyValue","console","href","origin","host","hostname","location","data","en","get","name"],"sources":["../../../../src/internal/compute/getGeneralGlobals.ts"],"sourcesContent":["import { identity } from \"lodash\";\nimport type { MicroApp } from \"@next-core/types\";\nimport { i18n, i18nText } from \"@next-core/i18n\";\nimport { widgetI18nFactory } from \"./WidgetI18n.js\";\nimport { getReadOnlyProxy } from \"../proxyFactories.js\";\nimport { getCssPropertyValue, getTheme } from \"../../themeAndMode.js\";\nimport { getBasePath } from \"../../getBasePath.js\";\nimport { getI18nNamespace } from \"../registerAppI18n.js\";\nimport { ImagesFactory, hooks } from \"../Runtime.js\";\n\nexport interface GeneralGlobalsOptions {\n collectCoverage?: unknown;\n widgetId?: string;\n widgetVersion?: string;\n app?: PartialMicroApp;\n appendI18nNamespace?: string;\n storyboardFunctions?: unknown;\n isStoryboardFunction?: boolean;\n}\n\nexport type PartialMicroApp = Pick<MicroApp, \"id\" | \"isBuildPush\">;\n\n// `GeneralGlobals` are globals which are page-state-agnostic,\n// thus they can be used both in storyboard expressions and functions.\nexport function getGeneralGlobals(\n attemptToVisitGlobals: Set<string> | string[],\n options: GeneralGlobalsOptions\n): Record<string, unknown> {\n const globalVariables: Record<string, unknown> = {};\n for (const variableName of attemptToVisitGlobals) {\n const variable = getIndividualGlobal(variableName, options);\n if (variable !== undefined) {\n globalVariables[variableName] = variable;\n }\n }\n return globalVariables;\n}\n\nfunction getIndividualGlobal(\n variableName: string,\n {\n collectCoverage,\n widgetId,\n widgetVersion,\n app,\n appendI18nNamespace,\n storyboardFunctions,\n isStoryboardFunction,\n }: GeneralGlobalsOptions\n): unknown {\n switch (variableName) {\n case \"BASE_URL\":\n return collectCoverage ? \"/next\" : getBasePath().replace(/\\/$/, \"\");\n case \"FN\":\n return storyboardFunctions;\n case \"IMG\":\n return collectCoverage\n ? fakeImageFactory()\n : widgetId\n ? hooks?.images?.widgetImagesFactory(widgetId, widgetVersion)\n : hooks?.images?.imagesFactory(\n app!.id,\n app!.isBuildPush,\n (app as { currentVersion?: string }).currentVersion\n );\n case \"I18N\":\n return collectCoverage\n ? identity\n : widgetId\n ? widgetI18nFactory(widgetId)\n : i18n.getFixedT(\n null,\n [appendI18nNamespace, getI18nNamespace(\"app\", app!.id)].filter(\n Boolean\n ) as string[]\n );\n case \"I18N_TEXT\":\n return collectCoverage ? fakeI18nText : i18nText;\n case \"PERMISSIONS\":\n return getReadOnlyProxy({\n check: collectCoverage\n ? fakeCheckPermissions\n : hooks?.checkPermissions?.checkPermissions,\n });\n case \"THEME\":\n return getReadOnlyProxy({\n getTheme: collectCoverage ? () => \"light\" : getTheme,\n getCssPropertyValue: collectCoverage ? () => \"\" : getCssPropertyValue,\n });\n case \"console\":\n return isStoryboardFunction ? getReadOnlyProxy(console) : undefined;\n case \"location\":\n return collectCoverage\n ? {\n href: \"http://localhost:3000/functions/test\",\n origin: \"http://localhost:3000\",\n host: \"localhost:3000\",\n hostname: \"localhost\",\n }\n : {\n href: location.href,\n origin: location.origin,\n host: location.host,\n hostname: location.hostname,\n };\n }\n}\n\nfunction fakeI18nText(data: Record<string, string>): string {\n return data?.en;\n}\n\nfunction fakeImageFactory(): ImagesFactory {\n return {\n get(name: string) {\n return `mock/images/${name}`;\n },\n };\n}\n\nfunction fakeCheckPermissions(): boolean {\n return true;\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AACA,IAAAO,QAAA,GAAAP,OAAA;AAcA;AACA;AACO,SAASQ,iBAAiBA,CAC/BC,qBAA6C,EAC7CC,OAA8B,EACL;EACzB,MAAMC,eAAwC,GAAG,CAAC,CAAC;EACnD,KAAK,MAAMC,YAAY,IAAIH,qBAAqB,EAAE;IAChD,MAAMI,QAAQ,GAAGC,mBAAmB,CAACF,YAAY,EAAEF,OAAO,CAAC;IAC3D,IAAIG,QAAQ,KAAKE,SAAS,EAAE;MAC1BJ,eAAe,CAACC,YAAY,CAAC,GAAGC,QAAQ;IAC1C;EACF;EACA,OAAOF,eAAe;AACxB;AAEA,SAASG,mBAAmBA,CAC1BF,YAAoB,EACpB;EACEI,eAAe;EACfC,QAAQ;EACRC,aAAa;EACbC,GAAG;EACHC,mBAAmB;EACnBC,mBAAmB;EACnBC;AACqB,CA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AAK,OAAO;MACV,OAAO,IAAAH,gCAAgB,EAAC;QACtBI,QAAQ,EAAEjC,eAAe,GAAG,MAAM,OAAO,GAAGiC,sBAAQ;QACpDC,mBAAmB,EAAElC,eAAe,GAAG,MAAM,EAAE,GAAGkC;MACpD,CAAC,CAAC;IACJ,KAAK,SAAS;MACZ,OAAO5B,oBAAoB,GAAG,IAAAuB,gCAAgB,EAACM,OAAO,CAAC,GAAGpC,SAAS;IACrE,KAAK,UAAU;MACb,OAAOC,eAAe,GAClB;QACEoC,IAAI,EAAE,sCAAsC;QAC5CC,MAAM,EAAE,uBAAuB;QAC/BC,IAAI,EAAE,gBAAgB;QACtBC,QAAQ,EAAE;MACZ,CAAC,GACD;QACEH,IAAI,EAAEI,QAAQ,CAACJ,IAAI;QACnBC,MAAM,EAAEG,QAAQ,CAACH,MAAM;QACvBC,IAAI,EAAEE,QAAQ,CAACF,IAAI;QACnBC,QAAQ,EAAEC,QAAQ,CAACD;MACrB,CAAC;EACT;AACF;AAEA,SAASZ,YAAYA,CAACc,IAA4B,EAAU;EAC1D,OAAOA,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEC,EAAE;AACjB;AAEA,SAAS9B,gBAAgBA,CAAA,EAAkB;EACzC,OAAO;IACL+B,GAAGA,CAACC,IAAY,EAAE;MAChB,OAAO,eAAeA,IAAI,EAAE;IAC9B;EACF,CAAC;AACH;AAEA,SAASb,oBAAoBA,CAAA,EAAY;EACvC,OAAO,IAAI;AACb","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { cook, precookFunction, __dev_only_clearGlobalExecutionContextStack, __dev_only_getGlobalExecutionContextStack } from "@next-core/cook";
|
|
2
2
|
import { supply } from "@next-core/supply";
|
|
3
3
|
import { collectMemberUsageInFunction } from "@next-core/utils/storyboard";
|
|
4
|
+
import { hasOwnProperty } from "@next-core/utils/general";
|
|
4
5
|
import { getGeneralGlobals } from "./internal/compute/getGeneralGlobals.js";
|
|
5
6
|
|
|
6
7
|
/** @internal */
|
|
@@ -56,12 +57,23 @@ export function StoryboardFunctionRegistryFactory() {
|
|
|
56
57
|
registeredFunctions.set(fn.name, {
|
|
57
58
|
source: fn.source,
|
|
58
59
|
typescript: fn.typescript,
|
|
60
|
+
transformed: fn.transformed,
|
|
59
61
|
deps,
|
|
60
62
|
hasPermissionsCheck
|
|
61
63
|
});
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
}
|
|
67
|
+
function getGlobalVariables(globals) {
|
|
68
|
+
return supply(globals, getGeneralGlobals(globals, {
|
|
69
|
+
collectCoverage,
|
|
70
|
+
widgetId,
|
|
71
|
+
widgetVersion,
|
|
72
|
+
app: currentApp,
|
|
73
|
+
storyboardFunctions,
|
|
74
|
+
isStoryboardFunction: true
|
|
75
|
+
}), !!collectCoverage);
|
|
76
|
+
}
|
|
65
77
|
function getStoryboardFunction(name) {
|
|
66
78
|
const fn = registeredFunctions.get(name);
|
|
67
79
|
if (!fn) {
|
|
@@ -74,51 +86,55 @@ export function StoryboardFunctionRegistryFactory() {
|
|
|
74
86
|
if (collectCoverage) {
|
|
75
87
|
collector = collectCoverage.createCollector(name);
|
|
76
88
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
89
|
+
|
|
90
|
+
// Do not use transformed functions when debugging.
|
|
91
|
+
const transformed = !overrides && !collector && fn.transformed;
|
|
92
|
+
if (transformed) {
|
|
93
|
+
const globalVariables = getGlobalVariables(transformed.globals);
|
|
94
|
+
// Spread globals as params to prevent accessing forbidden globals.
|
|
95
|
+
// NOTE: in native mode, forbidden globals are declared as `undefined`,
|
|
96
|
+
// thus accessing them will not throw a ReferenceError.
|
|
97
|
+
fn.cooked = new Function(...transformed.globals, `"use strict";return (${transformed.source})`)(...transformed.globals.map(key => hasOwnProperty(globalVariables, key) ? globalVariables[key] : undefined));
|
|
98
|
+
} else {
|
|
99
|
+
const precooked = precookFunction(fn.source, {
|
|
100
|
+
typescript: fn.typescript,
|
|
101
|
+
hooks: collector && {
|
|
102
|
+
beforeVisit: collector.beforeVisit
|
|
103
|
+
},
|
|
104
|
+
cacheKey: fn
|
|
105
|
+
});
|
|
106
|
+
const globalVariables = getGlobalVariables(precooked.attemptToVisitGlobals);
|
|
107
|
+
fn.cooked = cook(precooked.function, fn.source, {
|
|
108
|
+
rules: {
|
|
109
|
+
noVar: true
|
|
110
|
+
},
|
|
111
|
+
globalVariables: overrides ? {
|
|
112
|
+
...globalVariables,
|
|
113
|
+
...(overrides !== null && overrides !== void 0 && overrides.LodashWithStaticFields && precooked.attemptToVisitGlobals.has("_") ? {
|
|
114
|
+
_: {
|
|
115
|
+
...globalVariables._,
|
|
116
|
+
...overrides.LodashWithStaticFields
|
|
117
|
+
}
|
|
118
|
+
} : null),
|
|
119
|
+
...(overrides !== null && overrides !== void 0 && overrides.ArrayConstructor && precooked.attemptToVisitGlobals.has("Array") ? {
|
|
120
|
+
Array: overrides.ArrayConstructor
|
|
121
|
+
} : null),
|
|
122
|
+
...(overrides !== null && overrides !== void 0 && overrides.ObjectWithStaticFields && precooked.attemptToVisitGlobals.has("Object") ? {
|
|
123
|
+
Object: {
|
|
124
|
+
...globalVariables.Object,
|
|
125
|
+
...overrides.ObjectWithStaticFields
|
|
126
|
+
}
|
|
127
|
+
} : null)
|
|
128
|
+
} : globalVariables,
|
|
129
|
+
ArrayConstructor: overrides === null || overrides === void 0 ? void 0 : overrides.ArrayConstructor,
|
|
130
|
+
hooks: collector && {
|
|
131
|
+
beforeEvaluate: collector.beforeEvaluate,
|
|
132
|
+
beforeCall: collector.beforeCall,
|
|
133
|
+
beforeBranch: collector.beforeBranch
|
|
134
|
+
},
|
|
135
|
+
debug: !!debuggerOverrides
|
|
136
|
+
});
|
|
137
|
+
}
|
|
122
138
|
fn.processed = true;
|
|
123
139
|
return fn.cooked;
|
|
124
140
|
}
|
|
@@ -135,6 +151,7 @@ export function StoryboardFunctionRegistryFactory() {
|
|
|
135
151
|
registeredFunctions.set(name, {
|
|
136
152
|
source: data.source,
|
|
137
153
|
typescript: data.typescript,
|
|
154
|
+
transformed: data.transformed,
|
|
138
155
|
deps,
|
|
139
156
|
hasPermissionsCheck
|
|
140
157
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoryboardFunctionRegistry.js","names":["cook","precookFunction","__dev_only_clearGlobalExecutionContextStack","__dev_only_getGlobalExecutionContextStack","supply","collectMemberUsageInFunction","getGeneralGlobals","StoryboardFunctionRegistryFactory","widgetId","widgetVersion","collectCoverage","debuggerOverrides","arguments","length","undefined","registeredFunctions","Map","overrides","storyboardFunctions","Proxy","Object","freeze","get","_target","key","getStoryboardFunction","currentApp","registerStoryboardFunctions","functions","app","clear","Array","isArray","fn","_fn$perm","deps","delete","name","hasPermissionsCheck","perm","has","set","source","typescript","processed","cooked","collector","createCollector","precooked","hooks","beforeVisit","cacheKey","globalVariables","attemptToVisitGlobals","isStoryboardFunction","function","rules","noVar","LodashWithStaticFields","_","ArrayConstructor","ObjectWithStaticFields","beforeEvaluate","beforeCall","beforeBranch","debug","updateStoryboardFunction","data","newFn","checkPermissionsUsage","functionNames","checkedFunctions","Set","add","some","clearGlobalExecutionContextStack","getGlobalExecutionContextStack"],"sources":["../../src/StoryboardFunctionRegistry.ts"],"sourcesContent":["import type { MicroApp, StoryboardFunction } from \"@next-core/types\";\nimport {\n cook,\n precookFunction,\n EstreeNode,\n __dev_only_clearGlobalExecutionContextStack,\n __dev_only_getGlobalExecutionContextStack,\n} from \"@next-core/cook\";\nimport { supply } from \"@next-core/supply\";\nimport { collectMemberUsageInFunction } from \"@next-core/utils/storyboard\";\nimport type _ from \"lodash\";\nimport { getGeneralGlobals } from \"./internal/compute/getGeneralGlobals.js\";\n\n/** @internal */\nexport type ReadonlyStoryboardFunctions = Readonly<Record<string, Function>>;\n\n/** @internal */\nexport type StoryboardFunctionPatch = Pick<\n StoryboardFunction,\n \"source\" | \"typescript\"\n>;\n\n/** @internal */\nexport interface StoryboardFunctionRegistry {\n /** A readonly proxy for accessing cooked storyboard functions. */\n storyboardFunctions: ReadonlyStoryboardFunctions;\n\n /** Register storyboard functions. */\n registerStoryboardFunctions(\n functions: StoryboardFunction[] | undefined,\n app?: PartialMicroApp\n ): void;\n\n /** Update a storyboard function during debugging. */\n updateStoryboardFunction(name: string, data: StoryboardFunctionPatch): void;\n\n checkPermissionsUsage(functionNames: string[]): boolean;\n\n clearGlobalExecutionContextStack(): void;\n getGlobalExecutionContextStack(): ReturnType<\n typeof __dev_only_getGlobalExecutionContextStack\n >;\n}\n\n/** @internal */\nexport interface RuntimeStoryboardFunction {\n source: string;\n typescript?: boolean;\n processed?: boolean;\n cooked?: Function;\n deps: Set<string> | string[];\n hasPermissionsCheck: boolean;\n}\n\n/** @internal */\nexport interface FunctionCoverageCollector {\n beforeVisit(node: EstreeNode): void;\n beforeEvaluate(node: EstreeNode): void;\n beforeCall(node: EstreeNode): void;\n beforeBranch(node: EstreeNode, branch: string): void;\n}\n\n/** @internal */\nexport interface FunctionCoverageSettings {\n createCollector(name: string): FunctionCoverageCollector;\n}\n\n/** @internal */\nexport type PartialMicroApp = Pick<MicroApp, \"id\" | \"isBuildPush\">;\n\n/** @internal */\nexport function StoryboardFunctionRegistryFactory({\n widgetId,\n widgetVersion,\n collectCoverage,\n debuggerOverrides,\n}: {\n widgetId?: string;\n widgetVersion?: string;\n collectCoverage?: FunctionCoverageSettings;\n debuggerOverrides?: (ctx: {\n precookFunction: typeof precookFunction;\n cook: typeof cook;\n supply: typeof supply;\n }) => {\n LodashWithStaticFields?: Partial<typeof _>;\n ArrayConstructor?: typeof Array;\n ObjectWithStaticFields?: Partial<typeof Object>;\n };\n} = {}): StoryboardFunctionRegistry {\n const registeredFunctions = new Map<string, RuntimeStoryboardFunction>();\n\n const overrides = debuggerOverrides?.({\n precookFunction,\n cook,\n supply,\n });\n\n // Use `Proxy` with a frozen target, to make a readonly function registry.\n const storyboardFunctions = new Proxy(Object.freeze({}), {\n get(_target, key) {\n return getStoryboardFunction(key as string);\n },\n }) as ReadonlyStoryboardFunctions;\n\n let currentApp: PartialMicroApp | undefined;\n\n function registerStoryboardFunctions(\n functions: StoryboardFunction[],\n app?: PartialMicroApp\n ): void {\n if (app) {\n currentApp = app;\n }\n registeredFunctions.clear();\n if (Array.isArray(functions)) {\n for (const fn of functions) {\n let deps: Set<string> | string[] | undefined = fn.deps;\n if (deps == null) {\n deps = collectMemberUsageInFunction(fn, \"FN\", !!collectCoverage);\n (deps as Set<string>).delete(fn.name);\n }\n const hasPermissionsCheck =\n fn.perm ??\n collectMemberUsageInFunction(\n fn,\n \"PERMISSIONS\",\n !!collectCoverage\n ).has(\"check\");\n registeredFunctions.set(fn.name, {\n source: fn.source,\n typescript: fn.typescript,\n deps,\n hasPermissionsCheck,\n });\n }\n }\n }\n\n function getStoryboardFunction(name: string): Function | undefined {\n const fn = registeredFunctions.get(name);\n if (!fn) {\n return undefined;\n }\n if (fn.processed) {\n return fn.cooked;\n }\n let collector: FunctionCoverageCollector | undefined;\n if (collectCoverage) {\n collector = collectCoverage.createCollector(name);\n }\n const precooked = precookFunction(fn.source, {\n typescript: fn.typescript,\n hooks: collector && {\n beforeVisit: collector.beforeVisit,\n },\n cacheKey: fn,\n });\n const globalVariables = supply(\n precooked.attemptToVisitGlobals,\n getGeneralGlobals(precooked.attemptToVisitGlobals, {\n collectCoverage,\n widgetId,\n widgetVersion,\n app: currentApp,\n storyboardFunctions,\n isStoryboardFunction: true,\n }),\n !!collectCoverage\n );\n\n fn.cooked = cook(precooked.function, fn.source, {\n rules: {\n noVar: true,\n },\n globalVariables: overrides\n ? {\n ...globalVariables,\n ...(overrides?.LodashWithStaticFields &&\n precooked.attemptToVisitGlobals.has(\"_\")\n ? {\n _: {\n ...(globalVariables._ as typeof _),\n ...overrides.LodashWithStaticFields,\n },\n }\n : null),\n ...(overrides?.ArrayConstructor &&\n precooked.attemptToVisitGlobals.has(\"Array\")\n ? {\n Array: overrides.ArrayConstructor,\n }\n : null),\n ...(overrides?.ObjectWithStaticFields &&\n precooked.attemptToVisitGlobals.has(\"Object\")\n ? {\n Object: {\n ...(globalVariables.Object as typeof Object),\n ...overrides.ObjectWithStaticFields,\n },\n }\n : null),\n }\n : globalVariables,\n ArrayConstructor: overrides?.ArrayConstructor,\n hooks: collector && {\n beforeEvaluate: collector.beforeEvaluate,\n beforeCall: collector.beforeCall,\n beforeBranch: collector.beforeBranch,\n },\n debug: !!debuggerOverrides,\n }) as Function;\n fn.processed = true;\n return fn.cooked;\n }\n\n return {\n storyboardFunctions,\n registerStoryboardFunctions,\n updateStoryboardFunction(\n name: string,\n data: StoryboardFunctionPatch\n ): void {\n const newFn = {\n ...data,\n name,\n };\n const deps = collectMemberUsageInFunction(newFn, \"FN\", true);\n const hasPermissionsCheck = collectMemberUsageInFunction(\n newFn,\n \"PERMISSIONS\",\n true\n ).has(\"check\");\n registeredFunctions.set(name, {\n source: data.source,\n typescript: data.typescript,\n deps,\n hasPermissionsCheck,\n });\n },\n /**\n * Check whether listed functions attempt to call `PERMISSIONS.check()`,\n * includes in nested `FN.*()` calls.\n */\n checkPermissionsUsage(functionNames) {\n const checkedFunctions = new Set<string>();\n const hasPermissionsCheck = (name: string): boolean => {\n if (!checkedFunctions.has(name)) {\n checkedFunctions.add(name);\n const fn = registeredFunctions.get(name);\n return (\n !!fn &&\n (fn.hasPermissionsCheck || [...fn.deps].some(hasPermissionsCheck))\n );\n }\n return false;\n };\n return functionNames.some(hasPermissionsCheck);\n },\n clearGlobalExecutionContextStack() {\n __dev_only_clearGlobalExecutionContextStack();\n },\n getGlobalExecutionContextStack() {\n return __dev_only_getGlobalExecutionContextStack();\n },\n };\n}\n"],"mappings":"AACA,SACEA,IAAI,EACJC,eAAe,EAEfC,2CAA2C,EAC3CC,yCAAyC,QACpC,iBAAiB;AACxB,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,4BAA4B,QAAQ,6BAA6B;AAE1E,SAASC,iBAAiB,QAAQ,yCAAyC;;AAE3E;;AAGA;;AAMA;;AAsBA;;AAUA;;AAQA;;AAKA;;AAGA;AACA,OAAO,SAASC,iCAAiCA,CAAA,EAkBb;EAAA,IAlBc;IAChDC,QAAQ;IACRC,aAAa;IACbC,eAAe;IACfC;EAcF,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EACJ,MAAMG,mBAAmB,GAAG,IAAIC,GAAG,CAAoC,CAAC;EAExE,MAAMC,SAAS,GAAGN,iBAAiB,aAAjBA,iBAAiB,uBAAjBA,iBAAiB,CAAG;IACpCV,eAAe;IACfD,IAAI;IACJI;EACF,CAAC,CAAC;;EAEF;EACA,MAAMc,mBAAmB,GAAG,IAAIC,KAAK,CAACC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;IACvDC,GAAGA,CAACC,OAAO,EAAEC,GAAG,EAAE;MAChB,OAAOC,qBAAqB,CAACD,GAAa,CAAC;IAC7C;EACF,CAAC,CAAgC;EAEjC,IAAIE,UAAuC;EAE3C,SAASC,2BAA2BA,CAClCC,SAA+B,EAC/BC,GAAqB,EACf;IACN,IAAIA,GAAG,E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UAC1B,MAAMJ,EAAE,GAAGlB,mBAAmB,CAACO,GAAG,CAACe,IAAI,CAAC;UACxC,OACE,CAAC,CAACJ,EAAE,KACHA,EAAE,CAACK,mBAAmB,IAAI,CAAC,GAAGL,EAAE,CAACE,IAAI,CAAC,CAACuC,IAAI,CAACpC,mBAAmB,CAAC,CAAC;QAEtE;QACA,OAAO,KAAK;MACd,CAAC;MACD,OAAOgC,aAAa,CAACI,IAAI,CAACpC,mBAAmB,CAAC;IAChD,CAAC;IACDqC,gCAAgCA,CAAA,EAAG;MACjCzE,2CAA2C,CAAC,CAAC;IAC/C,CAAC;IACD0E,8BAA8BA,CAAA,EAAG;MAC/B,OAAOzE,yCAAyC,CAAC,CAAC;IACpD;EACF,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"StoryboardFunctionRegistry.js","names":["cook","precookFunction","__dev_only_clearGlobalExecutionContextStack","__dev_only_getGlobalExecutionContextStack","supply","collectMemberUsageInFunction","hasOwnProperty","getGeneralGlobals","StoryboardFunctionRegistryFactory","widgetId","widgetVersion","collectCoverage","debuggerOverrides","arguments","length","undefined","registeredFunctions","Map","overrides","storyboardFunctions","Proxy","Object","freeze","get","_target","key","getStoryboardFunction","currentApp","registerStoryboardFunctions","functions","app","clear","Array","isArray","fn","_fn$perm","deps","delete","name","hasPermissionsCheck","perm","has","set","source","typescript","transformed","getGlobalVariables","globals","isStoryboardFunction","processed","cooked","collector","createCollector","globalVariables","Function","map","precooked","hooks","beforeVisit","cacheKey","attemptToVisitGlobals","function","rules","noVar","LodashWithStaticFields","_","ArrayConstructor","ObjectWithStaticFields","beforeEvaluate","beforeCall","beforeBranch","debug","updateStoryboardFunction","data","newFn","checkPermissionsUsage","functionNames","checkedFunctions","Set","add","some","clearGlobalExecutionContextStack","getGlobalExecutionContextStack"],"sources":["../../src/StoryboardFunctionRegistry.ts"],"sourcesContent":["import type {\n MicroApp,\n StoryboardFunction,\n TransformedFunction,\n} from \"@next-core/types\";\nimport {\n cook,\n precookFunction,\n EstreeNode,\n __dev_only_clearGlobalExecutionContextStack,\n __dev_only_getGlobalExecutionContextStack,\n} from \"@next-core/cook\";\nimport { supply } from \"@next-core/supply\";\nimport { collectMemberUsageInFunction } from \"@next-core/utils/storyboard\";\nimport { hasOwnProperty } from \"@next-core/utils/general\";\nimport type _ from \"lodash\";\nimport { getGeneralGlobals } from \"./internal/compute/getGeneralGlobals.js\";\n\n/** @internal */\nexport type ReadonlyStoryboardFunctions = Readonly<Record<string, Function>>;\n\n/** @internal */\nexport type StoryboardFunctionPatch = Pick<\n StoryboardFunction,\n \"source\" | \"typescript\" | \"transformed\"\n>;\n\n/** @internal */\nexport interface StoryboardFunctionRegistry {\n /** A readonly proxy for accessing cooked storyboard functions. */\n storyboardFunctions: ReadonlyStoryboardFunctions;\n\n /** Register storyboard functions. */\n registerStoryboardFunctions(\n functions: StoryboardFunction[] | undefined,\n app?: PartialMicroApp\n ): void;\n\n /** Update a storyboard function during debugging. */\n updateStoryboardFunction(name: string, data: StoryboardFunctionPatch): void;\n\n checkPermissionsUsage(functionNames: string[]): boolean;\n\n clearGlobalExecutionContextStack(): void;\n getGlobalExecutionContextStack(): ReturnType<\n typeof __dev_only_getGlobalExecutionContextStack\n >;\n}\n\n/** @internal */\nexport interface RuntimeStoryboardFunction {\n source: string;\n typescript?: boolean;\n processed?: boolean;\n cooked?: Function;\n deps: Set<string> | string[];\n hasPermissionsCheck: boolean;\n transformed?: TransformedFunction;\n}\n\n/** @internal */\nexport interface FunctionCoverageCollector {\n beforeVisit(node: EstreeNode): void;\n beforeEvaluate(node: EstreeNode): void;\n beforeCall(node: EstreeNode): void;\n beforeBranch(node: EstreeNode, branch: string): void;\n}\n\n/** @internal */\nexport interface FunctionCoverageSettings {\n createCollector(name: string): FunctionCoverageCollector;\n}\n\n/** @internal */\nexport type PartialMicroApp = Pick<MicroApp, \"id\" | \"isBuildPush\" | \"config\">;\n\n/** @internal */\nexport function StoryboardFunctionRegistryFactory({\n widgetId,\n widgetVersion,\n collectCoverage,\n debuggerOverrides,\n}: {\n widgetId?: string;\n widgetVersion?: string;\n collectCoverage?: FunctionCoverageSettings;\n debuggerOverrides?: (ctx: {\n precookFunction: typeof precookFunction;\n cook: typeof cook;\n supply: typeof supply;\n }) => {\n LodashWithStaticFields?: Partial<typeof _>;\n ArrayConstructor?: typeof Array;\n ObjectWithStaticFields?: Partial<typeof Object>;\n };\n} = {}): StoryboardFunctionRegistry {\n const registeredFunctions = new Map<string, RuntimeStoryboardFunction>();\n\n const overrides = debuggerOverrides?.({\n precookFunction,\n cook,\n supply,\n });\n\n // Use `Proxy` with a frozen target, to make a readonly function registry.\n const storyboardFunctions = new Proxy(Object.freeze({}), {\n get(_target, key) {\n return getStoryboardFunction(key as string);\n },\n }) as ReadonlyStoryboardFunctions;\n\n let currentApp: PartialMicroApp | undefined;\n\n function registerStoryboardFunctions(\n functions: StoryboardFunction[],\n app?: PartialMicroApp\n ): void {\n if (app) {\n currentApp = app;\n }\n registeredFunctions.clear();\n if (Array.isArray(functions)) {\n for (const fn of functions) {\n let deps: Set<string> | string[] | undefined = fn.deps;\n if (deps == null) {\n deps = collectMemberUsageInFunction(fn, \"FN\", !!collectCoverage);\n (deps as Set<string>).delete(fn.name);\n }\n const hasPermissionsCheck =\n fn.perm ??\n collectMemberUsageInFunction(\n fn,\n \"PERMISSIONS\",\n !!collectCoverage\n ).has(\"check\");\n registeredFunctions.set(fn.name, {\n source: fn.source,\n typescript: fn.typescript,\n transformed: fn.transformed,\n deps,\n hasPermissionsCheck,\n });\n }\n }\n }\n\n function getGlobalVariables(globals: Set<string> | string[]) {\n return supply(\n globals,\n getGeneralGlobals(globals, {\n collectCoverage,\n widgetId,\n widgetVersion,\n app: currentApp,\n storyboardFunctions,\n isStoryboardFunction: true,\n }),\n !!collectCoverage\n );\n }\n\n function getStoryboardFunction(name: string): Function | undefined {\n const fn = registeredFunctions.get(name);\n if (!fn) {\n return undefined;\n }\n if (fn.processed) {\n return fn.cooked;\n }\n let collector: FunctionCoverageCollector | undefined;\n if (collectCoverage) {\n collector = collectCoverage.createCollector(name);\n }\n\n // Do not use transformed functions when debugging.\n const transformed = !overrides && !collector && fn.transformed;\n if (transformed) {\n const globalVariables = getGlobalVariables(transformed.globals);\n // Spread globals as params to prevent accessing forbidden globals.\n // NOTE: in native mode, forbidden globals are declared as `undefined`,\n // thus accessing them will not throw a ReferenceError.\n fn.cooked = new Function(\n ...transformed.globals,\n `\"use strict\";return (${transformed.source})`\n )(\n ...transformed.globals.map((key) =>\n hasOwnProperty(globalVariables, key)\n ? globalVariables[key]\n : undefined\n )\n );\n } else {\n const precooked = precookFunction(fn.source, {\n typescript: fn.typescript,\n hooks: collector && {\n beforeVisit: collector.beforeVisit,\n },\n cacheKey: fn,\n });\n const globalVariables = getGlobalVariables(\n precooked.attemptToVisitGlobals\n );\n fn.cooked = cook(precooked.function, fn.source, {\n rules: {\n noVar: true,\n },\n globalVariables: overrides\n ? {\n ...globalVariables,\n ...(overrides?.LodashWithStaticFields &&\n precooked.attemptToVisitGlobals.has(\"_\")\n ? {\n _: {\n ...(globalVariables._ as typeof _),\n ...overrides.LodashWithStaticFields,\n },\n }\n : null),\n ...(overrides?.ArrayConstructor &&\n precooked.attemptToVisitGlobals.has(\"Array\")\n ? {\n Array: overrides.ArrayConstructor,\n }\n : null),\n ...(overrides?.ObjectWithStaticFields &&\n precooked.attemptToVisitGlobals.has(\"Object\")\n ? {\n Object: {\n ...(globalVariables.Object as typeof Object),\n ...overrides.ObjectWithStaticFields,\n },\n }\n : null),\n }\n : globalVariables,\n ArrayConstructor: overrides?.ArrayConstructor,\n hooks: collector && {\n beforeEvaluate: collector.beforeEvaluate,\n beforeCall: collector.beforeCall,\n beforeBranch: collector.beforeBranch,\n },\n debug: !!debuggerOverrides,\n }) as Function;\n }\n fn.processed = true;\n return fn.cooked;\n }\n\n return {\n storyboardFunctions,\n registerStoryboardFunctions,\n updateStoryboardFunction(\n name: string,\n data: StoryboardFunctionPatch\n ): void {\n const newFn = {\n ...data,\n name,\n };\n const deps = collectMemberUsageInFunction(newFn, \"FN\", true);\n const hasPermissionsCheck = collectMemberUsageInFunction(\n newFn,\n \"PERMISSIONS\",\n true\n ).has(\"check\");\n registeredFunctions.set(name, {\n source: data.source,\n typescript: data.typescript,\n transformed: data.transformed,\n deps,\n hasPermissionsCheck,\n });\n },\n /**\n * Check whether listed functions attempt to call `PERMISSIONS.check()`,\n * includes in nested `FN.*()` calls.\n */\n checkPermissionsUsage(functionNames) {\n const checkedFunctions = new Set<string>();\n const hasPermissionsCheck = (name: string): boolean => {\n if (!checkedFunctions.has(name)) {\n checkedFunctions.add(name);\n const fn = registeredFunctions.get(name);\n return (\n !!fn &&\n (fn.hasPermissionsCheck || [...fn.deps].some(hasPermissionsCheck))\n );\n }\n return false;\n };\n return functionNames.some(hasPermissionsCheck);\n },\n clearGlobalExecutionContextStack() {\n __dev_only_clearGlobalExecutionContextStack();\n },\n getGlobalExecutionContextStack() {\n return __dev_only_getGlobalExecutionContextStack();\n },\n };\n}\n"],"mappings":"AAKA,SACEA,IAAI,EACJC,eAAe,EAEfC,2CAA2C,EAC3CC,yCAAyC,QACpC,iBAAiB;AACxB,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,4BAA4B,QAAQ,6BAA6B;AAC1E,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,SAASC,iBAAiB,QAAQ,yCAAyC;;AAE3E;;AAGA;;AAMA;;AAsBA;;AAWA;;AAQA;;AAKA;;AAGA;AACA,OAAO,SAASC,iCAAiCA,CAAA,EAkBb;EAAA,IAlBc;IAChDC,QAAQ;IACRC,aAAa;IACbC,eAAe;IACfC;EAcF,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EACJ,MAAMG,mBAAmB,GAAG,IAAIC,GAAG,CAAoC,CAAC;EAExE,MAAMC,SAAS,GAAGN,iBAAiB,aAAjBA,iB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I,CAACzC,mBAAmB,CAAC,CAAC;QAEtE;QACA,OAAO,KAAK;MACd,CAAC;MACD,OAAOqC,aAAa,CAACI,IAAI,CAACzC,mBAAmB,CAAC;IAChD,CAAC;IACD0C,gCAAgCA,CAAA,EAAG;MACjC/E,2CAA2C,CAAC,CAAC;IAC/C,CAAC;IACDgF,8BAA8BA,CAAA,EAAG;MAC/B,OAAO/E,yCAAyC,CAAC,CAAC;IACpD;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -93,6 +93,10 @@ export async function renderRoutes(returnNode, routes, _runtimeContext, renderer
|
|
|
93
93
|
if (!isIncremental) {
|
|
94
94
|
rendererContext.memoizeMenuRequestNode(routes, menuRequestNode);
|
|
95
95
|
}
|
|
96
|
+
const usedProcessors = strictCollectMemberUsage(route.context, "PROCESSORS", 2);
|
|
97
|
+
if (usedProcessors.size > 0) {
|
|
98
|
+
output.blockingList.push(catchLoad(loadProcessorsImperatively(usedProcessors, getBrickPackages()), "processors", [...usedProcessors].join(", "), rendererContext.unknownBricks));
|
|
99
|
+
}
|
|
96
100
|
let newOutput;
|
|
97
101
|
if (route.type === "routes") {
|
|
98
102
|
newOutput = await renderRoutes(returnNode, route.routes, runtimeContext, rendererContext, routePath, menuRequestNode, slotId, undefined, initialTracker);
|