@soda-gql/common 0.0.1

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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/dist/canonical-id/index.cjs +9 -0
  3. package/dist/canonical-id/index.d.cts +2 -0
  4. package/dist/canonical-id/index.d.ts +2 -0
  5. package/dist/canonical-id/index.js +4 -0
  6. package/dist/canonical-id-Bn6ZPdZl.js +155 -0
  7. package/dist/canonical-id-Bn6ZPdZl.js.map +1 -0
  8. package/dist/canonical-id-CE4Xjo2C.cjs +192 -0
  9. package/dist/chunk-CUT6urMc.cjs +30 -0
  10. package/dist/index-B_QJzQA2.d.cts +9 -0
  11. package/dist/index-B_QJzQA2.d.cts.map +1 -0
  12. package/dist/index-C0n5gWc3.d.cts +88 -0
  13. package/dist/index-C0n5gWc3.d.cts.map +1 -0
  14. package/dist/index-C8yyrGd7.d.cts +124 -0
  15. package/dist/index-C8yyrGd7.d.cts.map +1 -0
  16. package/dist/index-CcSB32XQ.d.ts +60 -0
  17. package/dist/index-CcSB32XQ.d.ts.map +1 -0
  18. package/dist/index-D6Lx478n.d.ts +124 -0
  19. package/dist/index-D6Lx478n.d.ts.map +1 -0
  20. package/dist/index-DN4VW1v7.d.ts +9 -0
  21. package/dist/index-DN4VW1v7.d.ts.map +1 -0
  22. package/dist/index-Fi3RpHje.d.cts +60 -0
  23. package/dist/index-Fi3RpHje.d.cts.map +1 -0
  24. package/dist/index-LjtXZhxM.d.ts +88 -0
  25. package/dist/index-LjtXZhxM.d.ts.map +1 -0
  26. package/dist/index.cjs +30 -0
  27. package/dist/index.d.cts +5 -0
  28. package/dist/index.d.ts +5 -0
  29. package/dist/index.js +6 -0
  30. package/dist/portable/index.cjs +13 -0
  31. package/dist/portable/index.d.cts +2 -0
  32. package/dist/portable/index.d.ts +2 -0
  33. package/dist/portable/index.js +3 -0
  34. package/dist/portable-BqSEwase.js +249 -0
  35. package/dist/portable-BqSEwase.js.map +1 -0
  36. package/dist/portable-Bq_Qob6b.cjs +308 -0
  37. package/dist/utils/index.cjs +9 -0
  38. package/dist/utils/index.d.cts +2 -0
  39. package/dist/utils/index.d.ts +2 -0
  40. package/dist/utils/index.js +3 -0
  41. package/dist/utils-DxBnV8tL.js +100 -0
  42. package/dist/utils-DxBnV8tL.js.map +1 -0
  43. package/dist/utils-NBAPoMgh.cjs +143 -0
  44. package/dist/zod/index.cjs +3 -0
  45. package/dist/zod/index.d.cts +2 -0
  46. package/dist/zod/index.d.ts +2 -0
  47. package/dist/zod/index.js +3 -0
  48. package/dist/zod-B1gOOwdX.cjs +16 -0
  49. package/dist/zod-BPbnZc6i.js +10 -0
  50. package/dist/zod-BPbnZc6i.js.map +1 -0
  51. package/package.json +61 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Shota Hatada
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ require('../utils-NBAPoMgh.cjs');
2
+ const require_canonical_id = require('../canonical-id-CE4Xjo2C.cjs');
3
+
4
+ exports.CanonicalIdSchema = require_canonical_id.CanonicalIdSchema;
5
+ exports.buildAstPath = require_canonical_id.buildAstPath;
6
+ exports.createCanonicalId = require_canonical_id.createCanonicalId;
7
+ exports.createCanonicalTracker = require_canonical_id.createCanonicalTracker;
8
+ exports.createOccurrenceTracker = require_canonical_id.createOccurrenceTracker;
9
+ exports.createPathTracker = require_canonical_id.createPathTracker;
@@ -0,0 +1,2 @@
1
+ import { CanonicalId, CanonicalIdSchema, CanonicalPathTracker, ScopeFrame, ScopeHandle, buildAstPath, createCanonicalId, createCanonicalTracker, createOccurrenceTracker, createPathTracker } from "../index-C8yyrGd7.cjs";
2
+ export { CanonicalId, CanonicalIdSchema, CanonicalPathTracker, ScopeFrame, ScopeHandle, buildAstPath, createCanonicalId, createCanonicalTracker, createOccurrenceTracker, createPathTracker };
@@ -0,0 +1,2 @@
1
+ import { CanonicalId, CanonicalIdSchema, CanonicalPathTracker, ScopeFrame, ScopeHandle, buildAstPath, createCanonicalId, createCanonicalTracker, createOccurrenceTracker, createPathTracker } from "../index-D6Lx478n.js";
2
+ export { CanonicalId, CanonicalIdSchema, CanonicalPathTracker, ScopeFrame, ScopeHandle, buildAstPath, createCanonicalId, createCanonicalTracker, createOccurrenceTracker, createPathTracker };
@@ -0,0 +1,4 @@
1
+ import "../utils-DxBnV8tL.js";
2
+ import { CanonicalIdSchema, buildAstPath, createCanonicalId, createCanonicalTracker, createOccurrenceTracker, createPathTracker } from "../canonical-id-Bn6ZPdZl.js";
3
+
4
+ export { CanonicalIdSchema, buildAstPath, createCanonicalId, createCanonicalTracker, createOccurrenceTracker, createPathTracker };
@@ -0,0 +1,155 @@
1
+ import { normalizePath } from "./utils-DxBnV8tL.js";
2
+ import { isAbsolute, resolve } from "node:path";
3
+ import z$1 from "zod";
4
+
5
+ //#region packages/common/src/canonical-id/canonical-id.ts
6
+ const canonicalIdSeparator = "::";
7
+ const CanonicalIdSchema = z$1.string();
8
+ const createCanonicalId = (filePath, astPath) => {
9
+ if (!isAbsolute(filePath)) {
10
+ throw new Error("[INTERNAL] CANONICAL_ID_REQUIRES_ABSOLUTE_PATH");
11
+ }
12
+ const resolved = resolve(filePath);
13
+ const normalized = normalizePath(resolved);
14
+ const idParts = [normalized, astPath];
15
+ return idParts.join(canonicalIdSeparator);
16
+ };
17
+
18
+ //#endregion
19
+ //#region packages/common/src/canonical-id/path-tracker.ts
20
+ /**
21
+ * Build AST path from scope stack (internal helper)
22
+ */
23
+ const _buildAstPath = (stack) => {
24
+ return stack.map((frame) => frame.nameSegment).join(".");
25
+ };
26
+ /**
27
+ * Create a canonical path tracker
28
+ *
29
+ * @param options Configuration options
30
+ * @returns Tracker instance
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * // In a Babel plugin
35
+ * const tracker = createCanonicalTracker({ filePath: state.filename });
36
+ *
37
+ * const visitor = {
38
+ * FunctionDeclaration: {
39
+ * enter(path) {
40
+ * const handle = tracker.enterScope({
41
+ * segment: path.node.id.name,
42
+ * kind: 'function'
43
+ * });
44
+ * },
45
+ * exit(path) {
46
+ * tracker.exitScope(handle);
47
+ * }
48
+ * }
49
+ * };
50
+ * ```
51
+ */
52
+ const createCanonicalTracker = (options) => {
53
+ const { filePath, getExportName } = options;
54
+ const scopeStack = [];
55
+ const occurrenceCounters = new Map();
56
+ const usedPaths = new Set();
57
+ const exportBindings = new Map();
58
+ const getNextOccurrence = (key) => {
59
+ const current = occurrenceCounters.get(key) ?? 0;
60
+ occurrenceCounters.set(key, current + 1);
61
+ return current;
62
+ };
63
+ const ensureUniquePath = (basePath) => {
64
+ let path = basePath;
65
+ let suffix = 0;
66
+ while (usedPaths.has(path)) {
67
+ suffix++;
68
+ path = `${basePath}$${suffix}`;
69
+ }
70
+ usedPaths.add(path);
71
+ return path;
72
+ };
73
+ return {
74
+ enterScope({ segment, kind, stableKey }) {
75
+ const key = stableKey ?? `${kind}:${segment}`;
76
+ const occurrence = getNextOccurrence(key);
77
+ const frame = {
78
+ nameSegment: segment,
79
+ kind,
80
+ occurrence
81
+ };
82
+ scopeStack.push(frame);
83
+ return {
84
+ __brand: "ScopeHandle",
85
+ depth: scopeStack.length - 1
86
+ };
87
+ },
88
+ exitScope(handle) {
89
+ if (handle.depth !== scopeStack.length - 1) {
90
+ throw new Error(`[INTERNAL] Invalid scope exit: expected depth ${scopeStack.length - 1}, got ${handle.depth}`);
91
+ }
92
+ scopeStack.pop();
93
+ },
94
+ registerDefinition() {
95
+ const basePath = _buildAstPath(scopeStack);
96
+ const astPath = ensureUniquePath(basePath);
97
+ const isTopLevel = scopeStack.length === 0;
98
+ let exportBinding;
99
+ if (getExportName && isTopLevel) {
100
+ exportBinding = undefined;
101
+ }
102
+ return {
103
+ astPath,
104
+ isTopLevel,
105
+ exportBinding
106
+ };
107
+ },
108
+ resolveCanonicalId(astPath) {
109
+ return createCanonicalId(filePath, astPath);
110
+ },
111
+ registerExportBinding(local, exported) {
112
+ exportBindings.set(local, exported);
113
+ },
114
+ currentDepth() {
115
+ return scopeStack.length;
116
+ }
117
+ };
118
+ };
119
+ /**
120
+ * Helper to create occurrence tracker (for backward compatibility)
121
+ */
122
+ const createOccurrenceTracker = () => {
123
+ const occurrenceCounters = new Map();
124
+ return { getNextOccurrence(key) {
125
+ const current = occurrenceCounters.get(key) ?? 0;
126
+ occurrenceCounters.set(key, current + 1);
127
+ return current;
128
+ } };
129
+ };
130
+ /**
131
+ * Helper to create path tracker (for backward compatibility)
132
+ */
133
+ const createPathTracker = () => {
134
+ const usedPaths = new Set();
135
+ return { ensureUniquePath(basePath) {
136
+ let path = basePath;
137
+ let suffix = 0;
138
+ while (usedPaths.has(path)) {
139
+ suffix++;
140
+ path = `${basePath}$${suffix}`;
141
+ }
142
+ usedPaths.add(path);
143
+ return path;
144
+ } };
145
+ };
146
+ /**
147
+ * Build AST path from scope stack (for backward compatibility)
148
+ */
149
+ const buildAstPath = (stack) => {
150
+ return stack.map((frame) => frame.nameSegment).join(".");
151
+ };
152
+
153
+ //#endregion
154
+ export { CanonicalIdSchema, buildAstPath, createCanonicalId, createCanonicalTracker, createOccurrenceTracker, createPathTracker };
155
+ //# sourceMappingURL=canonical-id-Bn6ZPdZl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical-id-Bn6ZPdZl.js","names":["CanonicalIdSchema: z.ZodType<CanonicalId>","z","scopeStack: ScopeFrame[]","frame: ScopeFrame","exportBinding: string | undefined"],"sources":["../src/canonical-id/canonical-id.ts","../src/canonical-id/path-tracker.ts"],"sourcesContent":["import { isAbsolute, resolve } from \"node:path\";\nimport z from \"zod\";\nimport { normalizePath } from \"../utils\";\n\nexport type CanonicalId = string & { readonly __brand: \"CanonicalId\" };\n\nconst canonicalIdSeparator = \"::\" as const;\n\nexport const CanonicalIdSchema: z.ZodType<CanonicalId> = z.string() as unknown as z.ZodType<CanonicalId>;\n\n// Type-safe schema for CanonicalId - validates as string but types as branded\nexport const createCanonicalId = (filePath: string, astPath: string): CanonicalId => {\n if (!isAbsolute(filePath)) {\n throw new Error(\"[INTERNAL] CANONICAL_ID_REQUIRES_ABSOLUTE_PATH\");\n }\n\n const resolved = resolve(filePath);\n const normalized = normalizePath(resolved);\n\n // Create a 2-part ID: {absPath}::{astPath}\n // astPath uniquely identifies the definition's location in the AST (e.g., \"MyComponent.useQuery.def\")\n const idParts = [normalized, astPath];\n\n return idParts.join(canonicalIdSeparator) as CanonicalId;\n};\n","/**\n * Canonical path tracker for AST traversal.\n *\n * This module provides a stateful helper that tracks scope information during\n * AST traversal to generate canonical IDs. It's designed to integrate with\n * existing plugin visitor patterns (Babel, SWC, TypeScript) without requiring\n * a separate AST traversal.\n *\n * Usage pattern:\n * 1. Plugin creates tracker at file/program entry\n * 2. Plugin calls enterScope/exitScope during its traversal\n * 3. Plugin calls registerDefinition when discovering GQL definitions\n * 4. Tracker provides canonical ID information\n */\n\nimport type { CanonicalId } from \"./canonical-id\";\nimport { createCanonicalId } from \"./canonical-id\";\n\n/**\n * Scope frame for tracking AST path segments\n */\nexport type ScopeFrame = {\n /** Name segment (e.g., \"MyComponent\", \"useQuery\", \"arrow#1\") */\n readonly nameSegment: string;\n /** Kind of scope */\n readonly kind: \"function\" | \"class\" | \"variable\" | \"property\" | \"method\" | \"expression\";\n /** Occurrence index for disambiguation */\n readonly occurrence: number;\n};\n\n/**\n * Opaque handle for scope tracking\n */\nexport type ScopeHandle = {\n readonly __brand: \"ScopeHandle\";\n readonly depth: number;\n};\n\n/**\n * Canonical path tracker interface\n */\nexport interface CanonicalPathTracker {\n /**\n * Enter a new scope during traversal\n * @param options Scope information\n * @returns Handle to use when exiting the scope\n */\n enterScope(options: { segment: string; kind: ScopeFrame[\"kind\"]; stableKey?: string }): ScopeHandle;\n\n /**\n * Exit a scope during traversal\n * @param handle Handle returned from enterScope\n */\n exitScope(handle: ScopeHandle): void;\n\n /**\n * Register a definition discovered during traversal\n * @returns Definition metadata including astPath and canonical ID information\n */\n registerDefinition(): {\n astPath: string;\n isTopLevel: boolean;\n exportBinding?: string;\n };\n\n /**\n * Resolve a canonical ID from an astPath\n * @param astPath AST path string\n * @returns Canonical ID\n */\n resolveCanonicalId(astPath: string): CanonicalId;\n\n /**\n * Register an export binding\n * @param local Local variable name\n * @param exported Exported name\n */\n registerExportBinding(local: string, exported: string): void;\n\n /**\n * Get current scope depth\n * @returns Current depth (0 = top level)\n */\n currentDepth(): number;\n}\n\n/**\n * Build AST path from scope stack (internal helper)\n */\nconst _buildAstPath = (stack: readonly ScopeFrame[]): string => {\n return stack.map((frame) => frame.nameSegment).join(\".\");\n};\n\n/**\n * Create a canonical path tracker\n *\n * @param options Configuration options\n * @returns Tracker instance\n *\n * @example\n * ```typescript\n * // In a Babel plugin\n * const tracker = createCanonicalTracker({ filePath: state.filename });\n *\n * const visitor = {\n * FunctionDeclaration: {\n * enter(path) {\n * const handle = tracker.enterScope({\n * segment: path.node.id.name,\n * kind: 'function'\n * });\n * },\n * exit(path) {\n * tracker.exitScope(handle);\n * }\n * }\n * };\n * ```\n */\nexport const createCanonicalTracker = (options: {\n filePath: string;\n getExportName?: (localName: string) => string | undefined;\n}): CanonicalPathTracker => {\n const { filePath, getExportName } = options;\n\n // Scope stack\n const scopeStack: ScopeFrame[] = [];\n\n // Occurrence counters for disambiguating duplicate names\n const occurrenceCounters = new Map<string, number>();\n\n // Used paths for ensuring uniqueness\n const usedPaths = new Set<string>();\n\n // Export bindings map\n const exportBindings = new Map<string, string>();\n\n const getNextOccurrence = (key: string): number => {\n const current = occurrenceCounters.get(key) ?? 0;\n occurrenceCounters.set(key, current + 1);\n return current;\n };\n\n const ensureUniquePath = (basePath: string): string => {\n let path = basePath;\n let suffix = 0;\n while (usedPaths.has(path)) {\n suffix++;\n path = `${basePath}$${suffix}`;\n }\n usedPaths.add(path);\n return path;\n };\n\n return {\n enterScope({ segment, kind, stableKey }): ScopeHandle {\n const key = stableKey ?? `${kind}:${segment}`;\n const occurrence = getNextOccurrence(key);\n\n const frame: ScopeFrame = {\n nameSegment: segment,\n kind,\n occurrence,\n };\n\n scopeStack.push(frame);\n\n return {\n __brand: \"ScopeHandle\",\n depth: scopeStack.length - 1,\n } as ScopeHandle;\n },\n\n exitScope(handle: ScopeHandle): void {\n // Validate handle depth matches current stack\n if (handle.depth !== scopeStack.length - 1) {\n throw new Error(`[INTERNAL] Invalid scope exit: expected depth ${scopeStack.length - 1}, got ${handle.depth}`);\n }\n scopeStack.pop();\n },\n\n registerDefinition(): {\n astPath: string;\n isTopLevel: boolean;\n exportBinding?: string;\n } {\n const basePath = _buildAstPath(scopeStack);\n const astPath = ensureUniquePath(basePath);\n const isTopLevel = scopeStack.length === 0;\n\n // Check export binding if provided\n let exportBinding: string | undefined;\n if (getExportName && isTopLevel) {\n // For top-level definitions, try to get export name\n // This is a simplified version - real logic depends on how the definition is bound\n exportBinding = undefined;\n }\n\n return {\n astPath,\n isTopLevel,\n exportBinding,\n };\n },\n\n resolveCanonicalId(astPath: string): CanonicalId {\n return createCanonicalId(filePath, astPath);\n },\n\n registerExportBinding(local: string, exported: string): void {\n exportBindings.set(local, exported);\n },\n\n currentDepth(): number {\n return scopeStack.length;\n },\n };\n};\n\n/**\n * Helper to create occurrence tracker (for backward compatibility)\n */\nexport const createOccurrenceTracker = (): {\n getNextOccurrence: (key: string) => number;\n} => {\n const occurrenceCounters = new Map<string, number>();\n\n return {\n getNextOccurrence(key: string): number {\n const current = occurrenceCounters.get(key) ?? 0;\n occurrenceCounters.set(key, current + 1);\n return current;\n },\n };\n};\n\n/**\n * Helper to create path tracker (for backward compatibility)\n */\nexport const createPathTracker = (): {\n ensureUniquePath: (basePath: string) => string;\n} => {\n const usedPaths = new Set<string>();\n\n return {\n ensureUniquePath(basePath: string): string {\n let path = basePath;\n let suffix = 0;\n while (usedPaths.has(path)) {\n suffix++;\n path = `${basePath}$${suffix}`;\n }\n usedPaths.add(path);\n return path;\n },\n };\n};\n\n/**\n * Build AST path from scope stack (for backward compatibility)\n */\nexport const buildAstPath = (stack: readonly ScopeFrame[]): string => {\n return stack.map((frame) => frame.nameSegment).join(\".\");\n};\n"],"mappings":";;;;;AAMA,MAAM,uBAAuB;AAE7B,MAAaA,oBAA4CC,IAAE,QAAQ;AAGnE,MAAa,qBAAqB,UAAkB,YAAiC;AACnF,KAAI,CAAC,WAAW,SAAS,EAAE;AACzB,QAAM,IAAI,MAAM,iDAAiD;;CAGnE,MAAM,WAAW,QAAQ,SAAS;CAClC,MAAM,aAAa,cAAc,SAAS;CAI1C,MAAM,UAAU,CAAC,YAAY,QAAQ;AAErC,QAAO,QAAQ,KAAK,qBAAqB;;;;;;;;ACkE3C,MAAM,iBAAiB,UAAyC;AAC9D,QAAO,MAAM,KAAK,UAAU,MAAM,YAAY,CAAC,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6B1D,MAAa,0BAA0B,YAGX;CAC1B,MAAM,EAAE,UAAU,kBAAkB;CAGpC,MAAMC,aAA2B,EAAE;CAGnC,MAAM,qBAAqB,IAAI,KAAqB;CAGpD,MAAM,YAAY,IAAI,KAAa;CAGnC,MAAM,iBAAiB,IAAI,KAAqB;CAEhD,MAAM,qBAAqB,QAAwB;EACjD,MAAM,UAAU,mBAAmB,IAAI,IAAI,IAAI;AAC/C,qBAAmB,IAAI,KAAK,UAAU,EAAE;AACxC,SAAO;;CAGT,MAAM,oBAAoB,aAA6B;EACrD,IAAI,OAAO;EACX,IAAI,SAAS;AACb,SAAO,UAAU,IAAI,KAAK,EAAE;AAC1B;AACA,UAAO,GAAG,SAAS,GAAG;;AAExB,YAAU,IAAI,KAAK;AACnB,SAAO;;AAGT,QAAO;EACL,WAAW,EAAE,SAAS,MAAM,aAA0B;GACpD,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG;GACpC,MAAM,aAAa,kBAAkB,IAAI;GAEzC,MAAMC,QAAoB;IACxB,aAAa;IACb;IACA;IACD;AAED,cAAW,KAAK,MAAM;AAEtB,UAAO;IACL,SAAS;IACT,OAAO,WAAW,SAAS;IAC5B;;EAGH,UAAU,QAA2B;AAEnC,OAAI,OAAO,UAAU,WAAW,SAAS,GAAG;AAC1C,UAAM,IAAI,MAAM,iDAAiD,WAAW,SAAS,EAAE,QAAQ,OAAO,QAAQ;;AAEhH,cAAW,KAAK;;EAGlB,qBAIE;GACA,MAAM,WAAW,cAAc,WAAW;GAC1C,MAAM,UAAU,iBAAiB,SAAS;GAC1C,MAAM,aAAa,WAAW,WAAW;GAGzC,IAAIC;AACJ,OAAI,iBAAiB,YAAY;AAG/B,oBAAgB;;AAGlB,UAAO;IACL;IACA;IACA;IACD;;EAGH,mBAAmB,SAA8B;AAC/C,UAAO,kBAAkB,UAAU,QAAQ;;EAG7C,sBAAsB,OAAe,UAAwB;AAC3D,kBAAe,IAAI,OAAO,SAAS;;EAGrC,eAAuB;AACrB,UAAO,WAAW;;EAErB;;;;;AAMH,MAAa,gCAER;CACH,MAAM,qBAAqB,IAAI,KAAqB;AAEpD,QAAO,EACL,kBAAkB,KAAqB;EACrC,MAAM,UAAU,mBAAmB,IAAI,IAAI,IAAI;AAC/C,qBAAmB,IAAI,KAAK,UAAU,EAAE;AACxC,SAAO;IAEV;;;;;AAMH,MAAa,0BAER;CACH,MAAM,YAAY,IAAI,KAAa;AAEnC,QAAO,EACL,iBAAiB,UAA0B;EACzC,IAAI,OAAO;EACX,IAAI,SAAS;AACb,SAAO,UAAU,IAAI,KAAK,EAAE;AAC1B;AACA,UAAO,GAAG,SAAS,GAAG;;AAExB,YAAU,IAAI,KAAK;AACnB,SAAO;IAEV;;;;;AAMH,MAAa,gBAAgB,UAAyC;AACpE,QAAO,MAAM,KAAK,UAAU,MAAM,YAAY,CAAC,KAAK,IAAI"}
@@ -0,0 +1,192 @@
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const require_utils = require('./utils-NBAPoMgh.cjs');
3
+ let node_path = require("node:path");
4
+ node_path = require_chunk.__toESM(node_path);
5
+ let zod = require("zod");
6
+ zod = require_chunk.__toESM(zod);
7
+
8
+ //#region packages/common/src/canonical-id/canonical-id.ts
9
+ const canonicalIdSeparator = "::";
10
+ const CanonicalIdSchema = zod.default.string();
11
+ const createCanonicalId = (filePath, astPath) => {
12
+ if (!(0, node_path.isAbsolute)(filePath)) {
13
+ throw new Error("[INTERNAL] CANONICAL_ID_REQUIRES_ABSOLUTE_PATH");
14
+ }
15
+ const resolved = (0, node_path.resolve)(filePath);
16
+ const normalized = require_utils.normalizePath(resolved);
17
+ const idParts = [normalized, astPath];
18
+ return idParts.join(canonicalIdSeparator);
19
+ };
20
+
21
+ //#endregion
22
+ //#region packages/common/src/canonical-id/path-tracker.ts
23
+ /**
24
+ * Build AST path from scope stack (internal helper)
25
+ */
26
+ const _buildAstPath = (stack) => {
27
+ return stack.map((frame) => frame.nameSegment).join(".");
28
+ };
29
+ /**
30
+ * Create a canonical path tracker
31
+ *
32
+ * @param options Configuration options
33
+ * @returns Tracker instance
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * // In a Babel plugin
38
+ * const tracker = createCanonicalTracker({ filePath: state.filename });
39
+ *
40
+ * const visitor = {
41
+ * FunctionDeclaration: {
42
+ * enter(path) {
43
+ * const handle = tracker.enterScope({
44
+ * segment: path.node.id.name,
45
+ * kind: 'function'
46
+ * });
47
+ * },
48
+ * exit(path) {
49
+ * tracker.exitScope(handle);
50
+ * }
51
+ * }
52
+ * };
53
+ * ```
54
+ */
55
+ const createCanonicalTracker = (options) => {
56
+ const { filePath, getExportName } = options;
57
+ const scopeStack = [];
58
+ const occurrenceCounters = new Map();
59
+ const usedPaths = new Set();
60
+ const exportBindings = new Map();
61
+ const getNextOccurrence = (key) => {
62
+ const current = occurrenceCounters.get(key) ?? 0;
63
+ occurrenceCounters.set(key, current + 1);
64
+ return current;
65
+ };
66
+ const ensureUniquePath = (basePath) => {
67
+ let path = basePath;
68
+ let suffix = 0;
69
+ while (usedPaths.has(path)) {
70
+ suffix++;
71
+ path = `${basePath}$${suffix}`;
72
+ }
73
+ usedPaths.add(path);
74
+ return path;
75
+ };
76
+ return {
77
+ enterScope({ segment, kind, stableKey }) {
78
+ const key = stableKey ?? `${kind}:${segment}`;
79
+ const occurrence = getNextOccurrence(key);
80
+ const frame = {
81
+ nameSegment: segment,
82
+ kind,
83
+ occurrence
84
+ };
85
+ scopeStack.push(frame);
86
+ return {
87
+ __brand: "ScopeHandle",
88
+ depth: scopeStack.length - 1
89
+ };
90
+ },
91
+ exitScope(handle) {
92
+ if (handle.depth !== scopeStack.length - 1) {
93
+ throw new Error(`[INTERNAL] Invalid scope exit: expected depth ${scopeStack.length - 1}, got ${handle.depth}`);
94
+ }
95
+ scopeStack.pop();
96
+ },
97
+ registerDefinition() {
98
+ const basePath = _buildAstPath(scopeStack);
99
+ const astPath = ensureUniquePath(basePath);
100
+ const isTopLevel = scopeStack.length === 0;
101
+ let exportBinding;
102
+ if (getExportName && isTopLevel) {
103
+ exportBinding = undefined;
104
+ }
105
+ return {
106
+ astPath,
107
+ isTopLevel,
108
+ exportBinding
109
+ };
110
+ },
111
+ resolveCanonicalId(astPath) {
112
+ return createCanonicalId(filePath, astPath);
113
+ },
114
+ registerExportBinding(local, exported) {
115
+ exportBindings.set(local, exported);
116
+ },
117
+ currentDepth() {
118
+ return scopeStack.length;
119
+ }
120
+ };
121
+ };
122
+ /**
123
+ * Helper to create occurrence tracker (for backward compatibility)
124
+ */
125
+ const createOccurrenceTracker = () => {
126
+ const occurrenceCounters = new Map();
127
+ return { getNextOccurrence(key) {
128
+ const current = occurrenceCounters.get(key) ?? 0;
129
+ occurrenceCounters.set(key, current + 1);
130
+ return current;
131
+ } };
132
+ };
133
+ /**
134
+ * Helper to create path tracker (for backward compatibility)
135
+ */
136
+ const createPathTracker = () => {
137
+ const usedPaths = new Set();
138
+ return { ensureUniquePath(basePath) {
139
+ let path = basePath;
140
+ let suffix = 0;
141
+ while (usedPaths.has(path)) {
142
+ suffix++;
143
+ path = `${basePath}$${suffix}`;
144
+ }
145
+ usedPaths.add(path);
146
+ return path;
147
+ } };
148
+ };
149
+ /**
150
+ * Build AST path from scope stack (for backward compatibility)
151
+ */
152
+ const buildAstPath = (stack) => {
153
+ return stack.map((frame) => frame.nameSegment).join(".");
154
+ };
155
+
156
+ //#endregion
157
+ Object.defineProperty(exports, 'CanonicalIdSchema', {
158
+ enumerable: true,
159
+ get: function () {
160
+ return CanonicalIdSchema;
161
+ }
162
+ });
163
+ Object.defineProperty(exports, 'buildAstPath', {
164
+ enumerable: true,
165
+ get: function () {
166
+ return buildAstPath;
167
+ }
168
+ });
169
+ Object.defineProperty(exports, 'createCanonicalId', {
170
+ enumerable: true,
171
+ get: function () {
172
+ return createCanonicalId;
173
+ }
174
+ });
175
+ Object.defineProperty(exports, 'createCanonicalTracker', {
176
+ enumerable: true,
177
+ get: function () {
178
+ return createCanonicalTracker;
179
+ }
180
+ });
181
+ Object.defineProperty(exports, 'createOccurrenceTracker', {
182
+ enumerable: true,
183
+ get: function () {
184
+ return createOccurrenceTracker;
185
+ }
186
+ });
187
+ Object.defineProperty(exports, 'createPathTracker', {
188
+ enumerable: true,
189
+ get: function () {
190
+ return createPathTracker;
191
+ }
192
+ });
@@ -0,0 +1,30 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+
25
+ Object.defineProperty(exports, '__toESM', {
26
+ enumerable: true,
27
+ get: function () {
28
+ return __toESM;
29
+ }
30
+ });
@@ -0,0 +1,9 @@
1
+ import { z } from "zod";
2
+
3
+ //#region packages/common/src/zod/schema-helper.d.ts
4
+ type SchemaFor<TOutput> = z.ZodType<TOutput, any, any>;
5
+ type ShapeFor<TOutput extends object> = { [K in keyof TOutput]-?: SchemaFor<TOutput[K]> };
6
+ declare function defineSchemaFor<TOutput extends object>(): <TShape extends ShapeFor<NoInfer<TOutput>>>(shape: TShape & { [K in Exclude<keyof TShape, keyof TOutput>]: never }) => z.ZodObject<TShape & { [K in Exclude<keyof TShape, keyof TOutput>]: never } extends infer T ? { -readonly [P in keyof T]: T[P] } : never, z.core.$strict>;
7
+ //#endregion
8
+ export { SchemaFor, ShapeFor, defineSchemaFor };
9
+ //# sourceMappingURL=index-B_QJzQA2.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-B_QJzQA2.d.cts","names":[],"sources":["../src/zod/schema-helper.ts"],"sourcesContent":[],"mappings":";;;KAGY,qBAAqB,CAAA,CAAE,QAAQ;KAE/B,2CAFA,MAEiD,OAFxC,KAEoD,SAFpD,CAE8D,OAF9D,CAEsE,CAFtE,CAAA,CAAA,EAAA;AAAsB,iBAI3B,eAJ2B,CAAA,gBAAA,MAAA,CAAA,CAAA,CAAA,EAAA,CAAA,eAKlB,QALkB,CAKT,OALS,CAKD,OALC,CAAA,CAAA,CAAA,CAAA,KAAA,EAKiB,MALjB,GAAA,QAKkC,OALlC,CAAA,MAKgD,MALhD,EAAA,MAK8D,OAL9D,CAAA,GAAA,KAAA,EAAA,EAAA,GAKgF,CAAA,CAAA,SALhF,CAKgF,MALhF,GAAA,QAK8B,OAL9B,CAAA,MAK8B,MAL9B,EAAA,MAK8B,OAL9B,CAAA,GAAA,KAAA,EAAA,SAAA,KAAA,EAAA,GAAA,kBAAA,MAK8B,CAL9B,GAK8B,CAL9B,CAK8B,CAL9B,CAAA,EAAA,GAAA,KAAA,EAK8B,CAAA,CAAA,IAAA,CAAA,OAL9B,CAAA"}
@@ -0,0 +1,88 @@
1
+ //#region packages/common/src/portable/fs.d.ts
2
+ /**
3
+ * Portable filesystem API that works on both Bun and Node.js
4
+ */
5
+ interface PortableFS {
6
+ readFile(path: string): Promise<string>;
7
+ writeFile(path: string, content: string): Promise<void>;
8
+ exists(path: string): Promise<boolean>;
9
+ stat(path: string): Promise<{
10
+ mtime: Date;
11
+ size: number;
12
+ }>;
13
+ rename(oldPath: string, newPath: string): Promise<void>;
14
+ mkdir(path: string, options?: {
15
+ recursive?: boolean;
16
+ }): Promise<void>;
17
+ }
18
+ declare function createPortableFS(): PortableFS;
19
+ declare function getPortableFS(): PortableFS;
20
+ /**
21
+ * Reset the filesystem singleton for testing
22
+ * @internal
23
+ */
24
+ declare function __resetPortableFSForTests(): void;
25
+ //#endregion
26
+ //#region packages/common/src/portable/hash.d.ts
27
+ /**
28
+ * Portable hashing API that works on both Bun and Node.js
29
+ */
30
+ type HashAlgorithm = "sha256" | "xxhash";
31
+ interface PortableHasher {
32
+ hash(content: string, algorithm?: HashAlgorithm): string;
33
+ }
34
+ declare function createPortableHasher(): PortableHasher;
35
+ declare function getPortableHasher(): PortableHasher;
36
+ /**
37
+ * Reset the hasher singleton for testing
38
+ * @internal
39
+ */
40
+ declare function __resetPortableHasherForTests(): void;
41
+ //#endregion
42
+ //#region packages/common/src/portable/id.d.ts
43
+ /**
44
+ * Portable ID generation that works on both Bun and Node.js
45
+ */
46
+ /**
47
+ * Generate a unique ID
48
+ * Uses UUIDv7 on Bun (monotonic), falls back to randomUUID on Node.js
49
+ */
50
+ declare function generateId(): string;
51
+ //#endregion
52
+ //#region packages/common/src/portable/runtime.d.ts
53
+ /**
54
+ * Runtime detection utilities for portable API implementation
55
+ */
56
+ declare const runtime: {
57
+ readonly isBun: boolean;
58
+ readonly isNode: boolean;
59
+ readonly supportsWebCrypto: boolean;
60
+ };
61
+ /**
62
+ * Helper to cache module imports to avoid repeated dynamic imports
63
+ */
64
+ declare function once<T>(fn: () => T): () => T;
65
+ /**
66
+ * Reset runtime state for testing purposes only
67
+ * @internal
68
+ */
69
+ declare function resetPortableForTests(): void;
70
+ //#endregion
71
+ //#region packages/common/src/portable/spawn.d.ts
72
+ /**
73
+ * Portable subprocess spawning that works on both Bun and Node.js
74
+ */
75
+ interface SpawnOptions {
76
+ cmd: string[];
77
+ cwd?: string;
78
+ env?: Record<string, string>;
79
+ }
80
+ interface SpawnResult {
81
+ stdout: string;
82
+ stderr: string;
83
+ exitCode: number;
84
+ }
85
+ declare function spawn(options: SpawnOptions): Promise<SpawnResult>;
86
+ //#endregion
87
+ export { type HashAlgorithm, type PortableFS, type PortableHasher, type SpawnOptions, type SpawnResult, __resetPortableFSForTests, __resetPortableHasherForTests, createPortableFS, createPortableHasher, generateId, getPortableFS, getPortableHasher, once, resetPortableForTests, runtime, spawn };
88
+ //# sourceMappingURL=index-C0n5gWc3.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-C0n5gWc3.d.cts","names":[],"sources":["../src/portable/fs.ts","../src/portable/hash.ts","../src/portable/id.ts","../src/portable/runtime.ts","../src/portable/spawn.ts"],"sourcesContent":[],"mappings":";;AAMA;;AAC0B,UADT,UAAA,CACS;UACkB,CAAA,IAAA,EAAA,MAAA,CAAA,EADlB,OACkB,CAAA,MAAA,CAAA;WACpB,CAAA,IAAA,EAAA,MAAA,EAAA,OAAA,EAAA,MAAA,CAAA,EADoB,OACpB,CAAA,IAAA,CAAA;QACe,CAAA,IAAA,EAAA,MAAA,CAAA,EADf,OACe,CAAA,OAAA,CAAA;MAAjB,CAAA,IAAA,EAAA,MAAA,CAAA,EAAA,OAAA,CAAA;IACsB,KAAA,EADL,IACK;IACc,IAAA,EAAA,MAAA;EAAO,CAAA,CAAA;EAsBjD,MAAA,CAAA,OAAA,EAAA,MAAgB,EAAA,OAAI,EAAA,MAAA,CAAA,EAvBQ,OAuBE,CAAA,IAAA,CAAA;EA4F9B,KAAA,CAAA,IAAA,EAAA,MAAa,EAAA,QAAI,EAAA;IAWjB,SAAA,CAAA,EAAA,OAAA;MA7H0C;;iBAsB1C,gBAAA,CAAA,GAAoB;AC5BxB,iBDwHI,aAAA,CAAA,CCxHS,EDwHQ,UCxHR;AAEzB;AAWA;AAqCA;AAWA;iBDsEgB,yBAAA,CAAA;;;;AAnIhB;;AAC0B,KCDd,aAAA,GDCc,QAAA,GAAA,QAAA;AACkB,UCA3B,cAAA,CDA2B;MACpB,CAAA,OAAA,EAAA,MAAA,EAAA,SAAA,CAAA,ECAY,aDAZ,CAAA,EAAA,MAAA;;AACF,iBCSN,oBAAA,CAAA,CDTM,ECSkB,cDTlB;AACsB,iBC6C5B,iBAAA,CAAA,CD7C4B,EC6CP,cD7CO;;;AAuB5C;AA4FA;AAWgB,iBCtEA,6BAAA,CAAA,CDsEyB,EAAA,IAAA;;;;AAnIzC;;;;;;AAIsB,iBEAN,UAAA,CAAA,CFAM,EAAA,MAAA;;;;AAJtB;;AAC0B,cGHb,OHGa,EAAA;WACkB,KAAA,EAAA,OAAA;WACpB,MAAA,EAAA,OAAA;WACe,iBAAA,EAAA,OAAA;;;;;AAwBvB,iBGrBA,IHqBgB,CAAA,CAAA,CAAA,CAAA,EAAI,EAAA,GAAA,GGrBF,CHqBE,CAAA,EAAU,GAAA,GGrBF,CHqBE;AA4F9C;AAWA;;;iBG3GgB,qBAAA,CAAA;;;;AHxBhB;;AAC0B,UIDT,YAAA,CJCS;KACkB,EAAA,MAAA,EAAA;KACpB,CAAA,EAAA,MAAA;KACe,CAAA,EID/B,MJC+B,CAAA,MAAA,EAAA,MAAA,CAAA;;AACK,UIC3B,WAAA,CJD2B;QACc,EAAA,MAAA;EAAO,MAAA,EAAA,MAAA;EAsBjD,QAAA,EAAA,MAAA;AA4FhB;AAWgB,iBIvHM,KAAA,CJuHN,OAAyB,EIvHJ,YJuHI,CAAA,EIvHW,OJuHX,CIvHmB,WJuHnB,CAAA"}
@@ -0,0 +1,124 @@
1
+ import z$1 from "zod";
2
+
3
+ //#region packages/common/src/canonical-id/canonical-id.d.ts
4
+ type CanonicalId = string & {
5
+ readonly __brand: "CanonicalId";
6
+ };
7
+ declare const CanonicalIdSchema: z$1.ZodType<CanonicalId>;
8
+ declare const createCanonicalId: (filePath: string, astPath: string) => CanonicalId;
9
+ //#endregion
10
+ //#region packages/common/src/canonical-id/path-tracker.d.ts
11
+
12
+ /**
13
+ * Scope frame for tracking AST path segments
14
+ */
15
+ type ScopeFrame = {
16
+ /** Name segment (e.g., "MyComponent", "useQuery", "arrow#1") */
17
+ readonly nameSegment: string;
18
+ /** Kind of scope */
19
+ readonly kind: "function" | "class" | "variable" | "property" | "method" | "expression";
20
+ /** Occurrence index for disambiguation */
21
+ readonly occurrence: number;
22
+ };
23
+ /**
24
+ * Opaque handle for scope tracking
25
+ */
26
+ type ScopeHandle = {
27
+ readonly __brand: "ScopeHandle";
28
+ readonly depth: number;
29
+ };
30
+ /**
31
+ * Canonical path tracker interface
32
+ */
33
+ interface CanonicalPathTracker {
34
+ /**
35
+ * Enter a new scope during traversal
36
+ * @param options Scope information
37
+ * @returns Handle to use when exiting the scope
38
+ */
39
+ enterScope(options: {
40
+ segment: string;
41
+ kind: ScopeFrame["kind"];
42
+ stableKey?: string;
43
+ }): ScopeHandle;
44
+ /**
45
+ * Exit a scope during traversal
46
+ * @param handle Handle returned from enterScope
47
+ */
48
+ exitScope(handle: ScopeHandle): void;
49
+ /**
50
+ * Register a definition discovered during traversal
51
+ * @returns Definition metadata including astPath and canonical ID information
52
+ */
53
+ registerDefinition(): {
54
+ astPath: string;
55
+ isTopLevel: boolean;
56
+ exportBinding?: string;
57
+ };
58
+ /**
59
+ * Resolve a canonical ID from an astPath
60
+ * @param astPath AST path string
61
+ * @returns Canonical ID
62
+ */
63
+ resolveCanonicalId(astPath: string): CanonicalId;
64
+ /**
65
+ * Register an export binding
66
+ * @param local Local variable name
67
+ * @param exported Exported name
68
+ */
69
+ registerExportBinding(local: string, exported: string): void;
70
+ /**
71
+ * Get current scope depth
72
+ * @returns Current depth (0 = top level)
73
+ */
74
+ currentDepth(): number;
75
+ }
76
+ /**
77
+ * Create a canonical path tracker
78
+ *
79
+ * @param options Configuration options
80
+ * @returns Tracker instance
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * // In a Babel plugin
85
+ * const tracker = createCanonicalTracker({ filePath: state.filename });
86
+ *
87
+ * const visitor = {
88
+ * FunctionDeclaration: {
89
+ * enter(path) {
90
+ * const handle = tracker.enterScope({
91
+ * segment: path.node.id.name,
92
+ * kind: 'function'
93
+ * });
94
+ * },
95
+ * exit(path) {
96
+ * tracker.exitScope(handle);
97
+ * }
98
+ * }
99
+ * };
100
+ * ```
101
+ */
102
+ declare const createCanonicalTracker: (options: {
103
+ filePath: string;
104
+ getExportName?: (localName: string) => string | undefined;
105
+ }) => CanonicalPathTracker;
106
+ /**
107
+ * Helper to create occurrence tracker (for backward compatibility)
108
+ */
109
+ declare const createOccurrenceTracker: () => {
110
+ getNextOccurrence: (key: string) => number;
111
+ };
112
+ /**
113
+ * Helper to create path tracker (for backward compatibility)
114
+ */
115
+ declare const createPathTracker: () => {
116
+ ensureUniquePath: (basePath: string) => string;
117
+ };
118
+ /**
119
+ * Build AST path from scope stack (for backward compatibility)
120
+ */
121
+ declare const buildAstPath: (stack: readonly ScopeFrame[]) => string;
122
+ //#endregion
123
+ export { CanonicalId, CanonicalIdSchema, CanonicalPathTracker, ScopeFrame, ScopeHandle, buildAstPath, createCanonicalId, createCanonicalTracker, createOccurrenceTracker, createPathTracker };
124
+ //# sourceMappingURL=index-C8yyrGd7.d.cts.map