@wix/zero-config-implementation 1.7.0 → 1.9.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.
Files changed (26) hide show
  1. package/dist/converters/data-item-builder.d.ts +4 -1
  2. package/dist/index.d.ts +5 -3
  3. package/dist/index.js +22432 -19408
  4. package/dist/information-extractors/react/extractors/core/index.d.ts +1 -1
  5. package/dist/information-extractors/react/extractors/core/runner.d.ts +5 -1
  6. package/dist/information-extractors/react/extractors/index.d.ts +1 -1
  7. package/dist/information-extractors/react/extractors/prop-tracker.d.ts +3 -6
  8. package/dist/information-extractors/react/index.d.ts +2 -3
  9. package/dist/information-extractors/react/types.d.ts +4 -17
  10. package/dist/information-extractors/react/utils/mock-generator.d.ts +13 -2
  11. package/dist/manifest-pipeline.d.ts +2 -2
  12. package/package.json +2 -2
  13. package/src/converters/data-item-builder.ts +120 -35
  14. package/src/converters/to-editor-component.ts +11 -6
  15. package/src/index.ts +5 -3
  16. package/src/information-extractors/react/extractors/core/index.ts +1 -1
  17. package/src/information-extractors/react/extractors/core/runner.ts +12 -7
  18. package/src/information-extractors/react/extractors/core/tree-builder.ts +3 -1
  19. package/src/information-extractors/react/extractors/index.ts +1 -0
  20. package/src/information-extractors/react/extractors/prop-tracker.ts +49 -28
  21. package/src/information-extractors/react/index.ts +1 -7
  22. package/src/information-extractors/react/types.ts +4 -20
  23. package/src/information-extractors/react/utils/mock-generator.ts +99 -31
  24. package/src/manifest-pipeline.ts +18 -12
  25. package/dist/information-extractors/react/utils/prop-spy.d.ts +0 -10
  26. package/src/information-extractors/react/utils/prop-spy.ts +0 -168
