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.
Files changed (61) hide show
  1. package/DX/installForwarding.js +1 -1
  2. package/DX/installForwarding.ts +1 -1
  3. package/README.md +2 -0
  4. package/assignFeatures.js +10 -31
  5. package/assignFeatures.ts +15 -39
  6. package/assignFrom.js +18 -17
  7. package/assignFrom.ts +23 -23
  8. package/assignFromAsync.js +14 -13
  9. package/assignFromAsync.ts +15 -15
  10. package/assignGingerly.js +87 -48
  11. package/assignGingerly.ts +177 -131
  12. package/assignPermissions/PermissionProcessor.js +166 -0
  13. package/assignPermissions/PermissionProcessor.ts +210 -0
  14. package/assignPermissions/isAllowedImportPath.js +2 -6
  15. package/assignPermissions/isAllowedImportPath.ts +3 -5
  16. package/assignPermissions/isAllowedUrl.js +18 -0
  17. package/assignPermissions/isAllowedUrl.ts +15 -0
  18. package/assignTentatively.js +9 -11
  19. package/assignTentatively.ts +11 -13
  20. package/beVigilant.js +1 -1
  21. package/beVigilant.ts +1 -1
  22. package/buildCSSQuery.js +1 -1
  23. package/buildCSSQuery.ts +1 -1
  24. package/eachTime.js +5 -6
  25. package/eachTime.ts +12 -15
  26. package/enhanceAll.js +3 -3
  27. package/enhanceAll.ts +4 -4
  28. package/evaluatePathWithAsyncMethods.js +12 -8
  29. package/evaluatePathWithAsyncMethods.ts +129 -117
  30. package/handlers/addEventListener.js +11 -11
  31. package/handlers/addEventListener.ts +12 -13
  32. package/handlers/lazyLoad.ts +7 -7
  33. package/handlers/lazyLoadSwitch.ts +3 -3
  34. package/handlers/manageTemplateList.js +10 -10
  35. package/handlers/manageTemplateList.ts +12 -12
  36. package/handlers/rangeSelector.ts +3 -3
  37. package/index.js +2 -3
  38. package/index.ts +2 -3
  39. package/inferencer/types/assign-gingerly/types.d.ts +40 -9
  40. package/inferencer/types/el-maker/types.d.ts +33 -0
  41. package/inferencer/types/scratch-box/types.d.ts +3 -0
  42. package/inferencer/types/truth-sourcer/types.d.ts +4 -0
  43. package/inferencer/types/wc-info/SimpleWCInfo.d.ts +15 -0
  44. package/package.json +24 -23
  45. package/parseWithAttrs.js +1 -1
  46. package/parseWithAttrs.ts +1 -1
  47. package/processHandlerCommands.js +5 -7
  48. package/processHandlerCommands.ts +12 -15
  49. package/{getValues.js → resolve/getValues.js} +19 -8
  50. package/{getValues.ts → resolve/getValues.ts} +331 -314
  51. package/{resolveIdRef.js → resolve/resolveIdRef.js} +1 -1
  52. package/{resolveIdRef.ts → resolve/resolveIdRef.ts} +1 -1
  53. package/{resolveValues.ts → resolve/resolveValues.ts} +1 -1
  54. package/types/assign-gingerly/types.d.ts +40 -9
  55. package/assignPermissions/restrictedProps.js +0 -43
  56. package/assignPermissions/restrictedProps.ts +0 -53
  57. package/resolveAndAssignFeatures.js +0 -36
  58. package/resolveAndAssignFeatures.ts +0 -43
  59. /package/{resolveTemplate.js → resolve/resolveTemplate.js} +0 -0
  60. /package/{resolveTemplate.ts → resolve/resolveTemplate.ts} +0 -0
  61. /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 { buildRestrictedPropSet, redirectRestrictedProp } from './assignPermissions/restrictedProps.js';
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
- permissions?: AssignPermissions
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, permissions);
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(restrictedPropSet, lhsParent, lhsKey, result)) {
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 && withMethods.has(part)) {
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.has(nextPart))) {
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
- return navigatePath(source, parts, withMethods);
287
+ const permissionProcessor = options?.permissionProcessor;
288
+ return navigatePath(source, parts, withMethods, permissionProcessor);
278
289
  }