spiceflow 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 (81) hide show
  1. package/README.md +178 -0
  2. package/context.d.ts +2 -0
  3. package/context.js +1 -0
  4. package/dist/babel.test.d.ts +2 -0
  5. package/dist/babel.test.d.ts.map +1 -0
  6. package/dist/babel.test.js +32 -0
  7. package/dist/babel.test.js.map +1 -0
  8. package/dist/babelDebugOutputs.d.ts +9 -0
  9. package/dist/babelDebugOutputs.d.ts.map +1 -0
  10. package/dist/babelDebugOutputs.js +40 -0
  11. package/dist/babelDebugOutputs.js.map +1 -0
  12. package/dist/babelTransformRpc.d.ts +17 -0
  13. package/dist/babelTransformRpc.d.ts.map +1 -0
  14. package/dist/babelTransformRpc.js +304 -0
  15. package/dist/babelTransformRpc.js.map +1 -0
  16. package/dist/browser.d.ts +8 -0
  17. package/dist/browser.d.ts.map +1 -0
  18. package/dist/browser.js +133 -0
  19. package/dist/browser.js.map +1 -0
  20. package/dist/build.d.ts +10 -0
  21. package/dist/build.d.ts.map +1 -0
  22. package/dist/build.js +253 -0
  23. package/dist/build.js.map +1 -0
  24. package/dist/cli.d.ts +3 -0
  25. package/dist/cli.d.ts.map +1 -0
  26. package/dist/cli.js +108 -0
  27. package/dist/cli.js.map +1 -0
  28. package/dist/context-internal.d.ts +20 -0
  29. package/dist/context-internal.d.ts.map +1 -0
  30. package/dist/context-internal.js +22 -0
  31. package/dist/context-internal.js.map +1 -0
  32. package/dist/context.d.ts +2 -0
  33. package/dist/context.d.ts.map +1 -0
  34. package/dist/context.js +8 -0
  35. package/dist/context.js.map +1 -0
  36. package/dist/expose.d.ts +6 -0
  37. package/dist/expose.d.ts.map +1 -0
  38. package/dist/expose.js +39 -0
  39. package/dist/expose.js.map +1 -0
  40. package/dist/headers.d.ts +1 -0
  41. package/dist/headers.d.ts.map +1 -0
  42. package/dist/headers.js +18 -0
  43. package/dist/headers.js.map +1 -0
  44. package/dist/index.d.ts +8 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +55 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/jsonRpc.d.ts +32 -0
  49. package/dist/jsonRpc.d.ts.map +1 -0
  50. package/dist/jsonRpc.js +4 -0
  51. package/dist/jsonRpc.js.map +1 -0
  52. package/dist/server.d.ts +32 -0
  53. package/dist/server.d.ts.map +1 -0
  54. package/dist/server.js +301 -0
  55. package/dist/server.js.map +1 -0
  56. package/dist/utils.d.ts +20 -0
  57. package/dist/utils.d.ts.map +1 -0
  58. package/dist/utils.js +44 -0
  59. package/dist/utils.js.map +1 -0
  60. package/headers.d.ts +2 -0
  61. package/headers.js +1 -0
  62. package/package.json +56 -0
  63. package/sdk-template/package.json +22 -0
  64. package/sdk-template/src/index.ts +2 -0
  65. package/sdk-template/src/v1/example.ts +5 -0
  66. package/sdk-template/src/v1/generator.ts +12 -0
  67. package/sdk-template/tsconfig.json +16 -0
  68. package/src/babel.test.ts +35 -0
  69. package/src/babelDebugOutputs.ts +56 -0
  70. package/src/babelTransformRpc.ts +404 -0
  71. package/src/browser.ts +142 -0
  72. package/src/build.ts +303 -0
  73. package/src/cli.ts +118 -0
  74. package/src/context-internal.ts +36 -0
  75. package/src/context.ts +1 -0
  76. package/src/expose.ts +34 -0
  77. package/src/headers.ts +19 -0
  78. package/src/index.ts +42 -0
  79. package/src/jsonRpc.ts +43 -0
  80. package/src/server.ts +384 -0
  81. package/src/utils.ts +61 -0
