@nocobase/flow-engine 2.2.0-beta.1 → 2.2.0-beta.11
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/lib/JSRunner.d.ts +1 -0
- package/lib/JSRunner.js +110 -20
- package/lib/components/FieldModelRenderer.js +44 -31
- package/lib/components/MobilePopup.js +28 -10
- package/lib/components/MobilePopup.style.js +27 -6
- package/lib/components/dnd/index.js +9 -2
- package/lib/components/settings/wrappers/contextual/FlowsFloatContextMenu.js +86 -32
- package/lib/components/settings/wrappers/contextual/useFloatToolbarVisibility.js +20 -0
- package/lib/flowContext.d.ts +1 -1
- package/lib/flowContext.js +97 -42
- package/lib/flowEngine.js +6 -0
- package/lib/flowSettings.d.ts +5 -1
- package/lib/flowSettings.js +70 -0
- package/lib/locale/en-US.json +1 -0
- package/lib/locale/index.d.ts +2 -0
- package/lib/locale/zh-CN.json +1 -0
- package/lib/resources/apiResource.js +2 -1
- package/lib/resources/baseRecordResource.js +6 -17
- package/lib/resources/multiRecordResource.js +13 -3
- package/lib/resources/singleRecordResource.js +7 -2
- package/lib/runjs-context/helpers.js +12 -5
- package/lib/types.d.ts +12 -0
- package/lib/utils/dataSourceDirty.d.ts +20 -0
- package/lib/utils/dataSourceDirty.js +139 -0
- package/lib/utils/dirtyAwareApiClient.d.ts +11 -0
- package/lib/utils/dirtyAwareApiClient.js +632 -0
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +11 -11
- package/lib/utils/loadedPageCache.d.ts +1 -0
- package/lib/utils/loadedPageCache.js +6 -0
- package/lib/utils/openViewRouteState.d.ts +28 -0
- package/lib/utils/openViewRouteState.js +125 -0
- package/lib/utils/parsePathnameToViewParams.d.ts +3 -0
- package/lib/utils/parsePathnameToViewParams.js +18 -1
- package/lib/utils/resolveRunJSObjectValues.js +3 -2
- package/lib/utils/runjsModuleLoader.js +0 -30
- package/lib/views/ViewNavigation.js +5 -0
- package/package.json +4 -4
- package/src/JSRunner.ts +112 -25
- package/src/__tests__/JSRunner.test.ts +4 -5
- package/src/__tests__/flowContext.test.ts +154 -0
- package/src/__tests__/flowEngine.dataSourceDirty.test.ts +51 -0
- package/src/__tests__/flowModel.openView.navigation.test.ts +28 -0
- package/src/__tests__/flowSettings.test.ts +72 -0
- package/src/__tests__/runjsRuntimeFeatures.test.ts +15 -2
- package/src/__tests__/viewScopedFlowEngine.test.ts +72 -6
- package/src/components/FieldModelRenderer.tsx +50 -36
- package/src/components/MobilePopup.style.ts +34 -7
- package/src/components/MobilePopup.tsx +30 -10
- package/src/components/__tests__/FieldModelRenderer.test.tsx +165 -0
- package/src/components/__tests__/MobilePopup.style.test.tsx +103 -0
- package/src/components/__tests__/MobilePopup.test.tsx +109 -0
- package/src/components/dnd/index.tsx +11 -2
- package/src/components/settings/wrappers/contextual/FlowsFloatContextMenu.tsx +105 -35
- package/src/components/settings/wrappers/contextual/__tests__/FlowsFloatContextMenu.test.tsx +381 -12
- package/src/components/settings/wrappers/contextual/useFloatToolbarVisibility.ts +28 -0
- package/src/flowContext.ts +104 -36
- package/src/flowEngine.ts +6 -0
- package/src/flowSettings.ts +85 -1
- package/src/locale/en-US.json +1 -0
- package/src/locale/zh-CN.json +1 -0
- package/src/resources/apiResource.ts +2 -1
- package/src/resources/baseRecordResource.ts +6 -23
- package/src/resources/multiRecordResource.ts +13 -3
- package/src/resources/singleRecordResource.ts +6 -1
- package/src/runjs-context/helpers.ts +12 -6
- package/src/types.ts +14 -0
- package/src/utils/__tests__/dirtyAwareApiClient.test.ts +713 -0
- package/src/utils/__tests__/openViewRouteState.test.ts +40 -0
- package/src/utils/__tests__/parsePathnameToViewParams.test.ts +36 -0
- package/src/utils/dataSourceDirty.ts +126 -0
- package/src/utils/dirtyAwareApiClient.ts +742 -0
- package/src/utils/index.ts +10 -9
- package/src/utils/loadedPageCache.ts +7 -0
- package/src/utils/openViewRouteState.ts +107 -0
- package/src/utils/parsePathnameToViewParams.ts +23 -1
- package/src/utils/resolveRunJSObjectValues.ts +5 -2
- package/src/utils/runjsModuleLoader.ts +0 -32
- package/src/views/ViewNavigation.ts +6 -1
- package/src/views/__tests__/ViewNavigation.test.ts +15 -0
- package/lib/utils/safeGlobals.d.ts +0 -28
- package/lib/utils/safeGlobals.js +0 -367
- package/src/utils/__tests__/runjsRequireAsyncAutoWhitelist.test.ts +0 -38
- package/src/utils/__tests__/safeGlobals.test.ts +0 -106
- package/src/utils/safeGlobals.ts +0 -406
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var dirtyAwareApiClient_exports = {};
|
|
29
|
+
__export(dirtyAwareApiClient_exports, {
|
|
30
|
+
SKIP_DATA_SOURCE_DIRTY: () => SKIP_DATA_SOURCE_DIRTY,
|
|
31
|
+
getDirtyAwareApiClient: () => getDirtyAwareApiClient
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(dirtyAwareApiClient_exports);
|
|
34
|
+
var import_sdk = require("@nocobase/sdk");
|
|
35
|
+
var import_dataSourceDirty = require("./dataSourceDirty");
|
|
36
|
+
const SKIP_DATA_SOURCE_DIRTY = "__nocobaseSkipDataSourceDirty";
|
|
37
|
+
const DIRTY_DISPATCH_TOKEN = Symbol("nocobaseDirtyDispatchToken");
|
|
38
|
+
const dirtyAwareApiClientCache = /* @__PURE__ */ new WeakMap();
|
|
39
|
+
const dirtyAwareApiClientProxies = /* @__PURE__ */ new WeakSet();
|
|
40
|
+
const MUTATING_RESOURCE_ACTIONS = [
|
|
41
|
+
"add",
|
|
42
|
+
"bulkdestroy",
|
|
43
|
+
"bulkupdate",
|
|
44
|
+
"create",
|
|
45
|
+
"delete",
|
|
46
|
+
"destroy",
|
|
47
|
+
"execute",
|
|
48
|
+
"firstorcreate",
|
|
49
|
+
"import",
|
|
50
|
+
"move",
|
|
51
|
+
"remove",
|
|
52
|
+
"save",
|
|
53
|
+
"saveastemplate",
|
|
54
|
+
"set",
|
|
55
|
+
"setfields",
|
|
56
|
+
"submit",
|
|
57
|
+
"update",
|
|
58
|
+
"updateorcreate",
|
|
59
|
+
"upsert"
|
|
60
|
+
];
|
|
61
|
+
function isApiClientLike(value) {
|
|
62
|
+
if (!value || typeof value !== "object") {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const candidate = value;
|
|
66
|
+
return typeof candidate.resource === "function" && typeof candidate.request === "function";
|
|
67
|
+
}
|
|
68
|
+
__name(isApiClientLike, "isApiClientLike");
|
|
69
|
+
function isMutatingResourceAction(actionName) {
|
|
70
|
+
const normalized = String(actionName || "").trim();
|
|
71
|
+
if (!normalized) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
const baseActionName = normalized.split("/")[0];
|
|
75
|
+
const lowerBaseActionName = baseActionName.toLowerCase();
|
|
76
|
+
return MUTATING_RESOURCE_ACTIONS.some((action) => {
|
|
77
|
+
if (lowerBaseActionName === action) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
if (!lowerBaseActionName.startsWith(action) || baseActionName.length <= action.length) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const nextChar = baseActionName[action.length];
|
|
84
|
+
return nextChar === "-" || nextChar === "_" || nextChar >= "A" && nextChar <= "Z";
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
__name(isMutatingResourceAction, "isMutatingResourceAction");
|
|
88
|
+
function getCurrentOrigin() {
|
|
89
|
+
var _a;
|
|
90
|
+
return typeof window === "undefined" ? void 0 : (_a = window.location) == null ? void 0 : _a.origin;
|
|
91
|
+
}
|
|
92
|
+
__name(getCurrentOrigin, "getCurrentOrigin");
|
|
93
|
+
function parseUrl(value, base) {
|
|
94
|
+
try {
|
|
95
|
+
return new URL(value, base);
|
|
96
|
+
} catch {
|
|
97
|
+
return void 0;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
__name(parseUrl, "parseUrl");
|
|
101
|
+
function stripSearchAndHash(path) {
|
|
102
|
+
const index = path.search(/[?#]/);
|
|
103
|
+
return index === -1 ? path : path.slice(0, index);
|
|
104
|
+
}
|
|
105
|
+
__name(stripSearchAndHash, "stripSearchAndHash");
|
|
106
|
+
function stripKnownApiPrefix(path) {
|
|
107
|
+
const cleanPath = stripSearchAndHash(path).trim();
|
|
108
|
+
if (!cleanPath) {
|
|
109
|
+
return void 0;
|
|
110
|
+
}
|
|
111
|
+
const normalizedPath = cleanPath.replace(/^\/+/, "");
|
|
112
|
+
if (!normalizedPath || normalizedPath === "api") {
|
|
113
|
+
return void 0;
|
|
114
|
+
}
|
|
115
|
+
if (normalizedPath.startsWith("api/")) {
|
|
116
|
+
return normalizedPath.slice("api/".length);
|
|
117
|
+
}
|
|
118
|
+
return normalizedPath;
|
|
119
|
+
}
|
|
120
|
+
__name(stripKnownApiPrefix, "stripKnownApiPrefix");
|
|
121
|
+
function normalizePathname(pathname) {
|
|
122
|
+
return pathname.endsWith("/") ? pathname : `${pathname}/`;
|
|
123
|
+
}
|
|
124
|
+
__name(normalizePathname, "normalizePathname");
|
|
125
|
+
function getAppApiUrl(app) {
|
|
126
|
+
if (!(app == null ? void 0 : app.getApiUrl)) {
|
|
127
|
+
return void 0;
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
return parseUrl(app.getApiUrl(), getCurrentOrigin());
|
|
131
|
+
} catch {
|
|
132
|
+
return void 0;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
__name(getAppApiUrl, "getAppApiUrl");
|
|
136
|
+
function stripConfiguredApiPrefix(path, apiPathname) {
|
|
137
|
+
const cleanPath = stripSearchAndHash(path).trim();
|
|
138
|
+
if (!cleanPath.startsWith("/")) {
|
|
139
|
+
return void 0;
|
|
140
|
+
}
|
|
141
|
+
const apiPath = normalizePathname(apiPathname);
|
|
142
|
+
const requestPath = normalizePathname(cleanPath);
|
|
143
|
+
if (!requestPath.startsWith(apiPath)) {
|
|
144
|
+
return void 0;
|
|
145
|
+
}
|
|
146
|
+
const apiPathWithoutTrailingSlash = apiPath.replace(/\/$/, "");
|
|
147
|
+
return cleanPath.slice(apiPathWithoutTrailingSlash.length).replace(/^\/+/, "") || void 0;
|
|
148
|
+
}
|
|
149
|
+
__name(stripConfiguredApiPrefix, "stripConfiguredApiPrefix");
|
|
150
|
+
function getDirtyResourcePathFromAbsoluteUrl(url, app) {
|
|
151
|
+
if (!["http:", "https:"].includes(url.protocol)) {
|
|
152
|
+
return void 0;
|
|
153
|
+
}
|
|
154
|
+
if (app == null ? void 0 : app.getApiUrl) {
|
|
155
|
+
const apiUrl = getAppApiUrl(app);
|
|
156
|
+
if (!apiUrl || url.origin !== apiUrl.origin) {
|
|
157
|
+
return void 0;
|
|
158
|
+
}
|
|
159
|
+
return stripConfiguredApiPrefix(url.pathname, apiUrl.pathname);
|
|
160
|
+
}
|
|
161
|
+
const currentOrigin = getCurrentOrigin();
|
|
162
|
+
if (!currentOrigin || url.origin !== currentOrigin) {
|
|
163
|
+
return void 0;
|
|
164
|
+
}
|
|
165
|
+
return stripKnownApiPrefix(url.pathname);
|
|
166
|
+
}
|
|
167
|
+
__name(getDirtyResourcePathFromAbsoluteUrl, "getDirtyResourcePathFromAbsoluteUrl");
|
|
168
|
+
function getDirtyResourcePathFromUrl(url, context) {
|
|
169
|
+
if (typeof url !== "string") {
|
|
170
|
+
return void 0;
|
|
171
|
+
}
|
|
172
|
+
const trimmedUrl = url.trim();
|
|
173
|
+
if (!trimmedUrl || trimmedUrl.startsWith("//")) {
|
|
174
|
+
return void 0;
|
|
175
|
+
}
|
|
176
|
+
if (/^https?:\/\//i.test(trimmedUrl)) {
|
|
177
|
+
const parsedUrl = parseUrl(trimmedUrl);
|
|
178
|
+
if (!parsedUrl) {
|
|
179
|
+
return void 0;
|
|
180
|
+
}
|
|
181
|
+
return getDirtyResourcePathFromAbsoluteUrl(parsedUrl, context.app);
|
|
182
|
+
}
|
|
183
|
+
const appApiUrl = getAppApiUrl(context.app);
|
|
184
|
+
const configuredResourcePath = appApiUrl ? stripConfiguredApiPrefix(trimmedUrl, appApiUrl.pathname) : void 0;
|
|
185
|
+
if (configuredResourcePath) {
|
|
186
|
+
return configuredResourcePath;
|
|
187
|
+
}
|
|
188
|
+
return stripKnownApiPrefix(trimmedUrl);
|
|
189
|
+
}
|
|
190
|
+
__name(getDirtyResourcePathFromUrl, "getDirtyResourcePathFromUrl");
|
|
191
|
+
function decodeResourcePathSegment(segment) {
|
|
192
|
+
try {
|
|
193
|
+
return decodeURIComponent(segment);
|
|
194
|
+
} catch {
|
|
195
|
+
return segment;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
__name(decodeResourcePathSegment, "decodeResourcePathSegment");
|
|
199
|
+
function getDataSourceKeyFromResourceOf(resourceOf) {
|
|
200
|
+
const dataSourceKey = String(resourceOf ?? "").trim();
|
|
201
|
+
return dataSourceKey || void 0;
|
|
202
|
+
}
|
|
203
|
+
__name(getDataSourceKeyFromResourceOf, "getDataSourceKeyFromResourceOf");
|
|
204
|
+
function parseResourceActionFromSegments(segments) {
|
|
205
|
+
const resourceSegments = [];
|
|
206
|
+
let actionName;
|
|
207
|
+
let actionSegmentIndex = -1;
|
|
208
|
+
for (let index = 0; index < segments.length; index += 2) {
|
|
209
|
+
const segment = segments[index];
|
|
210
|
+
const actionDelimiterIndex = segment.lastIndexOf(":");
|
|
211
|
+
const resourceSegment = actionDelimiterIndex === -1 ? segment : segment.slice(0, actionDelimiterIndex);
|
|
212
|
+
if (!resourceSegment) {
|
|
213
|
+
return void 0;
|
|
214
|
+
}
|
|
215
|
+
resourceSegments.push(decodeResourcePathSegment(resourceSegment));
|
|
216
|
+
if (actionDelimiterIndex !== -1) {
|
|
217
|
+
actionName = decodeResourcePathSegment(segment.slice(actionDelimiterIndex + 1)).trim();
|
|
218
|
+
actionSegmentIndex = index;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (!actionName || !resourceSegments.length) {
|
|
223
|
+
return void 0;
|
|
224
|
+
}
|
|
225
|
+
if (segments.length > actionSegmentIndex + 2) {
|
|
226
|
+
return void 0;
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
resourceName: resourceSegments.join("."),
|
|
230
|
+
actionName
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
__name(parseResourceActionFromSegments, "parseResourceActionFromSegments");
|
|
234
|
+
function parseDirtyResourceActionFromUrl(url, context) {
|
|
235
|
+
const resourcePath = getDirtyResourcePathFromUrl(url, context);
|
|
236
|
+
if (!resourcePath) {
|
|
237
|
+
return void 0;
|
|
238
|
+
}
|
|
239
|
+
const segments = stripSearchAndHash(resourcePath).split("/").filter(Boolean);
|
|
240
|
+
const firstSegment = decodeResourcePathSegment(segments[0] || "");
|
|
241
|
+
if (firstSegment === "dataSources" && segments.length >= 3) {
|
|
242
|
+
const dataSourceKey = getDataSourceKeyFromResourceOf(decodeResourcePathSegment(segments[1]));
|
|
243
|
+
const parsed = parseResourceActionFromSegments(segments.slice(2));
|
|
244
|
+
if (dataSourceKey && parsed) {
|
|
245
|
+
return {
|
|
246
|
+
...parsed,
|
|
247
|
+
dataSourceKey
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return parseResourceActionFromSegments(segments);
|
|
252
|
+
}
|
|
253
|
+
__name(parseDirtyResourceActionFromUrl, "parseDirtyResourceActionFromUrl");
|
|
254
|
+
function resolveDirtyResourceActionFromResource(resourceName, resourceOf, actionName, context) {
|
|
255
|
+
const normalizedResourceName = resourceName.trim();
|
|
256
|
+
const normalizedActionName = actionName.trim();
|
|
257
|
+
if (!normalizedResourceName || !normalizedActionName) {
|
|
258
|
+
return void 0;
|
|
259
|
+
}
|
|
260
|
+
if (normalizedResourceName.includes("/")) {
|
|
261
|
+
const parsed = parseDirtyResourceActionFromUrl(`${normalizedResourceName}:${normalizedActionName}`, context);
|
|
262
|
+
if (parsed) {
|
|
263
|
+
return parsed;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const dataSourcesPrefix = "dataSources.";
|
|
267
|
+
if (normalizedResourceName.startsWith(dataSourcesPrefix)) {
|
|
268
|
+
const dataSourceKey = getDataSourceKeyFromResourceOf(resourceOf);
|
|
269
|
+
const nestedResourceName = normalizedResourceName.slice(dataSourcesPrefix.length).trim();
|
|
270
|
+
if (dataSourceKey && nestedResourceName) {
|
|
271
|
+
return {
|
|
272
|
+
dataSourceKey,
|
|
273
|
+
resourceName: nestedResourceName,
|
|
274
|
+
actionName: normalizedActionName
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
resourceName: normalizedResourceName,
|
|
280
|
+
actionName: normalizedActionName
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
__name(resolveDirtyResourceActionFromResource, "resolveDirtyResourceActionFromResource");
|
|
284
|
+
function resolveDirtyResourceAction(options, context) {
|
|
285
|
+
const resourceName = typeof (options == null ? void 0 : options.resource) === "string" ? options.resource : void 0;
|
|
286
|
+
const actionName = typeof (options == null ? void 0 : options.action) === "string" ? options.action : void 0;
|
|
287
|
+
if (resourceName && actionName) {
|
|
288
|
+
return resolveDirtyResourceActionFromResource(resourceName, options.resourceOf, actionName, context);
|
|
289
|
+
}
|
|
290
|
+
return parseDirtyResourceActionFromUrl(options == null ? void 0 : options.url, context);
|
|
291
|
+
}
|
|
292
|
+
__name(resolveDirtyResourceAction, "resolveDirtyResourceAction");
|
|
293
|
+
function getDirtyResourceActionDispatchKey(dirtyResourceAction, headers) {
|
|
294
|
+
if (!dirtyResourceAction) {
|
|
295
|
+
return void 0;
|
|
296
|
+
}
|
|
297
|
+
return JSON.stringify([
|
|
298
|
+
dirtyResourceAction.dataSourceKey || (0, import_dataSourceDirty.getDataSourceKeyFromHeaders)(headers),
|
|
299
|
+
dirtyResourceAction.resourceName,
|
|
300
|
+
dirtyResourceAction.actionName
|
|
301
|
+
]);
|
|
302
|
+
}
|
|
303
|
+
__name(getDirtyResourceActionDispatchKey, "getDirtyResourceActionDispatchKey");
|
|
304
|
+
function getRequestDispatchKey(options, context) {
|
|
305
|
+
return getDirtyResourceActionDispatchKey(resolveDirtyResourceAction(options, context), options.headers);
|
|
306
|
+
}
|
|
307
|
+
__name(getRequestDispatchKey, "getRequestDispatchKey");
|
|
308
|
+
function getResourceDispatchKey(name, of, headers) {
|
|
309
|
+
const resourceName = String(name ?? "").trim();
|
|
310
|
+
if (!resourceName) {
|
|
311
|
+
return void 0;
|
|
312
|
+
}
|
|
313
|
+
return JSON.stringify([resourceName, String(of ?? ""), (0, import_dataSourceDirty.getDataSourceKeyFromHeaders)(headers)]);
|
|
314
|
+
}
|
|
315
|
+
__name(getResourceDispatchKey, "getResourceDispatchKey");
|
|
316
|
+
function getMatchingRequestToken(token, requestKey) {
|
|
317
|
+
if (!token || !requestKey || token.requestKey && token.requestKey !== requestKey) {
|
|
318
|
+
return void 0;
|
|
319
|
+
}
|
|
320
|
+
return token;
|
|
321
|
+
}
|
|
322
|
+
__name(getMatchingRequestToken, "getMatchingRequestToken");
|
|
323
|
+
function getMatchingResourceToken(token, resourceKey) {
|
|
324
|
+
if (!token || !resourceKey || token.resourceKey && token.resourceKey !== resourceKey) {
|
|
325
|
+
return void 0;
|
|
326
|
+
}
|
|
327
|
+
return token;
|
|
328
|
+
}
|
|
329
|
+
__name(getMatchingResourceToken, "getMatchingResourceToken");
|
|
330
|
+
function markResourceActionDataSourceDirty(context, dirtyResourceAction, headers) {
|
|
331
|
+
(0, import_dataSourceDirty.markDataSourceDirty)({
|
|
332
|
+
engine: context.engine,
|
|
333
|
+
dataSourceKey: dirtyResourceAction.dataSourceKey || (0, import_dataSourceDirty.getDataSourceKeyFromHeaders)(headers),
|
|
334
|
+
resourceName: dirtyResourceAction.resourceName,
|
|
335
|
+
includePreviousEngines: true
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
__name(markResourceActionDataSourceDirty, "markResourceActionDataSourceDirty");
|
|
339
|
+
function markResourceActionDataSourceDirtyOnce(token, context, dirtyResourceAction, headers) {
|
|
340
|
+
if (token.skip || token.marked || !dirtyResourceAction || !isMutatingResourceAction(dirtyResourceAction.actionName)) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
token.marked = true;
|
|
344
|
+
markResourceActionDataSourceDirty(context, dirtyResourceAction, headers);
|
|
345
|
+
}
|
|
346
|
+
__name(markResourceActionDataSourceDirtyOnce, "markResourceActionDataSourceDirtyOnce");
|
|
347
|
+
function isObjectRecord(value) {
|
|
348
|
+
return !!value && typeof value === "object";
|
|
349
|
+
}
|
|
350
|
+
__name(isObjectRecord, "isObjectRecord");
|
|
351
|
+
function createDirtyAwareResource(context, resource, resourceName, resourceOf, headers, requestTokenStack, parentToken) {
|
|
352
|
+
return new Proxy(resource, {
|
|
353
|
+
get(target, prop, receiver) {
|
|
354
|
+
const original = Reflect.get(target, prop, receiver);
|
|
355
|
+
if (typeof prop !== "string" || typeof original !== "function" || !isMutatingResourceAction(prop)) {
|
|
356
|
+
return original;
|
|
357
|
+
}
|
|
358
|
+
const action = original;
|
|
359
|
+
return async (...args) => {
|
|
360
|
+
const actionOptions = isObjectRecord(args[1]) ? args[1] : void 0;
|
|
361
|
+
const dirtyResourceAction = resolveDirtyResourceActionFromResource(resourceName, resourceOf, prop, context);
|
|
362
|
+
const requestKey = getDirtyResourceActionDispatchKey(dirtyResourceAction, headers);
|
|
363
|
+
const resourceKey = getResourceDispatchKey(resourceName, resourceOf, headers);
|
|
364
|
+
const inheritedToken = getMatchingRequestToken(
|
|
365
|
+
actionOptions == null ? void 0 : actionOptions[DIRTY_DISPATCH_TOKEN],
|
|
366
|
+
requestKey
|
|
367
|
+
) || getMatchingRequestToken(parentToken, requestKey);
|
|
368
|
+
const token = inheritedToken || { marked: false, skip: false };
|
|
369
|
+
const ownsToken = !inheritedToken;
|
|
370
|
+
token.requestKey ||= requestKey;
|
|
371
|
+
token.resourceKey ||= resourceKey;
|
|
372
|
+
if (actionOptions == null ? void 0 : actionOptions[SKIP_DATA_SOURCE_DIRTY]) {
|
|
373
|
+
token.skip = true;
|
|
374
|
+
}
|
|
375
|
+
const forwardedArgs = actionOptions || args[1] == null ? [
|
|
376
|
+
args[0],
|
|
377
|
+
{
|
|
378
|
+
...actionOptions,
|
|
379
|
+
[DIRTY_DISPATCH_TOKEN]: token
|
|
380
|
+
}
|
|
381
|
+
] : args;
|
|
382
|
+
let actionResult;
|
|
383
|
+
requestTokenStack.push({ key: requestKey, token });
|
|
384
|
+
try {
|
|
385
|
+
actionResult = Reflect.apply(action, receiver, forwardedArgs);
|
|
386
|
+
} finally {
|
|
387
|
+
requestTokenStack.pop();
|
|
388
|
+
}
|
|
389
|
+
const result = await actionResult;
|
|
390
|
+
if (ownsToken) {
|
|
391
|
+
markResourceActionDataSourceDirtyOnce(token, context, dirtyResourceAction, headers);
|
|
392
|
+
}
|
|
393
|
+
return result;
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
__name(createDirtyAwareResource, "createDirtyAwareResource");
|
|
399
|
+
function createDirtyAwareApiClient(api, context) {
|
|
400
|
+
const baseResource = api.resource;
|
|
401
|
+
const baseRequest = api.request;
|
|
402
|
+
const shouldUseResourceDispatchReceiver = baseResource === import_sdk.APIClient.prototype.resource;
|
|
403
|
+
const shouldUseRequestDispatchReceiver = baseRequest === import_sdk.APIClient.prototype.request;
|
|
404
|
+
const resourceTokenStack = [];
|
|
405
|
+
const requestTokenStack = [];
|
|
406
|
+
let hasResourceOverride = false;
|
|
407
|
+
let resourceOverride;
|
|
408
|
+
let hasRequestOverride = false;
|
|
409
|
+
let requestOverride;
|
|
410
|
+
const getCurrentResource = /* @__PURE__ */ __name(() => hasResourceOverride ? resourceOverride : resource, "getCurrentResource");
|
|
411
|
+
const getCurrentRequest = /* @__PURE__ */ __name(() => hasRequestOverride ? requestOverride : request, "getCurrentRequest");
|
|
412
|
+
const dispatchResource = /* @__PURE__ */ __name((token, args) => {
|
|
413
|
+
const resourceKey = getResourceDispatchKey(args[0], args[1], args[2]);
|
|
414
|
+
const activeToken = getMatchingResourceToken(token, resourceKey);
|
|
415
|
+
const shouldWrapActions = !!activeToken && hasResourceOverride;
|
|
416
|
+
if (activeToken) {
|
|
417
|
+
activeToken.resourceKey ||= resourceKey;
|
|
418
|
+
resourceTokenStack.push({ key: resourceKey, token: activeToken });
|
|
419
|
+
}
|
|
420
|
+
try {
|
|
421
|
+
const resourceInstance = Reflect.apply(getCurrentResource(), proxy, args);
|
|
422
|
+
if (!shouldWrapActions || !activeToken) {
|
|
423
|
+
return resourceInstance;
|
|
424
|
+
}
|
|
425
|
+
return new Proxy(resourceInstance, {
|
|
426
|
+
get(target, prop, receiver) {
|
|
427
|
+
const original = Reflect.get(target, prop, receiver);
|
|
428
|
+
if (typeof prop !== "string" || typeof original !== "function" || !isMutatingResourceAction(prop)) {
|
|
429
|
+
return original;
|
|
430
|
+
}
|
|
431
|
+
const action = original;
|
|
432
|
+
return (...actionArgs) => {
|
|
433
|
+
const actionOptions = isObjectRecord(actionArgs[1]) ? actionArgs[1] : void 0;
|
|
434
|
+
const forwardedArgs = actionOptions || actionArgs[1] == null ? [
|
|
435
|
+
actionArgs[0],
|
|
436
|
+
{
|
|
437
|
+
...actionOptions,
|
|
438
|
+
[DIRTY_DISPATCH_TOKEN]: activeToken
|
|
439
|
+
}
|
|
440
|
+
] : actionArgs;
|
|
441
|
+
resourceTokenStack.push({ key: resourceKey, token: activeToken });
|
|
442
|
+
requestTokenStack.push({ key: activeToken.requestKey, token: activeToken });
|
|
443
|
+
try {
|
|
444
|
+
return Reflect.apply(action, receiver, forwardedArgs);
|
|
445
|
+
} finally {
|
|
446
|
+
requestTokenStack.pop();
|
|
447
|
+
resourceTokenStack.pop();
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
} finally {
|
|
453
|
+
if (activeToken) {
|
|
454
|
+
resourceTokenStack.pop();
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}, "dispatchResource");
|
|
458
|
+
const createDispatchReceiver = /* @__PURE__ */ __name((token) => {
|
|
459
|
+
const receiver = Object.create(api);
|
|
460
|
+
Object.defineProperties(receiver, {
|
|
461
|
+
request: {
|
|
462
|
+
configurable: true,
|
|
463
|
+
value: /* @__PURE__ */ __name((config) => {
|
|
464
|
+
const options = config;
|
|
465
|
+
const requestKey = getRequestDispatchKey(options, context);
|
|
466
|
+
const stackFrame = requestTokenStack.at(-1);
|
|
467
|
+
const activeToken = getMatchingRequestToken(options == null ? void 0 : options[DIRTY_DISPATCH_TOKEN], requestKey) || (requestKey && (stackFrame == null ? void 0 : stackFrame.key) === requestKey ? stackFrame.token : void 0) || getMatchingRequestToken(token, requestKey);
|
|
468
|
+
const { [DIRTY_DISPATCH_TOKEN]: _dirtyDispatchToken, ...cleanOptions } = options;
|
|
469
|
+
const configWithToken = activeToken ? { ...cleanOptions, [DIRTY_DISPATCH_TOKEN]: activeToken } : cleanOptions;
|
|
470
|
+
if (activeToken) {
|
|
471
|
+
activeToken.requestKey ||= requestKey;
|
|
472
|
+
requestTokenStack.push({ key: requestKey, token: activeToken });
|
|
473
|
+
}
|
|
474
|
+
try {
|
|
475
|
+
return Reflect.apply(getCurrentRequest(), proxy, [configWithToken]);
|
|
476
|
+
} finally {
|
|
477
|
+
if (activeToken) {
|
|
478
|
+
requestTokenStack.pop();
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}, "value")
|
|
482
|
+
},
|
|
483
|
+
resource: {
|
|
484
|
+
configurable: true,
|
|
485
|
+
value: /* @__PURE__ */ __name((...args) => {
|
|
486
|
+
const resourceKey = getResourceDispatchKey(args[0], args[1], args[2]);
|
|
487
|
+
const stackFrame = resourceTokenStack.at(-1);
|
|
488
|
+
const activeToken = getMatchingResourceToken(token, resourceKey) || (resourceKey && (stackFrame == null ? void 0 : stackFrame.key) === resourceKey ? stackFrame.token : void 0);
|
|
489
|
+
return dispatchResource(activeToken, args);
|
|
490
|
+
}, "value")
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
return receiver;
|
|
494
|
+
}, "createDispatchReceiver");
|
|
495
|
+
const resource = /* @__PURE__ */ __name((name, of, headers, cancel) => {
|
|
496
|
+
const resourceKey = getResourceDispatchKey(name, of, headers);
|
|
497
|
+
const stackFrame = resourceTokenStack.at(-1);
|
|
498
|
+
const parentToken = resourceKey && (stackFrame == null ? void 0 : stackFrame.key) === resourceKey ? stackFrame.token : void 0;
|
|
499
|
+
const receiver = createDispatchReceiver(parentToken);
|
|
500
|
+
const resourceInstance = Reflect.apply(baseResource, shouldUseResourceDispatchReceiver ? receiver : api, [
|
|
501
|
+
name,
|
|
502
|
+
of,
|
|
503
|
+
headers,
|
|
504
|
+
cancel
|
|
505
|
+
]);
|
|
506
|
+
return createDirtyAwareResource(context, resourceInstance, name, of, headers, requestTokenStack, parentToken);
|
|
507
|
+
}, "resource");
|
|
508
|
+
const request = /* @__PURE__ */ __name((config) => {
|
|
509
|
+
const options = config;
|
|
510
|
+
const requestKey = getRequestDispatchKey(options, context);
|
|
511
|
+
const stackFrame = requestTokenStack.at(-1);
|
|
512
|
+
const inheritedToken = getMatchingRequestToken(options == null ? void 0 : options[DIRTY_DISPATCH_TOKEN], requestKey) || (requestKey && (stackFrame == null ? void 0 : stackFrame.key) === requestKey ? stackFrame.token : void 0);
|
|
513
|
+
const token = inheritedToken || { marked: false, skip: false };
|
|
514
|
+
const ownsToken = !inheritedToken;
|
|
515
|
+
token.requestKey ||= requestKey;
|
|
516
|
+
if (typeof options.resource === "string") {
|
|
517
|
+
token.resourceKey ||= getResourceDispatchKey(options.resource, options.resourceOf, options.headers);
|
|
518
|
+
}
|
|
519
|
+
const skipDataSourceDirty = options == null ? void 0 : options[SKIP_DATA_SOURCE_DIRTY];
|
|
520
|
+
if (skipDataSourceDirty) {
|
|
521
|
+
token.skip = true;
|
|
522
|
+
}
|
|
523
|
+
const dirtyResourceAction = resolveDirtyResourceAction(options, context);
|
|
524
|
+
const {
|
|
525
|
+
[DIRTY_DISPATCH_TOKEN]: _dirtyDispatchToken,
|
|
526
|
+
[SKIP_DATA_SOURCE_DIRTY]: _skipDataSourceDirty,
|
|
527
|
+
...cleanConfig
|
|
528
|
+
} = options;
|
|
529
|
+
const receiver = createDispatchReceiver(token);
|
|
530
|
+
return Reflect.apply(baseRequest, shouldUseRequestDispatchReceiver ? receiver : api, [cleanConfig]).then((result) => {
|
|
531
|
+
if (ownsToken) {
|
|
532
|
+
markResourceActionDataSourceDirtyOnce(token, context, dirtyResourceAction, options.headers);
|
|
533
|
+
}
|
|
534
|
+
return result;
|
|
535
|
+
});
|
|
536
|
+
}, "request");
|
|
537
|
+
const isLockedOwnProperty = /* @__PURE__ */ __name((target, prop) => {
|
|
538
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
|
539
|
+
return !!descriptor && !descriptor.configurable;
|
|
540
|
+
}, "isLockedOwnProperty");
|
|
541
|
+
const proxy = new Proxy(api, {
|
|
542
|
+
get(target, prop, receiver) {
|
|
543
|
+
if (prop === "resource") {
|
|
544
|
+
if (isLockedOwnProperty(target, prop)) {
|
|
545
|
+
return Reflect.get(target, prop, receiver);
|
|
546
|
+
}
|
|
547
|
+
return hasResourceOverride ? resourceOverride : resource;
|
|
548
|
+
}
|
|
549
|
+
if (prop === "request") {
|
|
550
|
+
if (isLockedOwnProperty(target, prop)) {
|
|
551
|
+
return Reflect.get(target, prop, receiver);
|
|
552
|
+
}
|
|
553
|
+
return hasRequestOverride ? requestOverride : request;
|
|
554
|
+
}
|
|
555
|
+
return Reflect.get(target, prop, receiver);
|
|
556
|
+
},
|
|
557
|
+
set(target, prop, value, receiver) {
|
|
558
|
+
if (prop === "resource") {
|
|
559
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
|
560
|
+
if (descriptor && (!descriptor.configurable || !Reflect.isExtensible(target))) {
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
563
|
+
hasResourceOverride = true;
|
|
564
|
+
resourceOverride = value;
|
|
565
|
+
return true;
|
|
566
|
+
}
|
|
567
|
+
if (prop === "request") {
|
|
568
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
|
569
|
+
if (descriptor && (!descriptor.configurable || !Reflect.isExtensible(target))) {
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
hasRequestOverride = true;
|
|
573
|
+
requestOverride = value;
|
|
574
|
+
return true;
|
|
575
|
+
}
|
|
576
|
+
return Reflect.set(target, prop, value, receiver);
|
|
577
|
+
},
|
|
578
|
+
deleteProperty(target, prop) {
|
|
579
|
+
if (prop !== "resource" && prop !== "request") {
|
|
580
|
+
return Reflect.deleteProperty(target, prop);
|
|
581
|
+
}
|
|
582
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
|
583
|
+
if (descriptor && (!descriptor.configurable || !Reflect.isExtensible(target))) {
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
if (prop === "resource") {
|
|
587
|
+
hasResourceOverride = false;
|
|
588
|
+
resourceOverride = void 0;
|
|
589
|
+
} else {
|
|
590
|
+
hasRequestOverride = false;
|
|
591
|
+
requestOverride = void 0;
|
|
592
|
+
}
|
|
593
|
+
return true;
|
|
594
|
+
},
|
|
595
|
+
defineProperty(target, prop, descriptor) {
|
|
596
|
+
if (prop === "resource" || prop === "request") {
|
|
597
|
+
return false;
|
|
598
|
+
}
|
|
599
|
+
return Reflect.defineProperty(target, prop, descriptor);
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
dirtyAwareApiClientProxies.add(proxy);
|
|
603
|
+
return proxy;
|
|
604
|
+
}
|
|
605
|
+
__name(createDirtyAwareApiClient, "createDirtyAwareApiClient");
|
|
606
|
+
function getDirtyAwareApiClient(value, context) {
|
|
607
|
+
if (!isApiClientLike(value)) {
|
|
608
|
+
return value;
|
|
609
|
+
}
|
|
610
|
+
if (dirtyAwareApiClientProxies.has(value)) {
|
|
611
|
+
return value;
|
|
612
|
+
}
|
|
613
|
+
const api = value;
|
|
614
|
+
let contextCache = dirtyAwareApiClientCache.get(api);
|
|
615
|
+
if (!contextCache) {
|
|
616
|
+
contextCache = /* @__PURE__ */ new WeakMap();
|
|
617
|
+
dirtyAwareApiClientCache.set(api, contextCache);
|
|
618
|
+
}
|
|
619
|
+
const cached = contextCache.get(context);
|
|
620
|
+
if (cached) {
|
|
621
|
+
return cached;
|
|
622
|
+
}
|
|
623
|
+
const wrapped = createDirtyAwareApiClient(value, context);
|
|
624
|
+
contextCache.set(context, wrapped);
|
|
625
|
+
return wrapped;
|
|
626
|
+
}
|
|
627
|
+
__name(getDirtyAwareApiClient, "getDirtyAwareApiClient");
|
|
628
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
629
|
+
0 && (module.exports = {
|
|
630
|
+
SKIP_DATA_SOURCE_DIRTY,
|
|
631
|
+
getDirtyAwareApiClient
|
|
632
|
+
});
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -20,8 +20,8 @@ export { buildRecordMeta, collectContextParamsForTemplate, createCurrentRecordMe
|
|
|
20
20
|
export { extractPropertyPath, formatPathToVariable, isVariableExpression } from './context';
|
|
21
21
|
export { clearAutoFlowError, getAutoFlowError, setAutoFlowError, type AutoFlowError } from './autoFlowError';
|
|
22
22
|
export { parsePathnameToViewParams, type ViewParam } from './parsePathnameToViewParams';
|
|
23
|
+
export { createOpenViewRouteState, decodeOpenViewRouteState, encodeOpenViewRouteState, isOpenViewRouteStateToken, RUNJS_OPEN_VIEW_ROUTE_STATE, type OpenViewRouteMode, type OpenViewRouteSize, type OpenViewRouteState, } from './openViewRouteState';
|
|
23
24
|
export { decodeBase64Url, encodeBase64Url, isCompleteCtxDatePath, isCtxDatePathPrefix, isCtxDateExpression, parseCtxDateExpression, resolveCtxDatePath, serializeCtxDateValue, } from './dateVariable';
|
|
24
|
-
export { createSafeDocument, createSafeWindow, createSafeNavigator, createSafeRunJSGlobals, runjsWithSafeGlobals, } from './safeGlobals';
|
|
25
25
|
export { isRunJSValue, normalizeRunJSValue, extractUsedVariablePathsFromRunJS, type RunJSValue } from './runjsValue';
|
|
26
26
|
export { resolveRunJSObjectValues } from './resolveRunJSObjectValues';
|
|
27
27
|
export { prepareRunJsCode, preprocessRunJsTemplates } from './runjsTemplateCompat';
|