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.
Files changed (56) hide show
  1. package/README.md +20 -18
  2. package/context.js +1 -1
  3. package/dist/babel.test.js +13 -18
  4. package/dist/babel.test.js.map +1 -1
  5. package/dist/babelDebugOutputs.d.ts +1 -1
  6. package/dist/babelDebugOutputs.d.ts.map +1 -1
  7. package/dist/babelDebugOutputs.js +12 -18
  8. package/dist/babelDebugOutputs.js.map +1 -1
  9. package/dist/babelTransformRpc.d.ts +3 -1
  10. package/dist/babelTransformRpc.d.ts.map +1 -1
  11. package/dist/babelTransformRpc.js +17 -27
  12. package/dist/babelTransformRpc.js.map +1 -1
  13. package/dist/browser.d.ts.map +1 -1
  14. package/dist/browser.js +8 -15
  15. package/dist/browser.js.map +1 -1
  16. package/dist/build.d.ts +9 -9
  17. package/dist/build.d.ts.map +1 -1
  18. package/dist/build.js +101 -84
  19. package/dist/build.js.map +1 -1
  20. package/dist/cli.js +30 -33
  21. package/dist/cli.js.map +1 -1
  22. package/dist/context-internal.js +8 -14
  23. package/dist/context-internal.js.map +1 -1
  24. package/dist/context.d.ts +1 -1
  25. package/dist/context.d.ts.map +1 -1
  26. package/dist/context.js +1 -7
  27. package/dist/context.js.map +1 -1
  28. package/dist/expose.js +5 -12
  29. package/dist/expose.js.map +1 -1
  30. package/dist/headers.d.ts +1 -0
  31. package/dist/headers.js +1 -1
  32. package/dist/headers.js.map +1 -1
  33. package/dist/index.d.ts +3 -3
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +12 -44
  36. package/dist/index.js.map +1 -1
  37. package/dist/jsonRpc.js +1 -2
  38. package/dist/jsonRpc.js.map +1 -1
  39. package/dist/server.js +12 -21
  40. package/dist/server.js.map +1 -1
  41. package/dist/utils.d.ts +2 -1
  42. package/dist/utils.d.ts.map +1 -1
  43. package/dist/utils.js +16 -12
  44. package/dist/utils.js.map +1 -1
  45. package/headers.js +1 -1
  46. package/package.json +3 -2
  47. package/src/babelDebugOutputs.ts +2 -2
  48. package/src/babelTransformRpc.ts +8 -8
  49. package/src/browser.ts +1 -2
  50. package/src/build.ts +80 -33
  51. package/src/cli.ts +9 -2
  52. package/src/context.ts +5 -1
  53. package/src/expose.ts +1 -1
  54. package/src/index.ts +12 -20
  55. package/src/server.ts +3 -3
  56. package/src/utils.ts +15 -3
package/src/cli.ts CHANGED
@@ -12,16 +12,23 @@ import path from 'path';
12
12
 
13
13
  export const cli = cac();
14
14
 
15
+ const __dirname = path.dirname(import.meta.url);
16
+
15
17
  cli
16
18
  .command('', 'Generate an SDK package for your functions')
19
+ .alias('build')
17
20
  .option('--watch', 'Watch for changes')
18
21
  .option('--url <url>', 'URL of the package, including the base path', {
19
22
  default: 'http://localhost:3333',
20
23
  })
24
+ .option(
25
+ '--openapi',
26
+ '[experimental] Creates an openapi.json schema based on your functions',
27
+ )
21
28
  .action(async (options) => {
22
- const { url, watch } = options;
29
+ const { url, watch, openapi } = options;
23
30
  const rootDir = await findRootDir(process.cwd());
24
- await build({ rootDir, url, watch });
31
+ await build({ rootDir, url, openapi, watch });
25
32
  });
26
33
  cli
27
34
  .command('init', 'Generate a new spiceflow project')
package/src/context.ts CHANGED
@@ -1 +1,5 @@
1
- export { getNodejsContext, getEdgeContext, getContext } from './context-internal';
1
+ export {
2
+ getNodejsContext,
3
+ getEdgeContext,
4
+ getContext,
5
+ } from './context-internal.js';
package/src/expose.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import http from 'http';
2
- import { internalNodeJsHandler } from './server';
2
+ import { internalNodeJsHandler } from './server.js';
3
3
 
