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
@@ -78,7 +78,7 @@ export function resolveIdVariable(varName, target, pin) {
78
78
  // Fire-and-forget: log correction suggestion
79
79
  const capturedConfig = config;
80
80
  const capturedVarName = varName;
81
- import('./DX/pinCorrector.js').then(module => {
81
+ import('../DX/pinCorrector.js').then(module => {
82
82
  module.logConfigCorrection(target, capturedVarName, capturedConfig);
83
83
  }).catch(() => { });
84
84
  }
@@ -91,7 +91,7 @@ export function resolveIdVariable(
91
91
  // Fire-and-forget: log correction suggestion
92
92
  const capturedConfig = config;
93
93
  const capturedVarName = varName;
94
- import('./DX/pinCorrector.js').then(module => {
94
+ import('../DX/pinCorrector.js').then(module => {
95
95
  module.logConfigCorrection(target, capturedVarName, capturedConfig);
96
96
  }).catch(() => {});
97
97
  }
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  import { getValue, getValues } from './getValues.js';
11
- import type { ResolveValuesOptions } from './types/assign-gingerly/types.js';
11
+ import type { ResolveValuesOptions } from '../types/assign-gingerly/types.js';
12
12
 
13
13
  export type { ResolveValuesOptions };
14
14
 
@@ -424,6 +424,11 @@ export interface GetValuesOptions extends IAssignGingerlyOptions {
424
424
  */
425
425
  root?: any;
426
426
 
427
+ /**
428
+ * Optional permission processor for guarding method calls during RHS resolution.
429
+ */
430
+ permissionProcessor?: PermissionProcessor;
431
+
427
432
  /**
428
433
  * Synchronous protocol handlers for resolving protocol-prefixed values.
429
434
  * Each handler receives the key portion and MUST return synchronously.
@@ -449,6 +454,11 @@ export interface ResolveValuesOptions extends IAssignGingerlyOptions {
449
454
  */
450
455
  root?: any;
451
456
 
457
+ /**
458
+ * Optional permission processor for guarding method calls during RHS resolution.
459
+ */
460
+ permissionProcessor?: PermissionProcessor;
461
+
452
462
  /**
453
463
  * Protocol handlers for resolving protocol-prefixed values (e.g., 'globalThis://key').
454
464
  * Each handler receives the key portion and returns the resolved value (sync or async).
@@ -474,6 +484,8 @@ export declare class EnhancementRegistry extends EventTarget {
474
484
  getItems(): EnhancementConfig[];
475
485
  findBySymbol(symbol: symbol | string): EnhancementConfig | undefined;
476
486
  findByEnhKey(enhKey: string | symbol): EnhancementConfig | undefined;
487
+ whenDefined(enhKey: string | symbol): Promise<void>;
488
+ _trackSetup(name: string | symbol, promise: Promise<void>): void;
477
489
  }
478
490
 
479
491
  /**
@@ -642,7 +654,7 @@ export declare function assignFeatures(
642
654
  ctr: Function,
643
655
  features: FeatureConfigsMap,
644
656
  featuresRegistry: FeaturesRegistry
645
- ): Promise<void> | undefined;
657
+ ): Promise<void>;
646
658
 
647
659
  /**
648
660
  * Captures own-properties that shadow feature getters.
@@ -695,7 +707,7 @@ export interface HandlerConfig {
695
707
  * Handlers are invoked when a LHS key ends with ' =>'.
696
708
  */
697
709
  export interface AssignFromHandler {
698
- assign(lhsTarget: any, resolvedParams: Record<string, any>, options: any, permissions?: AssignPermissions): Promise<void> | void;
710
+ assign(lhsTarget: any, resolvedParams: Record<string, any>, options: any, permissionProcessor?: PermissionProcessor): Promise<void> | void;
699
711
  }
700
712
 
701
713
  /**
@@ -873,7 +885,7 @@ export interface LazyLoadInstantiatedContext {
873
885
  export declare class LazyLoadHandler implements AssignFromHandler {
874
886
  config: any;
875
887
  constructor(config: any);
876
- assign(lhsTarget: any, resolvedParams: Record<string, any>, options?: any, permissions?: AssignPermissions): Promise<void>;
888
+ assign(lhsTarget: any, resolvedParams: Record<string, any>, options?: any, permissionProcessor?: PermissionProcessor): Promise<void>;
877
889
  protected onCloneInserted(nodes: Node[], lhsTarget: Element, resolvedParams: Record<string, any>): Promise<void>;
878
890
  }
879
891
 
@@ -931,11 +943,11 @@ export interface AddEventListenerConfig extends AssignDispatchVector {
931
943
  * Phase II+: object form for a restricted property setting.
932
944
  */
933
945
  export interface RestrictedPropSetting {
934
- prop: string;
935
- useMethod?: string; // Phase II: redirect to a safe method
936
- attr?: string; // Phase III: also watch setAttribute for this attr
937
- allowFromSameHost?: boolean; // Phase III
938
- allowCrossDomain?: boolean; // Phase III
946
+ props: string | string[];
947
+ useMethod?: string; // Phase II: redirect to a safe method
948
+ attr?: boolean | string | string[]; // Phase III: also watch setAttribute for these attrs
949
+ allowFromSameDomain?: boolean; // Phase III: allow same-origin URLs
950
+ allowCrossDomain?: boolean; // Phase III: allow any URL
939
951
  }
940
952
 
941
953
  /**
@@ -958,7 +970,8 @@ export interface AssignPermissions {
958
970
  * Restricted property settings.
959
971
  * Phase I: string entries are property names that cannot be assigned.
960
972
  * Phase II: an object with useMethod redirects ordinary assignment to that
961
- * method; command operations remain blocked. Phase III+ adds attr support.
973
+ * method; command operations remain blocked. Phase III+ adds props, attr,
974
+ * allowFromSameDomain, and allowCrossDomain support.
962
975
  *
963
976
  * NOTE: This is a property-assignment guard only. Method calls (setAttribute, etc.)
964
977
  * are not blocked — see Phase III+. Event listeners can still be registered, but
@@ -972,3 +985,21 @@ export interface AssignPermissions {
972
985
  /** Restricted method settings (Phase IV+) */
973
986
  restrictedMethodSettings?: Array<string | RestrictedMethodConfig>;
974
987
  }
988
+
989
+ //#region Permissions
990
+ export interface RestrictedPropSettingsMap {
991
+ props: Map<string, RestrictedPropSetting | undefined>;
992
+ attrs: Map<string, RestrictedPropSetting | undefined>;
993
+ }
994
+
995
+ export declare class PermissionProcessor {
996
+ constructor(permissions: AssignPermissions | undefined);
997
+ get crossDomainImports(): boolean;
998
+ get hasProps(): boolean;
999
+ get hasAttrs(): boolean;
1000
+ checkRestrictedProp(key: string): boolean;
1001
+ checkRestrictedMethod(methodName: string): boolean;
1002
+ redirectRestrictedProp(target: any, key: string, value: any): boolean;
1003
+ checkRestrictedAttributeCall(methodName: string, args: any[]): { blocked: boolean; attrName?: string };
1004
+ }
1005
+ //#endregion
@@ -1,43 +0,0 @@
1
- const warnedOnce = new Set();
2
- function warnRestricted(key) {
3
- if (!warnedOnce.has(key)) {
4
- warnedOnce.add(key);
5
- console.warn(`assignGingerly: property '${key}' is in restrictedPropSettings — assignment skipped.`);
6
- }
7
- }
8
- export function buildRestrictedPropSet(permissions) {
9
- const settings = permissions?.restrictedPropSettings;
10
- if (!settings || settings.length === 0)
11
- return undefined;
12
- const restrictedPropSet = new Map();
13
- for (const setting of settings) {
14
- const prop = typeof setting === 'string' ? setting : setting.prop;
15
- if (restrictedPropSet.has(prop)) {
16
- throw new Error(`assignGingerly: duplicate restrictedPropSettings entry for '${prop}'.`);
17
- }
18
- restrictedPropSet.set(prop, typeof setting === 'string' ? undefined : setting);
19
- }
20
- return restrictedPropSet;
21
- }
22
- export function checkRestrictedProp(restrictedPropSet, key) {
23
- if (!restrictedPropSet || !restrictedPropSet.has(key))
24
- return false;
25
- warnRestricted(key);
26
- return true;
27
- }
28
- export function redirectRestrictedProp(restrictedPropSet, target, key, value) {
29
- if (!restrictedPropSet || !restrictedPropSet.has(key))
30
- return false;
31
- const setting = restrictedPropSet.get(key);
32
- if (!setting?.useMethod) {
33
- warnRestricted(key);
34
- return true;
35
- }
36
- const method = target?.[setting.useMethod];
37
- if (typeof method !== 'function') {
38
- warnRestricted(key);
39
- return true;
40
- }
41
- method.call(target, value);
42
- return true;
43
- }
@@ -1,53 +0,0 @@
1
- import type { AssignPermissions, RestrictedPropSetting } from '../types/assign-gingerly/types.js';
2
-
3
- export type RestrictedPropSettingsMap = Map<string, RestrictedPropSetting | undefined>;
4
-
5
- const warnedOnce = new Set<string>();
6
-
7
- function warnRestricted(key: string): void {
8
- if (!warnedOnce.has(key)) {
9
- warnedOnce.add(key);
10
- console.warn(`assignGingerly: property '${key}' is in restrictedPropSettings — assignment skipped.`);
11
- }
12
- }
13
-
14
- export function buildRestrictedPropSet(permissions: AssignPermissions | undefined): RestrictedPropSettingsMap | undefined {
15
- const settings = permissions?.restrictedPropSettings;
16
- if (!settings || settings.length === 0) return undefined;
17
- const restrictedPropSet: RestrictedPropSettingsMap = new Map();
18
- for (const setting of settings) {
19
- const prop = typeof setting === 'string' ? setting : setting.prop;
20
- if (restrictedPropSet.has(prop)) {
21
- throw new Error(`assignGingerly: duplicate restrictedPropSettings entry for '${prop}'.`);
22
- }
23
- restrictedPropSet.set(prop, typeof setting === 'string' ? undefined : setting);
24
- }
25
- return restrictedPropSet;
26
- }
27
-
28
- export function checkRestrictedProp(restrictedPropSet: RestrictedPropSettingsMap | undefined, key: string): boolean {
29
- if (!restrictedPropSet || !restrictedPropSet.has(key)) return false;
30
- warnRestricted(key);
31
- return true;
32
- }
33
-
34
- export function redirectRestrictedProp(
35
- restrictedPropSet: RestrictedPropSettingsMap | undefined,
36
- target: any,
37
- key: string,
38
- value: any
39
- ): boolean {
40
- if (!restrictedPropSet || !restrictedPropSet.has(key)) return false;
41
- const setting = restrictedPropSet.get(key);
42
- if (!setting?.useMethod) {
43
- warnRestricted(key);
44
- return true;
45
- }
46
- const method = target?.[setting.useMethod];
47
- if (typeof method !== 'function') {
48
- warnRestricted(key);
49
- return true;
50
- }
51
- method.call(target, value);
52
- return true;
53
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * resolveAndAssignFeatures - Thin wrapper around assignFeatures for backward compatibility.
3
- *
4
- * Resolves all configured spawns (including async fallback spawns and string import paths)
5
- * and installs feature getters on the class prototype, then delegates to the registry's
6
- * assignFeatures implementation.
7
- *
8
- * This is kept as a convenience entry point for callers that already await this function.
9
- * The actual resolution logic lives in assignFeatures.
10
- *
11
- * @example
12
- * import { resolveAndAssignFeatures } from 'assign-gingerly/resolveAndAssignFeatures.js';
13
- *
14
- * await resolveAndAssignFeatures(MyElement, {
15
- * roundabout: {
16
- * customData: {...},
17
- * withAttrs: {...},
18
- * callbackForwarding: ['connectedCallback']
19
- * },
20
- * faceUp: {
21
- * callbackForwarding: ['connectedCallback', 'disconnectedCallback']
22
- * }
23
- * });
24
- */
25
- import { assignFeatures } from './assignFeatures.js';
26
- /**
27
- * Resolves all configured spawns and calls assignFeatures on the registry.
28
- *
29
- * @param ElementClass - The custom element class (must have static supportedFeatures)
30
- * @param featuresConfig - Feature configurations (spawn will be resolved from fallbackSpawn if missing)
31
- * @param registry - Optional CustomElementRegistry (defaults to global customElements)
32
- */
33
- export async function resolveAndAssignFeatures(ElementClass, featuresConfig, registry) {
34
- const reg = registry || customElements;
35
- await assignFeatures(ElementClass, featuresConfig, reg.featuresRegistry);
36
- }
@@ -1,43 +0,0 @@
1
- /**
2
- * resolveAndAssignFeatures - Thin wrapper around assignFeatures for backward compatibility.
3
- *
4
- * Resolves all configured spawns (including async fallback spawns and string import paths)
5
- * and installs feature getters on the class prototype, then delegates to the registry's
6
- * assignFeatures implementation.
7
- *
8
- * This is kept as a convenience entry point for callers that already await this function.
9
- * The actual resolution logic lives in assignFeatures.
10
- *
11
- * @example
12
- * import { resolveAndAssignFeatures } from 'assign-gingerly/resolveAndAssignFeatures.js';
13
- *
14
- * await resolveAndAssignFeatures(MyElement, {
15
- * roundabout: {
16
- * customData: {...},
17
- * withAttrs: {...},
18
- * callbackForwarding: ['connectedCallback']
19
- * },
20
- * faceUp: {
21
- * callbackForwarding: ['connectedCallback', 'disconnectedCallback']
22
- * }
23
- * });
24
- */
25
-
26
- import { FeatureConfigsMap } from './types/assign-gingerly/types.js';
27
- import { assignFeatures } from './assignFeatures.js';
28
-
29
- /**
30
- * Resolves all configured spawns and calls assignFeatures on the registry.
31
- *
32
- * @param ElementClass - The custom element class (must have static supportedFeatures)
33
- * @param featuresConfig - Feature configurations (spawn will be resolved from fallbackSpawn if missing)
34
- * @param registry - Optional CustomElementRegistry (defaults to global customElements)
35
- */
36
- export async function resolveAndAssignFeatures(
37
- ElementClass: Function,
38
- featuresConfig: FeatureConfigsMap,
39
- registry?: any
40
- ): Promise<void> {
41
- const reg = registry || customElements;
42
- await assignFeatures(ElementClass, featuresConfig, reg.featuresRegistry);
43
- }
File without changes