assign-gingerly 0.0.75 → 0.0.77
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/DX/installForwarding.js +1 -1
- package/DX/installForwarding.ts +1 -1
- package/README.md +2 -0
- package/assignFeatures.js +10 -31
- package/assignFeatures.ts +15 -39
- package/assignFrom.js +18 -17
- package/assignFrom.ts +23 -23
- package/assignFromAsync.js +14 -13
- package/assignFromAsync.ts +15 -15
- package/assignGingerly.js +87 -48
- package/assignGingerly.ts +177 -131
- package/assignPermissions/PermissionProcessor.js +166 -0
- package/assignPermissions/PermissionProcessor.ts +210 -0
- package/assignPermissions/isAllowedImportPath.js +2 -6
- package/assignPermissions/isAllowedImportPath.ts +3 -5
- package/assignPermissions/isAllowedUrl.js +18 -0
- package/assignPermissions/isAllowedUrl.ts +15 -0
- package/assignTentatively.js +9 -11
- package/assignTentatively.ts +11 -13
- package/beVigilant.js +1 -1
- package/beVigilant.ts +1 -1
- package/buildCSSQuery.js +1 -1
- package/buildCSSQuery.ts +1 -1
- package/eachTime.js +5 -6
- package/eachTime.ts +12 -15
- package/enhanceAll.js +3 -3
- package/enhanceAll.ts +4 -4
- package/evaluatePathWithAsyncMethods.js +12 -8
- package/evaluatePathWithAsyncMethods.ts +129 -117
- package/handlers/addEventListener.js +11 -11
- package/handlers/addEventListener.ts +12 -13
- package/handlers/lazyLoad.ts +7 -7
- package/handlers/lazyLoadSwitch.ts +3 -3
- package/handlers/manageTemplateList.js +10 -10
- package/handlers/manageTemplateList.ts +12 -12
- package/handlers/rangeSelector.ts +3 -3
- package/index.js +2 -3
- package/index.ts +2 -3
- package/inferencer/types/assign-gingerly/types.d.ts +40 -9
- package/inferencer/types/el-maker/types.d.ts +33 -0
- package/inferencer/types/scratch-box/types.d.ts +3 -0
- package/inferencer/types/truth-sourcer/types.d.ts +4 -0
- package/inferencer/types/wc-info/SimpleWCInfo.d.ts +15 -0
- package/package.json +24 -23
- package/parseWithAttrs.js +1 -1
- package/parseWithAttrs.ts +1 -1
- package/processHandlerCommands.js +5 -7
- package/processHandlerCommands.ts +12 -15
- package/{getValues.js → resolve/getValues.js} +19 -8
- package/{getValues.ts → resolve/getValues.ts} +331 -314
- package/{resolveIdRef.js → resolve/resolveIdRef.js} +1 -1
- package/{resolveIdRef.ts → resolve/resolveIdRef.ts} +1 -1
- package/{resolveValues.ts → resolve/resolveValues.ts} +1 -1
- package/types/assign-gingerly/types.d.ts +40 -9
- package/assignPermissions/restrictedProps.js +0 -43
- package/assignPermissions/restrictedProps.ts +0 -53
- package/resolveAndAssignFeatures.js +0 -36
- package/resolveAndAssignFeatures.ts +0 -43
- /package/{resolveTemplate.js → resolve/resolveTemplate.js} +0 -0
- /package/{resolveTemplate.ts → resolve/resolveTemplate.ts} +0 -0
- /package/{resolveValues.js → resolve/resolveValues.js} +0 -0
|
@@ -4,12 +4,11 @@
|
|
|
4
4
|
* Dynamically imported only when ` =>` keys are detected in the pattern.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { resolveValues } from './resolveValues.js';
|
|
8
|
-
import { getValues } from './getValues.js';
|
|
7
|
+
import { resolveValues } from './resolve/resolveValues.js';
|
|
8
|
+
import { getValues } from './resolve/getValues.js';
|
|
9
9
|
import { evaluatePathWithMethods } from './assignGingerly.js';
|
|
10
|
-
import { findClassPrototypeInPath } from './utils/findClassPrototypeInPath.js';
|
|
11
|
-
import {
|
|
12
|
-
import type { AssignPermissions } from './types/assign-gingerly/types.js';
|
|
10
|
+
import { findClassPrototypeInPath } from './utils/findClassPrototypeInPath.js';
|
|
11
|
+
import type { PermissionProcessor } from './types/assign-gingerly/types.js';
|
|
13
12
|
import type { AssignFromOptions, AssignFromHandlerConstructor } from './assignFromAsync.js';
|
|
14
13
|
|
|
15
14
|
/**
|
|
@@ -98,10 +97,8 @@ export async function processHandlerCommands(
|
|
|
98
97
|
handlerKeys: string[],
|
|
99
98
|
pattern: Record<string, any>,
|
|
100
99
|
options: AssignFromOptions,
|
|
101
|
-
|
|
102
|
-
): Promise<void> {
|
|
103
|
-
const restrictedPropSet = buildRestrictedPropSet(permissions);
|
|
104
|
-
|
|
100
|
+
permissionProcessor?: PermissionProcessor
|
|
101
|
+
): Promise<void> {
|
|
105
102
|
for (const key of handlerKeys) {
|
|
106
103
|
const lhsPath = key.substring(0, key.length - 3); // Remove ' =>'
|
|
107
104
|
const rhs = pattern[key];
|
|
@@ -213,13 +210,13 @@ export async function processHandlerCommands(
|
|
|
213
210
|
// Instantiate and invoke the handler
|
|
214
211
|
const handler = new HandlerClass(config);
|
|
215
212
|
//return; //1.5ms
|
|
216
|
-
const result = await handler.assign(lhsTarget, resolvedParams, options,
|
|
213
|
+
const result = await handler.assign(lhsTarget, resolvedParams, options, permissionProcessor);
|
|
217
214
|
//return; //1.5ms
|
|
218
|
-
// Return-value protocol: if handler returns a non-undefined value,
|
|
219
|
-
// assign it back to the LHS path
|
|
220
|
-
if (result !== undefined && lhsParent != null && lhsKey != null
|
|
221
|
-
&& !redirectRestrictedProp(
|
|
222
|
-
lhsParent[lhsKey] = result;
|
|
215
|
+
// Return-value protocol: if handler returns a non-undefined value,
|
|
216
|
+
// assign it back to the LHS path
|
|
217
|
+
if (result !== undefined && lhsParent != null && lhsKey != null
|
|
218
|
+
&& !permissionProcessor?.redirectRestrictedProp(lhsParent, lhsKey, result)) {
|
|
219
|
+
lhsParent[lhsKey] = result;
|
|
223
220
|
}
|
|
224
221
|
}
|
|
225
222
|
}
|
|
@@ -48,6 +48,14 @@ export function normalizeAliasOptions(options) {
|
|
|
48
48
|
}
|
|
49
49
|
return { aliasMap, withMethods };
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Check whether a method name is listed in withMethods and is not restricted
|
|
53
|
+
* by the permission processor. Restricted methods are treated as non-method
|
|
54
|
+
* property names so they fall through to normal access.
|
|
55
|
+
*/
|
|
56
|
+
function isAllowedMethod(methodName, withMethods, permissionProcessor) {
|
|
57
|
+
return !!withMethods && withMethods.has(methodName) && !permissionProcessor?.checkRestrictedMethod(methodName);
|
|
58
|
+
}
|
|
51
59
|
/**
|
|
52
60
|
* Apply alias substitutions to a path string.
|
|
53
61
|
* Replaces complete tokens between `?.` delimiters with their aliased values.
|
|
@@ -90,18 +98,18 @@ function parseCachedPath(path) {
|
|
|
90
98
|
* Navigate a path against a source object, optionally calling methods.
|
|
91
99
|
* Returns the resolved value at the end of the path.
|
|
92
100
|
*/
|
|
93
|
-
function navigatePath(source, parts, withMethods) {
|
|
101
|
+
function navigatePath(source, parts, withMethods, permissionProcessor) {
|
|
94
102
|
let current = source;
|
|
95
103
|
let i = 0;
|
|
96
104
|
while (i < parts.length) {
|
|
97
105
|
if (current == null)
|
|
98
106
|
return current;
|
|
99
107
|
const part = parts[i];
|
|
100
|
-
if (withMethods
|
|
108
|
+
if (isAllowedMethod(part, withMethods, permissionProcessor)) {
|
|
101
109
|
const method = current[part];
|
|
102
110
|
if (typeof method === 'function') {
|
|
103
111
|
const nextPart = parts[i + 1];
|
|
104
|
-
if (nextPart !== undefined && !(withMethods
|
|
112
|
+
if (nextPart !== undefined && !isAllowedMethod(nextPart, withMethods, permissionProcessor)) {
|
|
105
113
|
current = method.call(current, nextPart);
|
|
106
114
|
i += 2;
|
|
107
115
|
}
|
|
@@ -152,12 +160,13 @@ function getProtocolValue(value, protocols, options) {
|
|
|
152
160
|
* Recurses into nested arrays and plain objects.
|
|
153
161
|
*/
|
|
154
162
|
function getArray(arr, source, aliasMap, withMethods, protocols, options) {
|
|
163
|
+
const permissionProcessor = options?.permissionProcessor;
|
|
155
164
|
const result = [];
|
|
156
165
|
for (const item of arr) {
|
|
157
166
|
if (typeof item === 'string' && item.startsWith('?.')) {
|
|
158
167
|
const aliased = applyAliases(item, aliasMap);
|
|
159
168
|
const parts = parseCachedPath(aliased);
|
|
160
|
-
result.push(parts.length === 0 ? source : navigatePath(source, parts, withMethods));
|
|
169
|
+
result.push(parts.length === 0 ? source : navigatePath(source, parts, withMethods, permissionProcessor));
|
|
161
170
|
}
|
|
162
171
|
else if (typeof item === 'string' && item.startsWith('$0')) {
|
|
163
172
|
const rootRef = resolveRootReference(item, source, options?.root);
|
|
@@ -168,7 +177,7 @@ function getArray(arr, source, aliasMap, withMethods, protocols, options) {
|
|
|
168
177
|
const aliased = applyAliases(rootRef.path, aliasMap);
|
|
169
178
|
const normalizedPath = aliased.startsWith('?.') ? aliased : (aliased ? `?.${aliased}` : '?.');
|
|
170
179
|
const parts = parseCachedPath(normalizedPath);
|
|
171
|
-
result.push(parts.length === 0 ? rootRef.source : navigatePath(rootRef.source, parts, withMethods));
|
|
180
|
+
result.push(parts.length === 0 ? rootRef.source : navigatePath(rootRef.source, parts, withMethods, permissionProcessor));
|
|
172
181
|
}
|
|
173
182
|
}
|
|
174
183
|
else if (typeof item === 'string' && protocols && hasProtocol(item)) {
|
|
@@ -207,12 +216,13 @@ function getArray(arr, source, aliasMap, withMethods, protocols, options) {
|
|
|
207
216
|
export function getValues(pattern, source, options) {
|
|
208
217
|
const { aliasMap, withMethods } = normalizeAliasOptions(options);
|
|
209
218
|
const protocols = options?.protocols;
|
|
219
|
+
const permissionProcessor = options?.permissionProcessor;
|
|
210
220
|
const result = {};
|
|
211
221
|
for (const [key, value] of Object.entries(pattern)) {
|
|
212
222
|
if (typeof value === 'string' && value.startsWith('?.')) {
|
|
213
223
|
const aliased = applyAliases(value, aliasMap);
|
|
214
224
|
const parts = parseCachedPath(aliased);
|
|
215
|
-
result[key] = parts.length === 0 ? source : navigatePath(source, parts, withMethods);
|
|
225
|
+
result[key] = parts.length === 0 ? source : navigatePath(source, parts, withMethods, permissionProcessor);
|
|
216
226
|
}
|
|
217
227
|
else if (typeof value === 'string' && value.startsWith('$0')) {
|
|
218
228
|
const rootRef = resolveRootReference(value, source, options?.root);
|
|
@@ -223,7 +233,7 @@ export function getValues(pattern, source, options) {
|
|
|
223
233
|
const aliased = applyAliases(rootRef.path, aliasMap);
|
|
224
234
|
const normalizedPath = aliased.startsWith('?.') ? aliased : (aliased ? `?.${aliased}` : '?.');
|
|
225
235
|
const parts = parseCachedPath(normalizedPath);
|
|
226
|
-
result[key] = parts.length === 0 ? rootRef.source : navigatePath(rootRef.source, parts, withMethods);
|
|
236
|
+
result[key] = parts.length === 0 ? rootRef.source : navigatePath(rootRef.source, parts, withMethods, permissionProcessor);
|
|
227
237
|
}
|
|
228
238
|
}
|
|
229
239
|
else if (typeof value === 'string' && protocols && hasProtocol(value)) {
|
|
@@ -274,5 +284,6 @@ export function getValue(path, source, options) {
|
|
|
274
284
|
if (parts.length === 0)
|
|
275
285
|
return source;
|
|
276
286
|
const { withMethods } = normalizeAliasOptions(options);
|
|
277
|
-
|
|
287
|
+
const permissionProcessor = options?.permissionProcessor;
|
|
288
|
+
return navigatePath(source, parts, withMethods, permissionProcessor);
|
|
278
289
|
}
|