@@ -1,168 +0,0 @@
1
- import type { PropSpy, PropSpyMeta, TrackingStores } from '../types'
2
- import { PROP_SPY_SYMBOL } from '../types'
3
-
4
- // ─────────────────────────────────────────────────────────────────────────────
5
- // Types
6
- // ─────────────────────────────────────────────────────────────────────────────
7
-
8
- export interface PropSpyContext {
9
- createAuditedProps: <T extends object | null>(
10
- target: T,
11
- stores: TrackingStores,
12
- getComponent: () => string,
13
- basePath?: string,
14
- ) => T
15
- getSpyMetadataByUniqueId: (id: string) => PropSpyMeta | null
16
- }
17
-
18
- // ─────────────────────────────────────────────────────────────────────────────
19
- // Factory
20
- // ─────────────────────────────────────────────────────────────────────────────
21
-
22
- /**
23
- * Creates an encapsulated prop spy context.
24
- * Each context has its own ID counter and metadata map, avoiding global state.
25
- */
26
- export function createPropSpyContext(): PropSpyContext {
27
- let idCounter = 0
28
- const metadataMap = new Map<string, PropSpyMeta>()
29
-
30
- // ─────────────────────────────────────────────────────────────────────────────
31
- // Helpers
32
- // ─────────────────────────────────────────────────────────────────────────────
33
-
34
- const isPropSpy = (val: unknown): val is PropSpy => !!(val && typeof val === 'object' && PROP_SPY_SYMBOL in val)
35
-
36
- const isReactInternal = (val: unknown): boolean => {
37
- if (!val || typeof val !== 'object') return false
38
- const obj = val as Record<string, unknown>
39
- return !!(obj.$$typeof || obj._owner || obj._store || (obj.prototype as Record<string, unknown>)?.isReactComponent)
40
- }
41
-
42
- const logRead = (stores: TrackingStores, path: string, component: string, value: unknown) => {
43
- const record = stores.reads.get(path) ?? { components: new Set(), value }
44
- record.components.add(component)
45
- stores.reads.set(path, record)
46
- }
47
-
48
- const createMeta = (
49
- path: string,
50
- propName: string,
51
- originalValue: unknown,
52
- ): { meta: PropSpyMeta; uniqueId: string } => {
53
- const uniqueId = `__spy_${++idCounter}__`
54
- const meta = { path, propName, uniqueId, originalValue }
55
- return { meta, uniqueId }
56
- }
57
-
58
- // ─────────────────────────────────────────────────────────────────────────────
59
- // Primitive Wrapping
60
- // ─────────────────────────────────────────────────────────────────────────────
61
-
62
- const wrapPrimitiveOrFunction = (
63
- value: string | number | boolean | ((...args: unknown[]) => unknown),
64
- path: string,
65
- propName: string,
66
- stores: TrackingStores,
67
- getComponent: () => string,
68
- ) => {
69
- // Functions: Wrap to log execution
70
- if (typeof value === 'function') {
71
- const spy = function (this: unknown, ...args: unknown[]) {
72
- logRead(stores, path, getComponent(), value)
73
- return value.apply(this, args)
74
- }
75
- Object.defineProperties(spy, {
76
- name: { value: value.name || propName },
77
- length: { value: value.length },
78
- })
79
- return spy
80
- }
81
-
82
- const { meta, uniqueId } = createMeta(path, propName, value)
83
-
84
- // Strings: Embed markers
85
- if (typeof value === 'string') {
86
- metadataMap.set(uniqueId, meta)
87
- return `${uniqueId}${value}${uniqueId}`
88
- }
89
-
90
- // Numbers/Booleans: Wrapper Objects
91
- // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
92
- type SpyWrapper = (number | boolean) & { [PROP_SPY_SYMBOL]?: boolean; __meta?: PropSpyMeta }
93
- let spy: SpyWrapper | undefined
94
- if (typeof value === 'number') spy = new Number(value) as SpyWrapper
95
- if (typeof value === 'boolean') spy = new Boolean(value) as SpyWrapper
96
-
97
- if (spy) {
98
- spy[PROP_SPY_SYMBOL] = true
99
- spy.__meta = meta
100
- return spy
101
- }
102
-
103
- return value
104
- }
105
-
106
- // ─────────────────────────────────────────────────────────────────────────────
107
- // Core Logic
108
- // ─────────────────────────────────────────────────────────────────────────────
109
-
110
- const createAuditedProps = <T extends object | null>(
111
- target: T,
112
- stores: TrackingStores,
113
- getComponent: () => string,
114
- basePath = 'props',
115
- ): T => {
116
- if (!target || typeof target !== 'object' || isPropSpy(target)) return target
117
-
118
- return new Proxy(target, {
119
- get(obj, prop, receiver) {
120
- const value = Reflect.get(obj, prop, receiver)
121
- const propKey = String(prop)
122
-
123
- // Ignore symbols and known React internal properties
124
- if (typeof prop === 'symbol' || propKey === '$$typeof' || propKey.startsWith('_')) {
125
- return value
126
- }
127
-
128
- const path = Array.isArray(target) ? `${basePath}[${propKey}]` : `${basePath}.${propKey}`
129
- const component = getComponent()
130
-
131
- // 1. Handle React internals or nulls (Log but don't wrap)
132
- if (value == null || isReactInternal(value)) {
133
- logRead(stores, path, component, value)
134
- return value
135
- }
136
-
137
- // 2. Handle Primitives & Functions (Wrap & Log)
138
- if (typeof value !== 'object' || typeof value === 'function') {
139
- const wrapped = wrapPrimitiveOrFunction(
140
- value as string | number | boolean | ((...args: unknown[]) => unknown),
141
- path,
142
- propKey,
143
- stores,
144
- getComponent,
145
- )
146
- logRead(stores, path, component, wrapped)
147
- return wrapped
148
- }
149
-
150
- // 3. Handle Objects/Arrays (Recurse Proxy & Log)
151
- const audited = createAuditedProps(value, stores, getComponent, path)
152
- logRead(stores, path, component, audited)
153
- return audited
154
- },
155
- ownKeys: (obj) => Reflect.ownKeys(obj),
156
- getOwnPropertyDescriptor: (obj, prop) => Reflect.getOwnPropertyDescriptor(obj, prop),
157
- })
158
- }
159
-
160
- const getSpyMetadataByUniqueId = (id: string): PropSpyMeta | null => {
161
- return metadataMap.get(id) ?? null
162
- }
163
-
164
- return {
165
- createAuditedProps,
166
- getSpyMetadataByUniqueId,
167
- }
168
- }