package/README.md ADDED
@@ -0,0 +1,178 @@
1
+ <div align='center'>
2
+ <br/>
3
+ <br/>
4
+ <br/>
5
+ <h3>spiceflow</h3>
6
+ <br/>
7
+ <p>If GraphQL, JSON-RPC and React server actions had a baby, it would be called spiceflow</p>
8
+ <br/>
9
+ <br/>
10
+
11
+ </div>
12
+
13
+ Spiceflow is the fastest way to write and expose an RPC API. In Spiceflow any files with the directive `'use spiceflow'` will be processed as an API route, each function defined in the file will be exposed as an JSON-RPC method.
14
+
15
+ After defining your functions you can call `spiceflow serve` to start a server exposing your API, you can also espose the API using the Next.js or your own server.
16
+
17
+ When calling `spiceflow build` spiceflow will generate a client side SDK for your API, you can use it to call your API from the browser. This client SDK will be type safe, because the functions are called the same way from the server and the client, so types can be reused (after being bundled with @microsoft/api-extractor).
18
+
19
+ You can publish this SDK to npm and let your users interact with your API in an easy and type safe way.
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm i spiceflow
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```bash
30
+ # create a new spiceflow project, works best in a monorepo
31
+ npx spiceflow init --name my-api
32
+ tree
33
+ .
34
+ ├── package.json
35
+ ├── src
36
+ │ ├── index.ts
37
+ │ └── v1
38
+ │ ├── example.ts
39
+ │ └── generator.ts
40
+ └── tsconfig.json
41
+
42
+ npm run serve # builds the sdk in the dist folder and starts serving your API
43
+ npm run try-sdk # try using the sdk
44
+ ```
45
+
46
+ ## Writing your API functions
47
+
48
+ Any functions exported in a file with the `'use spiceflow'` directive will be processed as an API route, each function defined in the file will be exposed as an JSON-RPC method.
49
+
50
+ ```ts
51
+ // src/v1/functions.ts
52
+ 'use spiceflow';
53
+
54
+ export async function spiceflowFunction() {
55
+ return { hello: 'world' };
56
+ }
57
+
58
+ export async function* spiceflowGenerator() {
59
+ for (let i = 0; i < 10; i++) {
60
+ await sleep(300);
61
+ yield { i };
62
+ }
63
+ }
64
+
65
+ function sleep(ms: number) {
66
+ return new Promise((resolve) => setTimeout(resolve, ms));
67
+ }
68
+ ```
69
+
70
+ Expose the server
71
+
72
+ ```bash
73
+ spiceflow serve --watch
74
+ ```
75
+
76
+ Call your function from the client, these will use fetch to call the server
77
+
78
+ ```ts
79
+ import {
80
+ spiceflowFunction,
81
+ spiceflowGenerator,
82
+ } from './my-api/dist/v1/functions';
83
+
84
+ // will call the server with fetch
85
+ const { hello } = await spiceflowFunction();
86
+
87
+ for await (const { i } of spiceflowGenerator()) {
88
+ console.log(i);
89
+ }
90
+ ```
91
+
92
+ ## Serving your API
93
+
94
+ Spiceflow has 3 ways to serve your API:
95
+
96
+ ### Built-in Node.js server
97
+
98
+ ```
99
+ spiceflow serve --port 3333
100
+ ```
101
+
102
+ ### Next.js pages API handler
103
+
104
+ > Note: You will need to call `spiceflow build` before using the SDK when using this method
105
+
106
+ ```tsx
107
+ // pages/api/spiceflow/[...slug].tsx
108
+ import { nodeJsHandler } from './my-api/server';
109
+
110
+ export default async function handler(req, res) {
111
+ return await nodeJsHandler({ req, res, basePath: '/api/spiceflow' });
112
+ }
113
+ ```
114
+
115
+ ### Next.js app API route
116
+
117
+ ```tsx
118
+ // pages/api/spiceflow/[...slug]/route.tsx
119
+ import { edgeHandler } from './my-api/server';
120
+
121
+ export const POST = edgeHandler;
122
+ ```
123
+
124
+ After exposing your server you will need to rebuild your client sdk using that url:
125
+
126
+ ```bash
127
+ spiceflow build --url http://localhost:3000/api/spiceflow # the Next.js app url
128
+ ```
129
+
130
+ ## Accessing the request and response objects
131
+
132
+ This plugin injects the `req` and `res` objects in an `AsyncLocalStorage` context, so you can access them in your server functions:
133
+
134
+ Edge function example:
135
+
136
+ ```ts
137
+ 'use spiceflow';
138
+
139
+ import { getNodejsContext } from 'spiceflow/context';
140
+
141
+ export async function serverAction({}) {
142
+ const { req } = getNodejsContext();
143
+ const host = req?.headers.get('host');
144
+ return { host };
145
+ }
146
+ ```
147
+
148
+ ## Adding error logging and handling
149
+
150
+ You can export a function named `wrapMethod` to easily wrap all your server actions with error logging or other wrappers
151
+
152
+ ```ts
153
+ 'use spiceflow';
154
+
155
+ export function wrapMethod(fn) {
156
+ return async (...args) => {
157
+ try {
158
+ const res = await fn(...args);
159
+ return res;
160
+ } catch (error) {
161
+ console.error(error);
162
+ throw error;
163
+ }
164
+ };
165
+ }
166
+
167
+ export async function failingFunction({}) {
168
+ throw new Error('This function fails');
169
+ }
170
+ ```
171
+
172
+ ## Versioning
173
+
174
+ You can create a `v1` folder in your project and exports your function from `index.ts`, when you want to release a breaking version of your API, you can create a new folder and change the imports in `index.ts` file. This way the sdk users will always use the latest version of your API, while old SDK users will keep the old version.
175
+
176
+ ## How it works
177
+
178
+ Spiceflow `build` command transpiles the files with the `use spiceflow` directive so that any exported function will use fetch to send arguments and get the result, the the transformed files are saved in the `dist` folder. Other files are compiled to the dist directory using `tsc`. Spiceflow also bundles the type definitions with `@microsoft/api-extractor` so the generated dist files don't rely on external local packages and can be safely published to npm.
package/context.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import * as context from './dist/context';
2
+ export = context;
package/context.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/context');
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=babel.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel.test.d.ts","sourceRoot":"","sources":["../src/babel.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const vitest_1 = require("vitest");
7
+ const parser_1 = require("@babel/parser");
8
+ const generator_1 = __importDefault(require("@babel/generator"));
9
+ // import { parseExpression } from './utils';
10
+ (0, vitest_1.test)('parseExpression', () => {
11
+ {
12
+ const parsed = (0, parser_1.parseExpression)('{ "type": "StringLiteral", "value": "/api/actions-node" }');
13
+ const code = (0, generator_1.default)(parsed).code;
14
+ (0, vitest_1.expect)(code).toMatchInlineSnapshot(`
15
+ "{
16
+ "type": "StringLiteral",
17
+ "value": "/api/actions-node"
18
+ }"
19
+ `);
20
+ }
21
+ {
22
+ const parsed = (0, parser_1.parseExpression)('null');
23
+ const code = (0, generator_1.default)(parsed).code;
24
+ (0, vitest_1.expect)(code).toMatchInlineSnapshot(`"null"`);
25
+ }
26
+ {
27
+ const parsed = (0, parser_1.parseExpression)(`typeof wrapMethod === 'function' ? wrapMethod : undefined`);
28
+ const code = (0, generator_1.default)(parsed).code;
29
+ (0, vitest_1.expect)(code).toMatchInlineSnapshot(`"typeof wrapMethod === 'function' ? wrapMethod : undefined"`);
30
+ }
31
+ });
32
+ //# sourceMappingURL=babel.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel.test.js","sourceRoot":"","sources":["../src/babel.test.ts"],"names":[],"mappings":";;;;;AAAA,mCAAgD;AAChD,0CAAgD;AAChD,iEAAwC;AAGxC,6CAA6C;AAE7C,IAAA,aAAI,EAAC,iBAAiB,EAAE,GAAG,EAAE;IAC3B,CAAC;QACC,MAAM,MAAM,GAAG,IAAA,wBAAe,EAC5B,2DAA2D,CAC5D,CAAC;QACF,MAAM,IAAI,GAAG,IAAA,mBAAQ,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC;QACnC,IAAA,eAAM,EAAC,IAAI,CAAC,CAAC,qBAAqB,CAAC;;;;;KAKlC,CAAC,CAAC;IACL,CAAC;IACD,CAAC;QACC,MAAM,MAAM,GAAG,IAAA,wBAAe,EAAC,MAAM,CAAC,CAAC;QACvC,MAAM,IAAI,GAAG,IAAA,mBAAQ,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC;QACnC,IAAA,eAAM,EAAC,IAAI,CAAC,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IACD,CAAC;QACC,MAAM,MAAM,GAAG,IAAA,wBAAe,EAC5B,2DAA2D,CAC5D,CAAC;QACF,MAAM,IAAI,GAAG,IAAA,mBAAQ,EAAC,MAAM,CAAC,CAAC,IAAI,CAAC;QACnC,IAAA,eAAM,EAAC,IAAI,CAAC,CAAC,qBAAqB,CAChC,6DAA6D,CAC9D,CAAC;IACJ,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import * as babel from '@babel/core';
2
+ import * as types from '@babel/types';
3
+ import { PluginOptions } from './babelTransformRpc';
4
+ type Babel = {
5
+ types: typeof types;
6
+ };
7
+ export default function debugOutputsPlugin({ types: t }: Babel, { isServer }: PluginOptions): babel.PluginObj | undefined;
8
+ export {};
9
+ //# sourceMappingURL=babelDebugOutputs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babelDebugOutputs.d.ts","sourceRoot":"","sources":["../src/babelDebugOutputs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,aAAa,CAAC;AAErC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKpD,KAAK,KAAK,GAAG;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,CAAC;AAIrC,MAAM,CAAC,OAAO,UAAU,kBAAkB,CACxC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EACnB,EAAE,QAAQ,EAAE,EAAE,aAAa,GAC1B,KAAK,CAAC,SAAS,GAAG,SAAS,CAuC7B"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const generator_1 = __importDefault(require("@babel/generator"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const utils_1 = require("./utils");
10
+ let deletedDir = false;
11
+ function debugOutputsPlugin({ types: t }, { isServer }) {
12
+ const cwd = process.cwd();
13
+ if (!deletedDir) {
14
+ deletedDir = true;
15
+ fs_1.default.mkdirSync('./actions-outputs', { recursive: true });
16
+ }
17
+ return {
18
+ visitor: {
19
+ Program: {
20
+ exit(program, state) {
21
+ var _a;
22
+ const filePath = (_a = (0, utils_1.getFileName)(state)) !== null && _a !== void 0 ? _a : path_1.default.join('pages', 'Default.js');
23
+ if (!process.env.DEBUG_ACTIONS) {
24
+ return;
25
+ }
26
+ // stringify the AST and print it
27
+ const output = (0, generator_1.default)(program.node, {
28
+ /* options */
29
+ }, this.file.code);
30
+ let p = path_1.default.resolve('./actions-outputs', isServer ? 'server/' : 'client/', path_1.default.relative(cwd, path_1.default.resolve(filePath)));
31
+ utils_1.logger.log(`${isServer ? 'server' : 'client'} plugin output:`, p);
32
+ fs_1.default.mkdirSync(path_1.default.dirname(p), { recursive: true });
33
+ fs_1.default.writeFileSync(p, output.code);
34
+ },
35
+ },
36
+ },
37
+ };
38
+ }
39
+ exports.default = debugOutputsPlugin;
40
+ //# sourceMappingURL=babelDebugOutputs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babelDebugOutputs.js","sourceRoot":"","sources":["../src/babelDebugOutputs.ts"],"names":[],"mappings":";;;;;AACA,iEAAwC;AAExC,4CAAoB;AAEpB,gDAA4D;AAE5D,mCAA8C;AAI9C,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB,SAAwB,kBAAkB,CACxC,EAAE,KAAK,EAAE,CAAC,EAAS,EACnB,EAAE,QAAQ,EAAiB;IAE3B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAE1B,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,UAAU,GAAG,IAAI,CAAC;QAElB,YAAE,CAAC,SAAS,CAAC,mBAAmB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;IACD,OAAO;QACL,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,IAAI,CAAC,OAAO,EAAE,KAAK;;oBACjB,MAAM,QAAQ,GACZ,MAAA,IAAA,mBAAW,EAAC,KAAK,CAAC,mCAAI,cAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;oBAE7D,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;wBAC/B,OAAO;oBACT,CAAC;oBAED,iCAAiC;oBACjC,MAAM,MAAM,GAAG,IAAA,mBAAQ,EACrB,OAAO,CAAC,IAAI,EACZ;oBACE,aAAa;qBACd,EACD,IAAI,CAAC,IAAI,CAAC,IAAI,CACf,CAAC;oBACF,IAAI,CAAC,GAAG,cAAI,CAAC,OAAO,CAClB,mBAAmB,EACnB,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAChC,cAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAC3C,CAAC;oBACF,cAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,iBAAiB,EAAE,CAAC,CAAC,CAAC;oBAClE,YAAE,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;oBACnD,YAAE,CAAC,aAAa,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;gBACnC,CAAC;aACF;SACF;KACF,CAAC;AACJ,CAAC;AA1CD,qCA0CC"}
@@ -0,0 +1,17 @@
1
+ import * as babel from '@babel/core';
2
+ import type * as types from '@babel/types';
3
+ type Babel = {
4
+ types: typeof types;
5
+ };
6
+ export declare function getConfigObject(program: babel.NodePath<babel.types.Program>): {
7
+ isEdge: boolean;
8
+ } | undefined;
9
+ export declare function isEdgeInConfig(configObject?: babel.NodePath<babel.types.ObjectExpression>): boolean;
10
+ export interface PluginOptions {
11
+ isServer: boolean;
12
+ rootDir: string;
13
+ url?: string;
14
+ }
15
+ export default function ({ types: t }: Babel, { rootDir, isServer, url: rpcUrl }: PluginOptions): babel.PluginObj;
16
+ export {};
17
+ //# sourceMappingURL=babelTransformRpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babelTransformRpc.d.ts","sourceRoot":"","sources":["../src/babelTransformRpc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,aAAa,CAAC;AAGrC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAM3C,KAAK,KAAK,GAAG;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,CAAC;AAmDrC,wBAAgB,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC;;cAe3E;AAmDD,wBAAgB,cAAc,CAC5B,YAAY,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,GAC1D,OAAO,CAoBT;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAEhB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,CAAC,OAAO,WACZ,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EACnB,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,aAAa,GAChD,KAAK,CAAC,SAAS,CAmPjB"}
@@ -0,0 +1,304 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isEdgeInConfig = exports.getConfigObject = void 0;
7
+ const parser_1 = require("@babel/parser");
8
+ const path_1 = __importDefault(require("path"));
9
+ const utils_1 = require("./utils");
10
+ const { name } = require('../package.json');
11
+ const IMPORT_PATH_SERVER = `${name}/dist/server.js`;
12
+ const IMPORT_PATH_BROWSER = `${name}/dist/browser.js`;
13
+ function isAllowedTsExportDeclaration(declaration) {
14
+ return (declaration.isTSTypeAliasDeclaration() ||
15
+ declaration.isTSInterfaceDeclaration());
16
+ }
17
+ const allowedExports = new Set([
18
+ 'revalidate', //
19
+ 'preferredRegion',
20
+ 'runtime',
21
+ 'maxDuration',
22
+ 'fetchCache',
23
+ 'dynamic',
24
+ 'dynamicParams',
25
+ 'GET',
26
+ 'HEAD',
27
+ ]);
28
+ function getConfigObjectExpression(variable) {
29
+ const identifier = variable.get('id');
30
+ const init = variable.get('init');
31
+ if (identifier.isIdentifier() &&
32
+ identifier.node.name === 'config' &&
33
+ init.isObjectExpression()) {
34
+ const isEdge = isEdgeInConfig(init);
35
+ return {
36
+ isEdge,
37
+ };
38
+ }
39
+ if (identifier.isIdentifier() && identifier.node.name === 'runtime') {
40
+ const isEdge = init.isStringLiteral({ value: 'edge' });
41
+ return {
42
+ isEdge,
43
+ };
44
+ }
45
+ return null;
46
+ }
47
+ function getConfigObject(program) {
48
+ for (const statement of program.get('body')) {
49
+ if (statement.isExportNamedDeclaration()) {
50
+ const declaration = statement.get('declaration');
51
+ if (declaration.isVariableDeclaration()) {
52
+ for (const variable of declaration.get('declarations')) {
53
+ const configObject = getConfigObjectExpression(variable);
54
+ if (configObject) {
55
+ return configObject;
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ return;
62
+ }
63
+ exports.getConfigObject = getConfigObject;
64
+ function isServerAction(program) {
65
+ var _a;
66
+ const dir = (_a = program.node.directives) === null || _a === void 0 ? void 0 : _a.find((x) => { var _a; return ((_a = x.value) === null || _a === void 0 ? void 0 : _a.value) === utils_1.directive; });
67
+ return !!dir;
68
+ // https://regex101.com/r/Wm6UvV/1
69
+ // return /^("|')poor man's use server("|')(;?)\n/m.test(code);
70
+ }
71
+ function hasWrapMethod(program) {
72
+ var _a;
73
+ // check if there is a function export called wrapMethod
74
+ for (const statement of program.get('body')) {
75
+ // also check the export { wrapMethod }
76
+ if (statement.isExportNamedDeclaration()) {
77
+ for (const specifier of statement.get('specifiers')) {
78
+ if (specifier.node.exported.type === 'Identifier' &&
79
+ specifier.node.exported.name === 'wrapMethod') {
80
+ return true;
81
+ }
82
+ }
83
+ }
84
+ if (statement.isExportNamedDeclaration()) {
85
+ const declaration = statement.get('declaration');
86
+ if (declaration.isFunctionDeclaration()) {
87
+ const identifier = declaration.get('id');
88
+ if (((_a = identifier.node) === null || _a === void 0 ? void 0 : _a.name) === 'wrapMethod') {
89
+ return true;
90
+ }
91
+ }
92
+ else if (declaration.isVariableDeclaration()) {
93
+ for (const variable of declaration.get('declarations')) {
94
+ const id = variable.get('id');
95
+ if (id.isIdentifier() && id.node.name === 'wrapMethod') {
96
+ return true;
97
+ }
98
+ }
99
+ }
100
+ }
101
+ }
102
+ // return (
103
+ // /export\s+function\s+wrapMethod\s*\(/m.test(code) ||
104
+ // /export\s+(let|const)\s+wrapMethod\s*/m.test(code) ||
105
+ // // https://regex101.com/r/nRaEVs/1
106
+ // /export\s+\{[^}]*wrapMethod/m.test(code)
107
+ // );
108
+ }
109
+ function isEdgeInConfig(configObject) {
110
+ if (!configObject) {
111
+ return false;
112
+ }
113
+ for (const property of configObject.get('properties')) {
114
+ if (!property.isObjectProperty()) {
115
+ continue;
116
+ }
117
+ const key = property.get('key');
118
+ const value = property.get('value');
119
+ if (property.isObjectProperty() &&
120
+ key.isIdentifier({ name: 'runtime' }) &&
121
+ value.isStringLiteral({ value: 'edge' })) {
122
+ return true;
123
+ }
124
+ }
125
+ return false;
126
+ }
127
+ exports.isEdgeInConfig = isEdgeInConfig;
128
+ function default_1({ types: t }, { rootDir, isServer, url: rpcUrl }) {
129
+ return {
130
+ visitor: {
131
+ Program(program) {
132
+ var _a, _b, _c;
133
+ const { filename } = this.file.opts;
134
+ if (!filename) {
135
+ return;
136
+ }
137
+ const { isEdge } = getConfigObject(program) || {
138
+ isEdge: false,
139
+ };
140
+ const isAction = isServerAction(program);
141
+ if (!isAction) {
142
+ utils_1.logger.log(`Skipping ${filename} because it's not an action`);
143
+ return;
144
+ }
145
+ utils_1.logger.log(`Processing ${filename} as a ${isServer ? 'server' : 'client'} action`);
146
+ const hasWrap = hasWrapMethod(program);
147
+ const rel = path_1.default.relative(rootDir, filename);
148
+ const rpcRelativePath = rel
149
+ .replace(/\.[j|t]sx?$/, '')
150
+ // remove /pages at the start
151
+ .replace(/^src\//, '')
152
+ .replace(/\/index$/, '');
153
+ let rpcPath = rpcUrl
154
+ ? new URL(rpcRelativePath, rpcUrl).toString()
155
+ : '/' + rpcRelativePath;
156
+ const rpcMethodNames = [];
157
+ const createRpcMethodIdentifier = program.scope.generateUidIdentifier('createRpcMethod');
158
+ const createRpcMethod = (rpcMethod, meta) => {
159
+ return t.callExpression(createRpcMethodIdentifier, [
160
+ rpcMethod,
161
+ (0, parser_1.parseExpression)(JSON.stringify(meta)),
162
+ (0, parser_1.parseExpression)(hasWrap
163
+ ? `typeof wrapMethod === 'function' ? wrapMethod : undefined`
164
+ : 'null'),
165
+ ]);
166
+ };
167
+ const generators = new Map();
168
+ for (const statement of program.get('body')) {
169
+ if (statement.isExportNamedDeclaration()) {
170
+ // check if function is async generator
171
+ const declaration = statement.get('declaration');
172
+ if (isAllowedTsExportDeclaration(declaration)) {
173
+ // ignore
174
+ }
175
+ else if (declaration.isFunctionDeclaration()) {
176
+ const identifier = declaration.get('id');
177
+ const methodName = (_a = identifier.node) === null || _a === void 0 ? void 0 : _a.name;
178
+ if (methodName === 'wrapMethod') {
179
+ continue;
180
+ }
181
+ const isGenerator = !!declaration.node.generator;
182
+ generators.set(methodName, isGenerator);
183
+ if (!declaration.node.async) {
184
+ throw declaration.buildCodeFrameError('rpc exports must be async functions');
185
+ }
186
+ if (methodName) {
187
+ rpcMethodNames.push(methodName);
188
+ if (isServer) {
189
+ // replace with wrapped
190
+ statement.replaceWith(t.exportNamedDeclaration(t.variableDeclaration('const', [
191
+ t.variableDeclarator(t.identifier(methodName), createRpcMethod(t.toExpression(declaration.node), {
192
+ name: methodName,
193
+ pathname: rpcPath,
194
+ isGenerator,
195
+ })),
196
+ ])));
197
+ }
198
+ }
199
+ }
200
+ else if (declaration.isVariableDeclaration() &&
201
+ declaration.node.kind === 'const') {
202
+ for (const variable of declaration.get('declarations')) {
203
+ const init = variable.get('init');
204
+ if (getConfigObjectExpression(variable)) {
205
+ continue;
206
+ }
207
+ const node = variable.get('id');
208
+ if (node.isIdentifier() && allowedExports.has(node.node.name)) {
209
+ continue;
210
+ }
211
+ if (getConfigObjectExpression(variable)) {
212
+ // ignore, this is the only allowed non-function export
213
+ continue;
214
+ }
215
+ if (init.isFunctionExpression() ||
216
+ init.isArrowFunctionExpression()) {
217
+ const { id } = variable.node;
218
+ if (t.isIdentifier(id)) {
219
+ const methodName = id.name;
220
+ if (methodName === 'wrapMethod') {
221
+ continue;
222
+ }
223
+ }
224
+ if (!init.node.async) {
225
+ throw init.buildCodeFrameError('rpc exports must be async functions');
226
+ }
227
+ if (t.isIdentifier(id)) {
228
+ const methodName = id.name;
229
+ if (methodName === 'wrapMethod') {
230
+ continue;
231
+ }
232
+ const isGenerator = !!init.node.generator;
233
+ generators.set(methodName, isGenerator);
234
+ rpcMethodNames.push(methodName);
235
+ if (isServer) {
236
+ init.replaceWith(createRpcMethod(init.node, {
237
+ name: methodName,
238
+ pathname: rpcPath,
239
+ isGenerator,
240
+ }));
241
+ }
242
+ }
243
+ }
244
+ else {
245
+ throw variable.buildCodeFrameError('rpc exports must be static functions');
246
+ }
247
+ }
248
+ }
249
+ else {
250
+ for (const specifier of statement.get('specifiers')) {
251
+ if (((_b = specifier === null || specifier === void 0 ? void 0 : specifier.node) === null || _b === void 0 ? void 0 : _b.exported.type) === 'Identifier' &&
252
+ ((_c = specifier === null || specifier === void 0 ? void 0 : specifier.node) === null || _c === void 0 ? void 0 : _c.exported.name) === 'wrapMethod') {
253
+ continue;
254
+ }
255
+ throw specifier.buildCodeFrameError('rpc exports must be static functions');
256
+ }
257
+ }
258
+ }
259
+ else if (statement.isExportDefaultDeclaration()) {
260
+ throw statement.buildCodeFrameError('default exports are not allowed in rpc routes');
261
+ }
262
+ }
263
+ if (!isServer) {
264
+ const createRpcFetcherIdentifier = program.scope.generateUidIdentifier('createRpcFetcher');
265
+ // Clear the whole body
266
+ out: for (const statement of program.get('body')) {
267
+ // don't remove if it's an export with name is config or runtime
268
+ if (statement.isExportNamedDeclaration()) {
269
+ const declaration = statement.get('declaration');
270
+ if (declaration.isVariableDeclaration()) {
271
+ for (const variable of declaration.get('declarations')) {
272
+ const configObject = getConfigObjectExpression(variable);
273
+ if (configObject) {
274
+ continue out;
275
+ }
276
+ }
277
+ }
278
+ }
279
+ statement.remove();
280
+ }
281
+ program.pushContainer('body', [
282
+ t.importDeclaration([
283
+ t.importSpecifier(createRpcFetcherIdentifier, t.identifier('createRpcFetcher')),
284
+ ], t.stringLiteral(IMPORT_PATH_BROWSER)),
285
+ ...rpcMethodNames.map((name) => {
286
+ const isGenerator = !!generators.get(name);
287
+ return t.exportNamedDeclaration(t.variableDeclaration('const', [
288
+ t.variableDeclarator(t.identifier(name), (0, utils_1.annotateAsPure)(t, t.callExpression(createRpcFetcherIdentifier, [
289
+ (0, parser_1.parseExpression)(JSON.stringify({
290
+ url: rpcPath,
291
+ method: name,
292
+ isGenerator,
293
+ })),
294
+ ]))),
295
+ ]));
296
+ }),
297
+ ]);
298
+ }
299
+ },
300
+ },
301
+ };
302
+ }
303
+ exports.default = default_1;
304
+ //# sourceMappingURL=babelTransformRpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babelTransformRpc.js","sourceRoot":"","sources":["../src/babelTransformRpc.ts"],"names":[],"mappings":";;;;;;AAEA,0CAAgD;AAGhD,gDAAwB;AAExB,mCAA4D;AAI5D,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAC5C,MAAM,kBAAkB,GAAG,GAAG,IAAI,iBAAiB,CAAC;AACpD,MAAM,mBAAmB,GAAG,GAAG,IAAI,kBAAkB,CAAC;AAEtD,SAAS,4BAA4B,CACnC,WAAuE;IAEvE,OAAO,CACL,WAAW,CAAC,wBAAwB,EAAE;QACtC,WAAW,CAAC,wBAAwB,EAAE,CACvC,CAAC;AACJ,CAAC;AAED,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,YAAY,EAAE,EAAE;IAChB,iBAAiB;IACjB,SAAS;IACT,aAAa;IACb,YAAY;I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,EACD,CAAC,CAAC,aAAa,CAAC,mBAAmB,CAAC,CACrC;wBACD,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;4BAC7B,MAAM,WAAW,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;4BAC3C,OAAO,CAAC,CAAC,sBAAsB,CAC7B,CAAC,CAAC,mBAAmB,CAAC,OAAO,EAAE;gCAC7B,CAAC,CAAC,kBAAkB,CAClB,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAClB,IAAA,sBAAc,EACZ,CAAC,EACD,CAAC,CAAC,cAAc,CAAC,0BAA0B,EAAE;oCAC3C,IAAA,wBAAe,EACb,IAAI,CAAC,SAAS,CAAC;wCACb,GAAG,EAAE,OAAO;wCACZ,MAAM,EAAE,IAAI;wCACZ,WAAW;qCACZ,CAAC,CACH;iCACF,CAAC,CACH,CACF;6BACF,CAAC,CACH,CAAC;wBACJ,CAAC,CAAC;qBACH,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AAtPD,4BAsPC"}
@@ -0,0 +1,8 @@
1
+ type NextRpcCall = (...params: any[]) => any | AsyncGenerator<any>;
2
+ export declare function createRpcFetcher({ url, method, isGenerator, }: {
3
+ url: string;
4
+ method: string;
5
+ isGenerator?: boolean;
6
+ }): NextRpcCall;
7
+ export {};
8
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAMA,KAAK,WAAW,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;AAInE,wBAAgB,gBAAgB,CAAC,EAC/B,GAAG,EACH,MAAM,EACN,WAAW,GACZ,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,GAAG,WAAW,CAuGd"}