spiceflow 0.0.1 → 0.0.3
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.
- package/README.md +20 -18
- package/context.js +1 -1
- package/dist/babel.test.js +13 -18
- package/dist/babel.test.js.map +1 -1
- package/dist/babelDebugOutputs.d.ts +1 -1
- package/dist/babelDebugOutputs.d.ts.map +1 -1
- package/dist/babelDebugOutputs.js +12 -18
- package/dist/babelDebugOutputs.js.map +1 -1
- package/dist/babelTransformRpc.d.ts +3 -1
- package/dist/babelTransformRpc.d.ts.map +1 -1
- package/dist/babelTransformRpc.js +17 -27
- package/dist/babelTransformRpc.js.map +1 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +8 -15
- package/dist/browser.js.map +1 -1
- package/dist/build.d.ts +9 -9
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +101 -84
- package/dist/build.js.map +1 -1
- package/dist/cli.js +30 -33
- package/dist/cli.js.map +1 -1
- package/dist/context-internal.js +8 -14
- package/dist/context-internal.js.map +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -7
- package/dist/context.js.map +1 -1
- package/dist/expose.js +5 -12
- package/dist/expose.js.map +1 -1
- package/dist/headers.d.ts +1 -0
- package/dist/headers.js +1 -1
- package/dist/headers.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -44
- package/dist/index.js.map +1 -1
- package/dist/jsonRpc.js +1 -2
- package/dist/jsonRpc.js.map +1 -1
- package/dist/server.js +12 -21
- package/dist/server.js.map +1 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +16 -12
- package/dist/utils.js.map +1 -1
- package/headers.js +1 -1
- package/package.json +3 -2
- package/src/babelDebugOutputs.ts +2 -2
- package/src/babelTransformRpc.ts +8 -8
- package/src/browser.ts +1 -2
- package/src/build.ts +80 -33
- package/src/cli.ts +9 -2
- package/src/context.ts +5 -1
- package/src/expose.ts +1 -1
- package/src/index.ts +12 -20
- package/src/server.ts +3 -3
- package/src/utils.ts +15 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { PluginOptions } from './babelTransformRpc';
|
|
2
|
-
import { WrapMethod } from './server';
|
|
1
|
+
import { PluginOptions } from './babelTransformRpc.js';
|
|
2
|
+
import { WrapMethod } from './server.js';
|
|
3
3
|
export interface WithRpcConfig {
|
|
4
4
|
}
|
|
5
5
|
export { WrapMethod };
|
|
6
|
-
export declare function plugins(
|
|
6
|
+
export declare function plugins(options: PluginOptions): any[];
|
|
7
7
|
export declare function findRootDir(dir: string): string;
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAkB,MAAM,aAAa,CAAC;AAEzD,MAAM,WAAW,aAAa;CAAG;AAEjC,OAAO,EAAE,UAAU,EAAE,CAAC;AAOtB,wBAAgB,OAAO,CAAC,OAAO,EAAE,aAAa,SAO7C;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAS/C"}
|
package/dist/index.js
CHANGED
|
@@ -1,49 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.findRootDir = exports.plugins = void 0;
|
|
27
|
-
const fs = __importStar(require("fs"));
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
|
-
function plugins({ isServer, rootDir: nextDir, url, }) {
|
|
30
|
-
const rpcPluginOptions = {
|
|
31
|
-
isServer,
|
|
32
|
-
rootDir: nextDir,
|
|
33
|
-
url,
|
|
34
|
-
};
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import pluginSyntaxJsx from '@babel/plugin-syntax-jsx';
|
|
4
|
+
import pluginTransformTypescript from '@babel/plugin-transform-typescript';
|
|
5
|
+
import babelTransformRpc from './babelTransformRpc.js';
|
|
6
|
+
import babelDebugOutputs from './babelDebugOutputs.js';
|
|
7
|
+
export function plugins(options) {
|
|
35
8
|
return [
|
|
36
|
-
|
|
37
|
-
[
|
|
38
|
-
[
|
|
39
|
-
process.env.DEBUG_ACTIONS && [
|
|
40
|
-
require.resolve('../dist/babelDebugOutputs'),
|
|
41
|
-
rpcPluginOptions,
|
|
42
|
-
],
|
|
9
|
+
pluginSyntaxJsx,
|
|
10
|
+
[pluginTransformTypescript, { isTSX: true }],
|
|
11
|
+
[babelTransformRpc, options],
|
|
12
|
+
process.env.DEBUG_ACTIONS && [babelDebugOutputs, options],
|
|
43
13
|
].filter(Boolean);
|
|
44
14
|
}
|
|
45
|
-
|
|
46
|
-
function findRootDir(dir) {
|
|
15
|
+
export function findRootDir(dir) {
|
|
47
16
|
{
|
|
48
17
|
let curDir = path.resolve(dir, 'src');
|
|
49
18
|
if (fs.existsSync(curDir))
|
|
@@ -51,5 +20,4 @@ function findRootDir(dir) {
|
|
|
51
20
|
}
|
|
52
21
|
throw new Error("Couldn't find a src directory. Please create one under the project root");
|
|
53
22
|
}
|
|
54
|
-
exports.findRootDir = findRootDir;
|
|
55
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAS7B,OAAO,eAAe,MAAM,0BAA0B,CAAC;AACvD,OAAO,yBAAyB,MAAM,oCAAoC,CAAC;AAC3E,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AACvD,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AAEvD,MAAM,UAAU,OAAO,CAAC,OAAsB;IAC5C,OAAO;QACL,eAAe;QACf,CAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAC5C,CAAC,iBAAiB,EAAE,OAAO,CAAC;QAC5B,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC;KAC1D,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,CAAC;QACC,IAAI,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACtC,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;AACJ,CAAC"}
|
package/dist/jsonRpc.js
CHANGED
package/dist/jsonRpc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonRpc.js","sourceRoot":"","sources":["../src/jsonRpc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jsonRpc.js","sourceRoot":"","sources":["../src/jsonRpc.ts"],"names":[],"mappings":"AAAA,wCAAwC"}
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
3
2
|
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
4
3
|
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
@@ -12,15 +11,10 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
|
12
11
|
function reject(value) { resume("throw", value); }
|
|
13
12
|
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
14
13
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
exports.internalNodeJsHandler = exports.internalEdgeHandler = exports.createRpcMethod = void 0;
|
|
20
|
-
const superjson_1 = __importDefault(require("superjson"));
|
|
21
|
-
const context_internal_1 = require("./context-internal");
|
|
22
|
-
const utils_1 = require("./utils");
|
|
23
|
-
function createRpcMethod(method, meta, customWrapRpcMethod) {
|
|
14
|
+
import superjson from 'superjson';
|
|
15
|
+
import { asyncLocalStorage } from './context-internal.js';
|
|
16
|
+
import { jsonRpcError } from './utils.js';
|
|
17
|
+
export function createRpcMethod(method, meta, customWrapRpcMethod) {
|
|
24
18
|
let wrapped = method;
|
|
25
19
|
if (typeof customWrapRpcMethod === 'function') {
|
|
26
20
|
wrapped = customWrapRpcMethod(method, meta);
|
|
@@ -34,12 +28,11 @@ function createRpcMethod(method, meta, customWrapRpcMethod) {
|
|
|
34
28
|
}
|
|
35
29
|
return (...args) => wrapped(...args);
|
|
36
30
|
}
|
|
37
|
-
|
|
38
|
-
function internalEdgeHandler({ methodsMap, }) {
|
|
31
|
+
export function internalEdgeHandler({ methodsMap, }) {
|
|
39
32
|
return async ({ req, basePath }) => {
|
|
40
33
|
const body = await req.json();
|
|
41
34
|
const res = new Response();
|
|
42
|
-
const result = await
|
|
35
|
+
const result = await asyncLocalStorage.run({ req, res }, () => handler({
|
|
43
36
|
methodsMap,
|
|
44
37
|
body,
|
|
45
38
|
pathname: new URL(req.url).pathname,
|
|
@@ -88,8 +81,7 @@ function internalEdgeHandler({ methodsMap, }) {
|
|
|
88
81
|
});
|
|
89
82
|
};
|
|
90
83
|
}
|
|
91
|
-
|
|
92
|
-
function internalNodeJsHandler({ methodsMap, }) {
|
|
84
|
+
export function internalNodeJsHandler({ methodsMap, }) {
|
|
93
85
|
return async ({ req, res, basePath, }) => {
|
|
94
86
|
let body = req['body'];
|
|
95
87
|
if (body && typeof body === 'string') {
|
|
@@ -103,11 +95,11 @@ function internalNodeJsHandler({ methodsMap, }) {
|
|
|
103
95
|
}
|
|
104
96
|
catch (error) {
|
|
105
97
|
res.writeHead(400);
|
|
106
|
-
res.end(JSON.stringify(
|
|
98
|
+
res.end(JSON.stringify(jsonRpcError({ message: 'Invalid body, must be JSON' })));
|
|
107
99
|
return;
|
|
108
100
|
}
|
|
109
101
|
}
|
|
110
|
-
const result = await
|
|
102
|
+
const result = await asyncLocalStorage.run({ req, res }, () => handler({
|
|
111
103
|
methodsMap,
|
|
112
104
|
body,
|
|
113
105
|
basePath,
|
|
@@ -146,7 +138,6 @@ function internalNodeJsHandler({ methodsMap, }) {
|
|
|
146
138
|
res.writeHead(status || 200).end(JSON.stringify(json, null, 2));
|
|
147
139
|
};
|
|
148
140
|
}
|
|
149
|
-
exports.internalNodeJsHandler = internalNodeJsHandler;
|
|
150
141
|
function isAsyncGenerator(obj) {
|
|
151
142
|
return obj != null && typeof obj.next === 'function';
|
|
152
143
|
}
|
|
@@ -212,13 +203,13 @@ const handler = async ({ method, methodsMap, basePath, body, pathname, }) => {
|
|
|
212
203
|
};
|
|
213
204
|
}
|
|
214
205
|
try {
|
|
215
|
-
const args =
|
|
206
|
+
const args = superjson.deserialize({
|
|
216
207
|
json: params,
|
|
217
208
|
meta: argsMeta,
|
|
218
209
|
});
|
|
219
210
|
const result = await requestedMethod(...args);
|
|
220
211
|
if (!isAsyncGenerator(result)) {
|
|
221
|
-
const { json, meta } =
|
|
212
|
+
const { json, meta } = superjson.serialize(result);
|
|
222
213
|
return {
|
|
223
214
|
json: {
|
|
224
215
|
jsonrpc: '2.0',
|
|
@@ -237,7 +228,7 @@ const handler = async ({ method, methodsMap, basePath, body, pathname, }) => {
|
|
|
237
228
|
if (done) {
|
|
238
229
|
break;
|
|
239
230
|
}
|
|
240
|
-
const { json, meta } =
|
|
231
|
+
const { json, meta } = superjson.serialize(value);
|
|
241
232
|
yield yield __await({
|
|
242
233
|
json: {
|
|
243
234
|
jsonrpc: '2.0',
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAkB1C,MAA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AAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAC5D;iBACF;aACwB;SAC5B,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,SAAS,WAAW,CAAC,GAAoB;IACvC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,IAAI,GAAG,EAAE,CAAC;QACd,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;YACvB,IAAI,IAAI,KAAK,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACjB,IAAI,CAAC;gBACH,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBACpC,OAAO,CAAC,UAAU,CAAC,CAAC;YACtB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PluginPass } from '@babel/core';
|
|
2
2
|
import { Node, types } from '@babel/core';
|
|
3
|
-
import { JsonRpcErrorResponse } from './jsonRpc';
|
|
3
|
+
import { JsonRpcErrorResponse } from './jsonRpc.js';
|
|
4
4
|
export declare function annotateAsPure<N extends Node>(t: typeof types, node: N): N;
|
|
5
5
|
export type Literal = number | string | boolean | {
|
|
6
6
|
[key: string]: Literal;
|
|
@@ -17,4 +17,5 @@ export declare function jsonRpcError({ id, message, code, }: {
|
|
|
17
17
|
message: any;
|
|
18
18
|
code?: number | undefined;
|
|
19
19
|
}): JsonRpcErrorResponse;
|
|
20
|
+
export declare function camelCaseCapitalized(str: string): string;
|
|
20
21
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,aAAa,CAAC;AAE1D,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAgB,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAIlE,wBAAgB,cAAc,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,OAAO,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAG1E;AAED,MAAM,MAAM,OAAO,GACf,MAAM,GACN,MAAM,GACN,OAAO,GACP;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,GAC1B,OAAO,EAAE,CAAC;AAGd,eAAO,MAAM,MAAM;;;CAOlB,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,sBAY5C;AACD,eAAO,MAAM,SAAS,kBAAkB,CAAC;AAEzC,eAAO,MAAM,eAAe,0BAA0B,CAAC;AAEvD,wBAAgB,YAAY,CAAC,EAC3B,EAAS,EACT,OAAO,EACP,IAAQ,GACT;;;;CAAA,GAAG,oBAAoB,CAUvB;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,UAU/C"}
|
package/dist/utils.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jsonRpcError = exports.serverEntryName = exports.directive = exports.getFileName = exports.logger = exports.annotateAsPure = void 0;
|
|
4
1
|
const PURE_ANNOTATION = '#__PURE__';
|
|
5
|
-
function annotateAsPure(t, node) {
|
|
2
|
+
export function annotateAsPure(t, node) {
|
|
6
3
|
t.addComment(node, 'leading', PURE_ANNOTATION);
|
|
7
4
|
return node;
|
|
8
5
|
}
|
|
9
|
-
exports.annotateAsPure = annotateAsPure;
|
|
10
6
|
const enabled = !!process.env.DEBUG_ACTIONS;
|
|
11
|
-
|
|
7
|
+
export const logger = {
|
|
12
8
|
log(...args) {
|
|
13
9
|
enabled && console.log('[actions]:', ...args);
|
|
14
10
|
},
|
|
@@ -16,7 +12,7 @@ exports.logger = {
|
|
|
16
12
|
enabled && console.log('[actions]:', ...args);
|
|
17
13
|
},
|
|
18
14
|
};
|
|
19
|
-
function getFileName(state) {
|
|
15
|
+
export function getFileName(state) {
|
|
20
16
|
const { filename, cwd } = state;
|
|
21
17
|
if (!filename) {
|
|
22
18
|
return undefined;
|
|
@@ -26,10 +22,9 @@ function getFileName(state) {
|
|
|
26
22
|
}
|
|
27
23
|
return filename;
|
|
28
24
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function jsonRpcError({ id = null, message, code = 1, }) {
|
|
25
|
+
export const directive = 'use spiceflow';
|
|
26
|
+
export const serverEntryName = '_function_server_file';
|
|
27
|
+
export function jsonRpcError({ id = null, message, code = 1, }) {
|
|
33
28
|
return {
|
|
34
29
|
jsonrpc: '2.0',
|
|
35
30
|
id,
|
|
@@ -40,5 +35,14 @@ function jsonRpcError({ id = null, message, code = 1, }) {
|
|
|
40
35
|
},
|
|
41
36
|
};
|
|
42
37
|
}
|
|
43
|
-
|
|
38
|
+
export function camelCaseCapitalized(str) {
|
|
39
|
+
// functionName -> FunctionName
|
|
40
|
+
// CamelCase -> CamelCase
|
|
41
|
+
// camelCase -> CamelCase
|
|
42
|
+
if (str.length === 0) {
|
|
43
|
+
return str;
|
|
44
|
+
}
|
|
45
|
+
const first = str[0].toUpperCase();
|
|
46
|
+
return first + str.slice(1);
|
|
47
|
+
}
|
|
44
48
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAKA,MAAM,eAAe,GAAG,WAAW,CAAC;AAEpC,MAAM,UAAU,cAAc,CAAiB,CAAe,EAAE,IAAO;IACrE,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;IAC/C,OAAO,IAAI,CAAC;AACd,CAAC;AASD,MAAM,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AAC5C,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,GAAG,CAAC,GAAG,IAAI;QACT,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,IAAI,CAAC,CAAC;IAChD,CAAC;IACD,KAAK,CAAC,GAAG,IAAI;QACX,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,IAAI,CAAC,CAAC;IAChD,CAAC;CACF,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,KAAiB;IAC3C,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;IAEhC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,GAAG,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACpC,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AACD,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,CAAC;AAEzC,MAAM,CAAC,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAEvD,MAAM,UAAU,YAAY,CAAC,EAC3B,EAAE,GAAG,IAAI,EACT,OAAO,EACP,IAAI,GAAG,CAAC,GACT;IACC,OAAO;QACL,OAAO,EAAE,KAAK;QACd,EAAE;QACF,KAAK,EAAE;YACL,IAAI;YACJ,OAAO;YACP,IAAI,EAAE,IAAI;SACX;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,GAAW;IAC9C,+BAA+B;IAC/B,yBAAyB;IACzB,yBAAyB;IAEzB,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,GAAG,CAAC;IACb,CAAC;IACD,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACnC,OAAO,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC9B,CAAC"}
|
package/headers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export * from './dist/headers';
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spiceflow",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "If GraphQL, JSON-RPC and React server actions had a baby, it would be called spiceflow",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"repository": "https://github.com/remorses/spiceflow",
|
|
8
9
|
"bin": "dist/cli.js",
|
|
9
10
|
"files": [
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
"fs-extra": "^11.2.0",
|
|
40
41
|
"picocolors": "^1.0.0",
|
|
41
42
|
"superjson": "^1.13.3",
|
|
42
|
-
"ts-json-schema-generator": "^2.1.
|
|
43
|
+
"ts-json-schema-generator": "^2.1.1"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@babel/generator": "^7.23.6",
|
package/src/babelDebugOutputs.ts
CHANGED
|
@@ -2,10 +2,10 @@ import * as babel from '@babel/core';
|
|
|
2
2
|
import generate from '@babel/generator';
|
|
3
3
|
import * as types from '@babel/types';
|
|
4
4
|
import fs from 'fs';
|
|
5
|
-
import { PluginOptions } from './babelTransformRpc';
|
|
5
|
+
import { PluginOptions } from './babelTransformRpc.js';
|
|
6
6
|
import { default as nodePath, default as path } from 'path';
|
|
7
7
|
|
|
8
|
-
import { getFileName, logger } from './utils';
|
|
8
|
+
import { getFileName, logger } from './utils.js';
|
|
9
9
|
|
|
10
10
|
type Babel = { types: typeof types };
|
|
11
11
|
|
package/src/babelTransformRpc.ts
CHANGED
|
@@ -4,14 +4,12 @@ import { parseExpression } from '@babel/parser';
|
|
|
4
4
|
import type * as types from '@babel/types';
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import path from 'path';
|
|
7
|
-
import { WrapMethodMeta } from './server';
|
|
8
|
-
import { annotateAsPure, directive, logger } from './utils';
|
|
7
|
+
import { WrapMethodMeta } from './server.js';
|
|
8
|
+
import { annotateAsPure, directive, logger } from './utils.js';
|
|
9
9
|
|
|
10
10
|
type Babel = { types: typeof types };
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
const IMPORT_PATH_SERVER = `${name}/dist/server.js`;
|
|
14
|
-
const IMPORT_PATH_BROWSER = `${name}/dist/browser.js`;
|
|
12
|
+
const IMPORT_PATH_BROWSER = `spiceflow/dist/browser.js`;
|
|
15
13
|
|
|
16
14
|
function isAllowedTsExportDeclaration(
|
|
17
15
|
declaration: babel.NodePath<babel.types.Declaration | null | undefined>,
|
|
@@ -151,17 +149,17 @@ export function isEdgeInConfig(
|
|
|
151
149
|
export interface PluginOptions {
|
|
152
150
|
isServer: boolean;
|
|
153
151
|
rootDir: string;
|
|
154
|
-
|
|
152
|
+
onMethod?: (method: WrapMethodMeta) => void;
|
|
155
153
|
url?: string;
|
|
156
154
|
}
|
|
157
155
|
|
|
158
156
|
export default function (
|
|
159
157
|
{ types: t }: Babel,
|
|
160
|
-
{ rootDir, isServer, url: rpcUrl }: PluginOptions,
|
|
158
|
+
{ rootDir, onMethod, isServer, url: rpcUrl }: PluginOptions,
|
|
161
159
|
): babel.PluginObj {
|
|
162
160
|
return {
|
|
163
161
|
visitor: {
|
|
164
|
-
Program(program) {
|
|
162
|
+
Program(program, state) {
|
|
165
163
|
const { filename } = this.file.opts;
|
|
166
164
|
|
|
167
165
|
if (!filename) {
|
|
@@ -235,6 +233,7 @@ export default function (
|
|
|
235
233
|
if (methodName === 'wrapMethod') {
|
|
236
234
|
continue;
|
|
237
235
|
}
|
|
236
|
+
|
|
238
237
|
const isGenerator = !!declaration.node.generator;
|
|
239
238
|
generators.set(methodName!, isGenerator);
|
|
240
239
|
if (!declaration.node.async) {
|
|
@@ -376,6 +375,7 @@ export default function (
|
|
|
376
375
|
),
|
|
377
376
|
...rpcMethodNames.map((name) => {
|
|
378
377
|
const isGenerator = !!generators.get(name);
|
|
378
|
+
onMethod?.({ name, pathname: rpcPath, isGenerator });
|
|
379
379
|
return t.exportNamedDeclaration(
|
|
380
380
|
t.variableDeclaration('const', [
|
|
381
381
|
t.variableDeclarator(
|
package/src/browser.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { JsonRpcRequest, JsonRpcResponse } from './jsonRpc';
|
|
2
1
|
import { EventSourceParserStream } from 'eventsource-parser/stream';
|
|
3
|
-
import {
|
|
2
|
+
import { JsonRpcRequest, JsonRpcResponse } from './jsonRpc.js';
|
|
4
3
|
|
|
5
4
|
import superjson from 'superjson';
|
|
6
5
|
|
package/src/build.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pico from 'picocolors';
|
|
2
2
|
import fsx from 'fs-extra';
|
|
3
3
|
|
|
4
4
|
import {
|
|
@@ -12,13 +12,25 @@ import { getPackages } from '@manypkg/get-packages';
|
|
|
12
12
|
|
|
13
13
|
import { transform } from '@babel/core';
|
|
14
14
|
import { exec } from 'child_process';
|
|
15
|
-
import
|
|
15
|
+
import globSync from 'fast-glob';
|
|
16
16
|
import fs from 'fs';
|
|
17
17
|
import path from 'path';
|
|
18
|
-
import { plugins } from '.';
|
|
19
|
-
import { directive, serverEntryName } from './utils';
|
|
18
|
+
import { plugins } from './index.js';
|
|
19
|
+
import { camelCaseCapitalized, directive, serverEntryName } from './utils.js';
|
|
20
|
+
import { createGenerator } from 'ts-json-schema-generator';
|
|
21
|
+
import { WrapMethodMeta } from './server.js';
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
type BuildOptions = {
|
|
24
|
+
openapi?: boolean;
|
|
25
|
+
rootDir: string;
|
|
26
|
+
url: string;
|
|
27
|
+
watch?: boolean;
|
|
28
|
+
};
|
|
29
|
+
export async function buildOnce({
|
|
30
|
+
openapi = false,
|
|
31
|
+
rootDir,
|
|
32
|
+
url,
|
|
33
|
+
}: BuildOptions) {
|
|
22
34
|
console.log();
|
|
23
35
|
console.log('building functions');
|
|
24
36
|
if (url && !url.endsWith('/')) {
|
|
@@ -42,7 +54,7 @@ export async function buildOnce({ rootDir, url }) {
|
|
|
42
54
|
const globBase = path.relative(cwd, rootDir);
|
|
43
55
|
const globs = [path.posix.join(globBase, '**/*.{ts,tsx,js,jsx}')];
|
|
44
56
|
// console.log({ globs });
|
|
45
|
-
const allPossibleFiles = globSync(globs, {
|
|
57
|
+
const allPossibleFiles = globSync.globSync(globs, {
|
|
46
58
|
onlyFiles: true,
|
|
47
59
|
absolute: true,
|
|
48
60
|
});
|
|
@@ -105,49 +117,57 @@ export async function buildOnce({ rootDir, url }) {
|
|
|
105
117
|
|
|
106
118
|
const actionName = path.basename(actionFile, path.extname(actionFile));
|
|
107
119
|
|
|
120
|
+
let methods = [] as WrapMethodMeta[];
|
|
108
121
|
const res = transform(content || '', {
|
|
109
122
|
babelrc: false,
|
|
110
123
|
sourceType: 'module',
|
|
111
|
-
plugins:
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
124
|
+
plugins: [
|
|
125
|
+
...plugins({
|
|
126
|
+
isServer: false,
|
|
127
|
+
url,
|
|
128
|
+
onMethod(meta) {
|
|
129
|
+
methods.push(meta);
|
|
130
|
+
},
|
|
131
|
+
rootDir,
|
|
132
|
+
}),
|
|
133
|
+
],
|
|
116
134
|
filename: abs,
|
|
117
135
|
|
|
118
136
|
sourceMaps: false,
|
|
119
137
|
});
|
|
138
|
+
|
|
120
139
|
if (!res || !res.code) {
|
|
121
140
|
console.error(
|
|
122
141
|
`Error transforming ${actionFile}, returned nothing, maybe not an action?`,
|
|
123
142
|
);
|
|
124
143
|
continue;
|
|
125
144
|
}
|
|
126
|
-
|
|
127
145
|
const importPath =
|
|
128
146
|
'./' +
|
|
129
147
|
path.posix.join(path.posix.dirname(actionFile), actionName + '.js');
|
|
148
|
+
const outFile = path.resolve(libOutDir, importPath);
|
|
149
|
+
|
|
130
150
|
console.log(`processed ${importPath}`);
|
|
131
151
|
imports.push(importPath);
|
|
132
152
|
fs.mkdirSync(path.resolve(libOutDir, path.dirname(importPath)), {
|
|
133
153
|
recursive: true,
|
|
134
154
|
});
|
|
135
|
-
|
|
155
|
+
if (openapi) {
|
|
156
|
+
const openapiTypes =
|
|
157
|
+
`import * as methods from ${JSON.stringify(
|
|
158
|
+
'./' + path.basename(importPath),
|
|
159
|
+
)}\n` +
|
|
160
|
+
methods
|
|
161
|
+
.map(
|
|
162
|
+
(x) =>
|
|
163
|
+
`export const x: Awaited<ReturnType<typeof methods.${x.name}>>\n`,
|
|
164
|
+
)
|
|
165
|
+
.join('\n');
|
|
166
|
+
fs.writeFileSync(openapiTypesPath(outFile), openapiTypes, 'utf-8');
|
|
167
|
+
fs.writeFileSync(outFile, res.code, 'utf-8');
|
|
168
|
+
}
|
|
136
169
|
}
|
|
137
170
|
|
|
138
|
-
// const generator = createGenerator({
|
|
139
|
-
// path: dtsOutputFilePath,
|
|
140
|
-
// type: '*',
|
|
141
|
-
// tsconfig: 'tsconfig.json',
|
|
142
|
-
// skipTypeCheck: true,
|
|
143
|
-
// functions: 'comment',
|
|
144
|
-
// });
|
|
145
|
-
// const schema = generator.createSchema();
|
|
146
|
-
// fs.writeFileSync(
|
|
147
|
-
// path.resolve(outDir, 'schema.json'),
|
|
148
|
-
// JSON.stringify(schema, null, 2),
|
|
149
|
-
// );
|
|
150
|
-
|
|
151
171
|
const bundledPackages = (await getPackages(process.cwd())).packages.map(
|
|
152
172
|
(x) => x.packageJson.name,
|
|
153
173
|
);
|
|
@@ -171,6 +191,25 @@ export async function buildOnce({ rootDir, url }) {
|
|
|
171
191
|
outputFilePath: entryPointDts,
|
|
172
192
|
tsconfigFilePath: 'tsconfig.json',
|
|
173
193
|
});
|
|
194
|
+
if (!openapi) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const generator = createGenerator({
|
|
199
|
+
path: path.resolve(actionFile),
|
|
200
|
+
type: `*`,
|
|
201
|
+
tsconfig: 'tsconfig.json',
|
|
202
|
+
minify: false,
|
|
203
|
+
// discriminatorType: 'open-api',
|
|
204
|
+
skipTypeCheck: true,
|
|
205
|
+
functions: 'comment',
|
|
206
|
+
});
|
|
207
|
+
const schema = generator.createSchema();
|
|
208
|
+
console.log(JSON.stringify(schema, null, 2));
|
|
209
|
+
// fs.writeFileSync(
|
|
210
|
+
// path.resolve(libOutDir, 'schema.json'),
|
|
211
|
+
// JSON.stringify(schema, null, 2),
|
|
212
|
+
// );
|
|
174
213
|
}
|
|
175
214
|
} finally {
|
|
176
215
|
await fs.promises.unlink(serverEntrypoint).catch(() => null);
|
|
@@ -181,11 +220,12 @@ const logger = console;
|
|
|
181
220
|
let isBuilding = { ref: false };
|
|
182
221
|
let missedWatch = { ref: false };
|
|
183
222
|
|
|
184
|
-
export async function build(
|
|
185
|
-
await buildOnce(
|
|
186
|
-
if (!watch) {
|
|
223
|
+
export async function build(options: BuildOptions) {
|
|
224
|
+
await buildOnce(options);
|
|
225
|
+
if (!options.watch) {
|
|
187
226
|
return;
|
|
188
227
|
}
|
|
228
|
+
const { rootDir, url } = options;
|
|
189
229
|
const watcher = chokidar.watch(rootDir, {
|
|
190
230
|
// ignored: /(^|[\/\\])\../, // ignore dotfiles
|
|
191
231
|
ignored: ['**/node_modules/**', '**/dist/**', `src/${serverEntryName}.ts`],
|
|
@@ -200,10 +240,10 @@ export async function build({ rootDir, url, watch = false }) {
|
|
|
200
240
|
isBuilding.ref = true;
|
|
201
241
|
try {
|
|
202
242
|
logger.log(`detected change in ${path}`);
|
|
203
|
-
await buildOnce(
|
|
243
|
+
await buildOnce(options);
|
|
204
244
|
if (missedWatch.ref) {
|
|
205
245
|
// logger.log('missed a change, rebuilding');
|
|
206
|
-
await buildOnce(
|
|
246
|
+
await buildOnce(options);
|
|
207
247
|
missedWatch.ref = false;
|
|
208
248
|
}
|
|
209
249
|
} finally {
|
|
@@ -292,8 +332,8 @@ function runCommand(command: string) {
|
|
|
292
332
|
exec(command, {}, (error, stdout, stderr) => {
|
|
293
333
|
if (error) {
|
|
294
334
|
console.log();
|
|
295
|
-
console.error(red(stdout));
|
|
296
|
-
console.error(red(stderr));
|
|
335
|
+
console.error(pico.red(stdout));
|
|
336
|
+
console.error(pico.red(stderr));
|
|
297
337
|
reject(error);
|
|
298
338
|
} else {
|
|
299
339
|
resolve(stdout);
|
|
@@ -301,3 +341,10 @@ function runCommand(command: string) {
|
|
|
301
341
|
});
|
|
302
342
|
});
|
|
303
343
|
}
|
|
344
|
+
|
|
345
|
+
function openapiTypesPath(outFile) {
|
|
346
|
+
return path.resolve(
|
|
347
|
+
path.dirname(outFile),
|
|
348
|
+
`${path.basename(outFile, path.extname(outFile))}-schema.d.ts`,
|
|
349
|
+
);
|
|
350
|
+
}
|