@cmj/juice 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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -0
  3. package/dist/cli/commands.d.ts +29 -0
  4. package/dist/cli/commands.d.ts.map +1 -0
  5. package/dist/cli/commands.js +102 -0
  6. package/dist/cli/commands.js.map +1 -0
  7. package/dist/cli/create.d.ts +35 -0
  8. package/dist/cli/create.d.ts.map +1 -0
  9. package/dist/cli/create.js +108 -0
  10. package/dist/cli/create.js.map +1 -0
  11. package/dist/cli/index.d.ts +3 -0
  12. package/dist/cli/index.d.ts.map +1 -0
  13. package/dist/cli/index.js +97 -0
  14. package/dist/cli/index.js.map +1 -0
  15. package/dist/cli/templates.d.ts +14 -0
  16. package/dist/cli/templates.d.ts.map +1 -0
  17. package/dist/cli/templates.js +154 -0
  18. package/dist/cli/templates.js.map +1 -0
  19. package/dist/compiler/errors.d.ts +91 -0
  20. package/dist/compiler/errors.d.ts.map +1 -0
  21. package/dist/compiler/errors.js +110 -0
  22. package/dist/compiler/errors.js.map +1 -0
  23. package/dist/compiler/manifest.d.ts +39 -0
  24. package/dist/compiler/manifest.d.ts.map +1 -0
  25. package/dist/compiler/manifest.js +78 -0
  26. package/dist/compiler/manifest.js.map +1 -0
  27. package/dist/compiler/parse.d.ts +126 -0
  28. package/dist/compiler/parse.d.ts.map +1 -0
  29. package/dist/compiler/parse.js +246 -0
  30. package/dist/compiler/parse.js.map +1 -0
  31. package/dist/compiler/plugin.d.ts +43 -0
  32. package/dist/compiler/plugin.d.ts.map +1 -0
  33. package/dist/compiler/plugin.js +281 -0
  34. package/dist/compiler/plugin.js.map +1 -0
  35. package/dist/compiler/proxy.d.ts +42 -0
  36. package/dist/compiler/proxy.d.ts.map +1 -0
  37. package/dist/compiler/proxy.js +80 -0
  38. package/dist/compiler/proxy.js.map +1 -0
  39. package/dist/compiler/registry.d.ts +58 -0
  40. package/dist/compiler/registry.d.ts.map +1 -0
  41. package/dist/compiler/registry.js +79 -0
  42. package/dist/compiler/registry.js.map +1 -0
  43. package/dist/compiler/server-action-registry.d.ts +57 -0
  44. package/dist/compiler/server-action-registry.d.ts.map +1 -0
  45. package/dist/compiler/server-action-registry.js +76 -0
  46. package/dist/compiler/server-action-registry.js.map +1 -0
  47. package/dist/compiler/server-actions.d.ts +49 -0
  48. package/dist/compiler/server-actions.d.ts.map +1 -0
  49. package/dist/compiler/server-actions.js +89 -0
  50. package/dist/compiler/server-actions.js.map +1 -0
  51. package/dist/compiler/types.d.ts +188 -0
  52. package/dist/compiler/types.d.ts.map +1 -0
  53. package/dist/compiler/types.js +9 -0
  54. package/dist/compiler/types.js.map +1 -0
  55. package/dist/runtime/actions.d.ts +37 -0
  56. package/dist/runtime/actions.d.ts.map +1 -0
  57. package/dist/runtime/actions.js +167 -0
  58. package/dist/runtime/actions.js.map +1 -0
  59. package/dist/runtime/dev.d.ts +43 -0
  60. package/dist/runtime/dev.d.ts.map +1 -0
  61. package/dist/runtime/dev.js +260 -0
  62. package/dist/runtime/dev.js.map +1 -0
  63. package/dist/runtime/errors.d.ts +98 -0
  64. package/dist/runtime/errors.d.ts.map +1 -0
  65. package/dist/runtime/errors.js +124 -0
  66. package/dist/runtime/errors.js.map +1 -0
  67. package/dist/runtime/index.d.ts +3 -0
  68. package/dist/runtime/index.d.ts.map +1 -0
  69. package/dist/runtime/index.js +5 -0
  70. package/dist/runtime/index.js.map +1 -0
  71. package/dist/runtime/matcher.d.ts +44 -0
  72. package/dist/runtime/matcher.d.ts.map +1 -0
  73. package/dist/runtime/matcher.js +83 -0
  74. package/dist/runtime/matcher.js.map +1 -0
  75. package/dist/runtime/render.d.ts +25 -0
  76. package/dist/runtime/render.d.ts.map +1 -0
  77. package/dist/runtime/render.js +141 -0
  78. package/dist/runtime/render.js.map +1 -0
  79. package/dist/runtime/resolve.d.ts +24 -0
  80. package/dist/runtime/resolve.d.ts.map +1 -0
  81. package/dist/runtime/resolve.js +41 -0
  82. package/dist/runtime/resolve.js.map +1 -0
  83. package/dist/runtime/router.d.ts +74 -0
  84. package/dist/runtime/router.d.ts.map +1 -0
  85. package/dist/runtime/router.js +367 -0
  86. package/dist/runtime/router.js.map +1 -0
  87. package/dist/runtime/types.d.ts +245 -0
  88. package/dist/runtime/types.d.ts.map +1 -0
  89. package/dist/runtime/types.js +5 -0
  90. package/dist/runtime/types.js.map +1 -0
  91. package/package.json +92 -0
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Generates React Flight proxy modules that replace `'use client'` source
3
+ * modules in the server build.
4
+ *
5
+ * The proxy module exports `registerClientReference` calls for each export
6
+ * found in the original client component. This allows the React Flight
7
+ * serializer to emit a reference to the client chunk instead of attempting
8
+ * to render the component on the server.
9
+ *
10
+ * @module proxy
11
+ * @internal
12
+ */
13
+ /**
14
+ * Generate the server-side proxy source code for a `'use client'` module.
15
+ *
16
+ * The emitted code replaces the original module in the server bundle.
17
+ * Each export becomes a `registerClientReference()` call that the React
18
+ * Flight serializer understands.
19
+ *
20
+ * @param moduleSpecifier - Root-relative module path used as the stable ID
21
+ * in the Flight wire format (e.g., `'components/Counter.tsx'`).
22
+ * @param exports - All exports extracted from the original module AST.
23
+ * @returns A complete ES module source string ready to feed into Vite's
24
+ * `load` hook.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const source = _generateProxyModule('components/Counter.tsx', [
29
+ * { exportedName: 'default', localName: 'Counter' },
30
+ * { exportedName: 'Badge', localName: 'Badge' },
31
+ * ]);
32
+ * // Returns:
33
+ * // import { registerClientReference } from 'react-server-dom-webpack/server';
34
+ * // export default registerClientReference({}, 'components/Counter.tsx', 'default');
35
+ * // export const Badge = registerClientReference({}, 'components/Counter.tsx', 'Badge');
36
+ * ```
37
+ *
38
+ * @internal
39
+ */
40
+ export function _generateProxyModule(moduleSpecifier, exports) {
41
+ if (exports.length === 0) {
42
+ throw new Error(`[juice/compiler] _generateProxyModule called with zero exports ` +
43
+ `for "${moduleSpecifier}". This is a compiler bug — the transform ` +
44
+ `hook should reject directive modules with no exports before reaching proxy generation.`);
45
+ }
46
+ const lines = [
47
+ `import { registerClientReference } from 'react-server-dom-webpack/server';`,
48
+ '',
49
+ ];
50
+ for (const exp of exports) {
51
+ const ref = `registerClientReference({}, ${JSON.stringify(moduleSpecifier)}, ${JSON.stringify(exp.exportedName)})`;
52
+ if (exp.exportedName === 'default') {
53
+ lines.push(`export default ${ref};`);
54
+ }
55
+ else if (_isValidIdentifier(exp.exportedName)) {
56
+ lines.push(`export const ${exp.exportedName} = ${ref};`);
57
+ }
58
+ else {
59
+ // Non-identifier export names (e.g., "string-name") use re-export syntax
60
+ lines.push(`const _${_safeVarName(exp.exportedName)} = ${ref};`);
61
+ lines.push(`export { _${_safeVarName(exp.exportedName)} as ${JSON.stringify(exp.exportedName)} };`);
62
+ }
63
+ }
64
+ return lines.join('\n') + '\n';
65
+ }
66
+ /**
67
+ * Check whether a string is a valid JS identifier (safe for `export const X`).
68
+ * @internal
69
+ */
70
+ function _isValidIdentifier(name) {
71
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
72
+ }
73
+ /**
74
+ * Convert a non-identifier string to a safe variable name for internal use.
75
+ * @internal
76
+ */
77
+ function _safeVarName(name) {
78
+ return name.replace(/[^a-zA-Z0-9_$]/g, '_');
79
+ }
80
+ //# sourceMappingURL=proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../src/compiler/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,oBAAoB,CAClC,eAAuB,EACvB,OAAgC;IAEhC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,iEAAiE;YACjE,QAAQ,eAAe,4CAA4C;YACnE,wFAAwF,CACzF,CAAC;IACJ,C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client Vite builds via the same plugin
5
+ * instance. The registry is a simple `Map` keyed by the root-relative
6
+ * module specifier.
7
+ *
8
+ * @module registry
9
+ * @internal
10
+ */
11
+ import type { ClientModuleInfo } from './types.js';
12
+ /**
13
+ * Registry tracking all modules that declared `'use client'`.
14
+ *
15
+ * @remarks
16
+ * This map is populated during the `transform` hook of the server build and
17
+ * consumed during the `buildStart` / `generateBundle` hooks of the client build.
18
+ * Because both builds share the same plugin object, the map persists across builds.
19
+ *
20
+ * @internal
21
+ */
22
+ export declare class ClientModuleRegistry {
23
+ private readonly _modules;
24
+ /**
25
+ * Register a client module.
26
+ *
27
+ * @param info - The parsed client module information.
28
+ */
29
+ register(info: ClientModuleInfo): void;
30
+ /**
31
+ * Check if a module specifier has been registered as a client module.
32
+ *
33
+ * @param moduleSpecifier - Root-relative module path.
34
+ */
35
+ has(moduleSpecifier: string): boolean;
36
+ /**
37
+ * Retrieve the info for a registered client module.
38
+ *
39
+ * @param moduleSpecifier - Root-relative module path.
40
+ * @returns The module info, or `undefined` if not registered.
41
+ */
42
+ get(moduleSpecifier: string): ClientModuleInfo | undefined;
43
+ /**
44
+ * Iterate over all registered client modules.
45
+ */
46
+ entries(): IterableIterator<[string, ClientModuleInfo]>;
47
+ /**
48
+ * Number of registered client modules.
49
+ */
50
+ get size(): number;
51
+ /**
52
+ * Clear all registrations. Used between test runs.
53
+ *
54
+ * @internal
55
+ */
56
+ _clear(): void;
57
+ }
58
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/compiler/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;GASG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuC;IAEhE;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI;IAgBtC;;;;OAIG;IACH,GAAG,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO;IAIrC;;;;;OAKG;IACH,GAAG,CAAC,eAAe,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAI1D;;OAEG;IACH,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAIvD;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;OAIG;IACH,MAAM,IAAI,IAAI;CAGf"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * In-memory registry of detected `'use client'` modules.
3
+ *
4
+ * Shared between the server and client Vite builds via the same plugin
5
+ * instance. The registry is a simple `Map` keyed by the root-relative
6
+ * module specifier.
7
+ *
8
+ * @module registry
9
+ * @internal
10
+ */
11
+ /**
12
+ * Registry tracking all modules that declared `'use client'`.
13
+ *
14
+ * @remarks
15
+ * This map is populated during the `transform` hook of the server build and
16
+ * consumed during the `buildStart` / `generateBundle` hooks of the client build.
17
+ * Because both builds share the same plugin object, the map persists across builds.
18
+ *
19
+ * @internal
20
+ */
21
+ export class ClientModuleRegistry {
22
+ _modules = new Map();
23
+ /**
24
+ * Register a client module.
25
+ *
26
+ * @param info - The parsed client module information.
27
+ */
28
+ register(info) {
29
+ if (this._modules.has(info.moduleSpecifier)) {
30
+ // HMR re-processing is expected — only warn in non-HMR contexts
31
+ // (i.e., when the exports change between registrations)
32
+ const existing = this._modules.get(info.moduleSpecifier);
33
+ if (existing.exports.length !== info.exports.length) {
34
+ console.warn(`[juice] Client module "${info.moduleSpecifier}" re-registered ` +
35
+ `with different exports (${existing.exports.length} → ${info.exports.length}). ` +
36
+ `This may indicate a stale build cache.`);
37
+ }
38
+ }
39
+ this._modules.set(info.moduleSpecifier, info);
40
+ }
41
+ /**
42
+ * Check if a module specifier has been registered as a client module.
43
+ *
44
+ * @param moduleSpecifier - Root-relative module path.
45
+ */
46
+ has(moduleSpecifier) {
47
+ return this._modules.has(moduleSpecifier);
48
+ }
49
+ /**
50
+ * Retrieve the info for a registered client module.
51
+ *
52
+ * @param moduleSpecifier - Root-relative module path.
53
+ * @returns The module info, or `undefined` if not registered.
54
+ */
55
+ get(moduleSpecifier) {
56
+ return this._modules.get(moduleSpecifier);
57
+ }
58
+ /**
59
+ * Iterate over all registered client modules.
60
+ */
61
+ entries() {
62
+ return this._modules.entries();
63
+ }
64
+ /**
65
+ * Number of registered client modules.
66
+ */
67
+ get size() {
68
+ return this._modules.size;
69
+ }
70
+ /**
71
+ * Clear all registrations. Used between test runs.
72
+ *
73
+ * @internal
74
+ */
75
+ _clear() {
76
+ this._modules.clear();
77
+ }
78
+ }
79
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/compiler/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;;;;;;;GASG;AACH,MAAM,OAAO,oBAAoB;IACd,QAAQ,GAAG,IAAI,GAAG,EAA4B,CAAC;IAEhE;;;;OAIG;IACH,QAAQ,CAAC,IAAsB;QAC7B,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;YAC5C,gEAAgE;YAChE,wDAAwD;YACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,CAAE,CAAC;YAC1D,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;gBACpD,OAAO,CAAC,IAAI,CACV,0BAA0B,IAAI,CAAC,eAAe,kBAAkB;oBAChE,2BAA2B,QAAQ,CAAC,OAAO,CAAC,MAAM,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK;oBAChF,wCAAwC,CACzC,CAAC;YACJ,CAAC;QACH,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,eAAuB;QACzB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,eAAuB;QACzB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * In-memory registry of detected `'use server'` modules.
3
+ *
4
+ * Mirrors {@link ClientModuleRegistry} but tracks server action modules.
5
+ * Shared between builds via the same plugin instance.
6
+ *
7
+ * @module server-action-registry
8
+ * @internal
9
+ */
10
+ import type { ServerActionInfo } from './types.js';
11
+ /**
12
+ * Registry tracking all modules that declared `'use server'`.
13
+ *
14
+ * @remarks
15
+ * This map is populated during the `transform` hook and consumed during
16
+ * manifest emission. Each entry maps a root-relative module specifier
17
+ * to its server action info.
18
+ *
19
+ * @internal
20
+ */
21
+ export declare class ServerActionRegistry {
22
+ private readonly _modules;
23
+ /**
24
+ * Register a server action module.
25
+ *
26
+ * @param info - The parsed server action module information.
27
+ */
28
+ register(info: ServerActionInfo): void;
29
+ /**
30
+ * Check if a module specifier has been registered as a server action module.
31
+ *
32
+ * @param moduleSpecifier - Root-relative module path.
33
+ */
34
+ has(moduleSpecifier: string): boolean;
35
+ /**
36
+ * Retrieve the info for a registered server action module.
37
+ *
38
+ * @param moduleSpecifier - Root-relative module path.
39
+ * @returns The module info, or `undefined` if not registered.
40
+ */
41
+ get(moduleSpecifier: string): ServerActionInfo | undefined;
42
+ /**
43
+ * Iterate over all registered server action modules.
44
+ */
45
+ entries(): IterableIterator<[string, ServerActionInfo]>;
46
+ /**
47
+ * Number of registered server action modules.
48
+ */
49
+ get size(): number;
50
+ /**
51
+ * Clear all registrations. Used between test runs.
52
+ *
53
+ * @internal
54
+ */
55
+ _clear(): void;
56
+ }
57
+ //# sourceMappingURL=server-action-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-action-registry.d.ts","sourceRoot":"","sources":["../../src/compiler/server-action-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;GASG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuC;IAEhE;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI;IActC;;;;OAIG;IACH,GAAG,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO;IAIrC;;;;;OAKG;IACH,GAAG,CAAC,eAAe,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAI1D;;OAEG;IACH,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAIvD;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;OAIG;IACH,MAAM,IAAI,IAAI;CAGf"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * In-memory registry of detected `'use server'` modules.
3
+ *
4
+ * Mirrors {@link ClientModuleRegistry} but tracks server action modules.
5
+ * Shared between builds via the same plugin instance.
6
+ *
7
+ * @module server-action-registry
8
+ * @internal
9
+ */
10
+ /**
11
+ * Registry tracking all modules that declared `'use server'`.
12
+ *
13
+ * @remarks
14
+ * This map is populated during the `transform` hook and consumed during
15
+ * manifest emission. Each entry maps a root-relative module specifier
16
+ * to its server action info.
17
+ *
18
+ * @internal
19
+ */
20
+ export class ServerActionRegistry {
21
+ _modules = new Map();
22
+ /**
23
+ * Register a server action module.
24
+ *
25
+ * @param info - The parsed server action module information.
26
+ */
27
+ register(info) {
28
+ if (this._modules.has(info.moduleSpecifier)) {
29
+ const existing = this._modules.get(info.moduleSpecifier);
30
+ if (existing.exports.length !== info.exports.length) {
31
+ console.warn(`[juice] Server action module "${info.moduleSpecifier}" re-registered ` +
32
+ `with different exports (${existing.exports.length} → ${info.exports.length}). ` +
33
+ `This may indicate a stale build cache.`);
34
+ }
35
+ }
36
+ this._modules.set(info.moduleSpecifier, info);
37
+ }
38
+ /**
39
+ * Check if a module specifier has been registered as a server action module.
40
+ *
41
+ * @param moduleSpecifier - Root-relative module path.
42
+ */
43
+ has(moduleSpecifier) {
44
+ return this._modules.has(moduleSpecifier);
45
+ }
46
+ /**
47
+ * Retrieve the info for a registered server action module.
48
+ *
49
+ * @param moduleSpecifier - Root-relative module path.
50
+ * @returns The module info, or `undefined` if not registered.
51
+ */
52
+ get(moduleSpecifier) {
53
+ return this._modules.get(moduleSpecifier);
54
+ }
55
+ /**
56
+ * Iterate over all registered server action modules.
57
+ */
58
+ entries() {
59
+ return this._modules.entries();
60
+ }
61
+ /**
62
+ * Number of registered server action modules.
63
+ */
64
+ get size() {
65
+ return this._modules.size;
66
+ }
67
+ /**
68
+ * Clear all registrations. Used between test runs.
69
+ *
70
+ * @internal
71
+ */
72
+ _clear() {
73
+ this._modules.clear();
74
+ }
75
+ }
76
+ //# sourceMappingURL=server-action-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-action-registry.js","sourceRoot":"","sources":["../../src/compiler/server-action-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;;;;;;;;GASG;AACH,MAAM,OAAO,oBAAoB;IACd,QAAQ,GAAG,IAAI,GAAG,EAA4B,CAAC;IAEhE;;;;OAIG;IACH,QAAQ,CAAC,IAAsB;QAC7B,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;YAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,CAAE,CAAC;YAC1D,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;gBACpD,OAAO,CAAC,IAAI,CACV,iCAAiC,IAAI,CAAC,eAAe,kBAAkB;oBACvE,2BAA2B,QAAQ,CAAC,OAAO,CAAC,MAAM,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK;oBAChF,wCAAwC,CACzC,CAAC;YACJ,CAAC;QACH,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,eAAuB;QACzB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,eAAuB;QACzB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Generates client-side proxy modules for `'use server'` actions.
3
+ *
4
+ * When a client component calls a server action, it needs a proxy that
5
+ * serializes the call into a Flight request. This module generates those
6
+ * proxies for the client build.
7
+ *
8
+ * In the **server build**, `'use server'` modules pass through unchanged —
9
+ * they are real functions that execute on the server.
10
+ *
11
+ * In the **client build**, `'use server'` modules are replaced with proxies
12
+ * that call `createServerReference()`, which the React Flight client uses
13
+ * to make server-side RPC calls.
14
+ *
15
+ * @module server-actions
16
+ * @internal
17
+ */
18
+ import type { ExportRecord } from './types.js';
19
+ /**
20
+ * Generate the client-side proxy source code for a `'use server'` module.
21
+ *
22
+ * Each export becomes a `createServerReference()` call that the React
23
+ * Flight client uses to invoke the corresponding server function.
24
+ *
25
+ * @param moduleSpecifier - Root-relative module path used as the stable ID
26
+ * (e.g., `'actions/auth.ts'`).
27
+ * @param exports - All exported server actions extracted from the module AST.
28
+ * @param callServerImport - The import path for the `callServer` function that
29
+ * handles the actual RPC transport. Defaults to the
30
+ * Juice runtime entrypoint.
31
+ * @returns A complete ES module source string for the client build.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * const source = _generateServerActionProxy('actions/auth.ts', [
36
+ * { exportedName: 'login', localName: 'login' },
37
+ * { exportedName: 'logout', localName: 'logout' },
38
+ * ]);
39
+ * // Returns:
40
+ * // import { createServerReference } from 'react-server-dom-webpack/client';
41
+ * // import { callServer } from '@cmj/juice/runtime';
42
+ * // export const login = createServerReference('actions/auth.ts#login', callServer);
43
+ * // export const logout = createServerReference('actions/auth.ts#logout', callServer);
44
+ * ```
45
+ *
46
+ * @internal
47
+ */
48
+ export declare function _generateServerActionProxy(moduleSpecifier: string, exports: readonly ExportRecord[], callServerImport?: string): string;
49
+ //# sourceMappingURL=server-actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-actions.d.ts","sourceRoot":"","sources":["../../src/compiler/server-actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,SAAS,YAAY,EAAE,EAChC,gBAAgB,GAAE,MAA6B,GAC9C,MAAM,CA+BR"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Generates client-side proxy modules for `'use server'` actions.
3
+ *
4
+ * When a client component calls a server action, it needs a proxy that
5
+ * serializes the call into a Flight request. This module generates those
6
+ * proxies for the client build.
7
+ *
8
+ * In the **server build**, `'use server'` modules pass through unchanged —
9
+ * they are real functions that execute on the server.
10
+ *
11
+ * In the **client build**, `'use server'` modules are replaced with proxies
12
+ * that call `createServerReference()`, which the React Flight client uses
13
+ * to make server-side RPC calls.
14
+ *
15
+ * @module server-actions
16
+ * @internal
17
+ */
18
+ /**
19
+ * Generate the client-side proxy source code for a `'use server'` module.
20
+ *
21
+ * Each export becomes a `createServerReference()` call that the React
22
+ * Flight client uses to invoke the corresponding server function.
23
+ *
24
+ * @param moduleSpecifier - Root-relative module path used as the stable ID
25
+ * (e.g., `'actions/auth.ts'`).
26
+ * @param exports - All exported server actions extracted from the module AST.
27
+ * @param callServerImport - The import path for the `callServer` function that
28
+ * handles the actual RPC transport. Defaults to the
29
+ * Juice runtime entrypoint.
30
+ * @returns A complete ES module source string for the client build.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const source = _generateServerActionProxy('actions/auth.ts', [
35
+ * { exportedName: 'login', localName: 'login' },
36
+ * { exportedName: 'logout', localName: 'logout' },
37
+ * ]);
38
+ * // Returns:
39
+ * // import { createServerReference } from 'react-server-dom-webpack/client';
40
+ * // import { callServer } from '@cmj/juice/runtime';
41
+ * // export const login = createServerReference('actions/auth.ts#login', callServer);
42
+ * // export const logout = createServerReference('actions/auth.ts#logout', callServer);
43
+ * ```
44
+ *
45
+ * @internal
46
+ */
47
+ export function _generateServerActionProxy(moduleSpecifier, exports, callServerImport = '@cmj/juice/runtime') {
48
+ if (exports.length === 0) {
49
+ throw new Error(`[juice/compiler] _generateServerActionProxy called with zero exports ` +
50
+ `for "${moduleSpecifier}". This is a compiler bug — the transform ` +
51
+ `hook should reject directive modules with no exports before reaching proxy generation.`);
52
+ }
53
+ const lines = [
54
+ `import { createServerReference } from 'react-server-dom-webpack/client';`,
55
+ `import { callServer } from ${JSON.stringify(callServerImport)};`,
56
+ '',
57
+ ];
58
+ for (const exp of exports) {
59
+ const actionId = `${moduleSpecifier}#${exp.exportedName}`;
60
+ const ref = `createServerReference(${JSON.stringify(actionId)}, callServer)`;
61
+ if (exp.exportedName === 'default') {
62
+ lines.push(`export default ${ref};`);
63
+ }
64
+ else if (_isValidIdentifier(exp.exportedName)) {
65
+ lines.push(`export const ${exp.exportedName} = ${ref};`);
66
+ }
67
+ else {
68
+ const safeName = `_${_safeVarName(exp.exportedName)}`;
69
+ lines.push(`const ${safeName} = ${ref};`);
70
+ lines.push(`export { ${safeName} as ${JSON.stringify(exp.exportedName)} };`);
71
+ }
72
+ }
73
+ return lines.join('\n') + '\n';
74
+ }
75
+ /**
76
+ * Check whether a string is a valid JS identifier.
77
+ * @internal
78
+ */
79
+ function _isValidIdentifier(name) {
80
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
81
+ }
82
+ /**
83
+ * Convert a non-identifier string to a safe variable name.
84
+ * @internal
85
+ */
86
+ function _safeVarName(name) {
87
+ return name.replace(/[^a-zA-Z0-9_$]/g, '_');
88
+ }
89
+ //# sourceMappingURL=server-actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-actions.js","sourceRoot":"","sources":["../../src/compiler/server-actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,0BAA0B,CACxC,eAAuB,EACvB,OAAgC,EAChC,mBAA2B,oBAAoB;IAE/C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,uEAAuE;YAC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