4
4
  export async function exposeNodeServer({ methodsMap, basePath, port }) {
5
5
  const handler = internalNodeJsHandler({ methodsMap });
package/src/index.ts CHANGED
@@ -1,33 +1,25 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
- import { PluginOptions } from './babelTransformRpc';
3
+ import { PluginOptions } from './babelTransformRpc.js';
4
4
 
5
- import { WrapMethod } from './server';
5
+ import { WrapMethod, WrapMethodMeta } from './server.js';
6
6
 
7
7
  export interface WithRpcConfig {}
8
8
 
9
9
  export { WrapMethod };
10
10
 
11
- export function plugins({
12
- isServer,
13
- rootDir: nextDir,
14
- url,
15
- }: PluginOptions) {
16
- const rpcPluginOptions: PluginOptions = {
17
- isServer,
18
- rootDir: nextDir,
19
- url,
20
- };
11
+ import pluginSyntaxJsx from '@babel/plugin-syntax-jsx';
12
+ import pluginTransformTypescript from '@babel/plugin-transform-typescript';
13
+ import babelTransformRpc from './babelTransformRpc.js';
14
+ import babelDebugOutputs from './babelDebugOutputs.js';
21
15
 
16
+ export function plugins(options: PluginOptions) {
22
17
  return [
23
- require.resolve('@babel/plugin-syntax-jsx'),
24
- [require.resolve('@babel/plugin-transform-typescript'), { isTSX: true }],
25
- [require.resolve('../dist/babelTransformRpc'), rpcPluginOptions],
26
- process.env.DEBUG_ACTIONS && [
27
- require.resolve('../dist/babelDebugOutputs'),
28
- rpcPluginOptions,
29
- ],
30
- ].filter(Boolean) as any[];
18
+ pluginSyntaxJsx,
19
+ [pluginTransformTypescript, { isTSX: true }],
20
+ [babelTransformRpc, options],
21
+ process.env.DEBUG_ACTIONS && [babelDebugOutputs, options],
22
+ ].filter(Boolean);
31
23
  }
32
24
 
33
25
  export function findRootDir(dir: string): string {
package/src/server.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { IncomingMessage, ServerResponse } from 'http';
2
2
  import superjson from 'superjson';
3
- import { asyncLocalStorage } from './context-internal';
4
- import { JsonRpcRequest, JsonRpcResponse } from './jsonRpc';
5
- import { jsonRpcError } from './utils';
3
+ import { asyncLocalStorage } from './context-internal.js';
4
+ import { JsonRpcRequest, JsonRpcResponse } from './jsonRpc.js';
5
+ import { jsonRpcError } from './utils.js';
6
6
 
7
7
  export type Method<P extends any[], R> = (
8
8
  ...params: P
package/src/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { PluginPass, parse } from '@babel/core';
1
+ import { PluginPass, parse, traverse } from '@babel/core';
2
2
 
3
3
  import { Node, types } from '@babel/core';
4
- import { JsonRpcError, JsonRpcErrorResponse } from './jsonRpc';
4
+ import { JsonRpcError, JsonRpcErrorResponse } from './jsonRpc.js';
5
5
 
6
6
  const PURE_ANNOTATION = '#__PURE__';
7
7
 
@@ -40,7 +40,7 @@ export function getFileName(state: PluginPass) {
40
40
 
41
41
  return filename;
42
42
  }
43
- export const directive = "use spiceflow"
43
+ export const directive = 'use spiceflow';
44
44
 
45
45
  export const serverEntryName = '_function_server_file';
46
46
 
@@ -59,3 +59,15 @@ export function jsonRpcError({
59
59
  },
60
60
  };
61
61
  }
62
+
63
+ export function camelCaseCapitalized(str: string) {
64
+ // functionName -> FunctionName
65
+ // CamelCase -> CamelCase
66
+ // camelCase -> CamelCase
67
+
68
+ if (str.length === 0) {
69
+ return str;
70
+ }
71
+ const first = str[0].toUpperCase();
72
+ return first + str.slice(1);
73
+ }