@based/type-gen 0.0.4 → 0.0.5

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.
@@ -1,4 +1,4 @@
1
- import { BasedFunctionConfig } from '@based/functions';
1
+ import { BasedFunctionConfig } from "@based/functions";
2
2
  export declare const updateTypes: (fns: ({
3
3
  config: BasedFunctionConfig;
4
4
  path: string;
@@ -14,4 +14,3 @@ export declare const updateTypes: (fns: ({
14
14
  clientPath: string | void;
15
15
  functionPath: string | void;
16
16
  }>;
17
- //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,44 @@
1
+ import { updateTypesPath } from "./updateTypesPath.js";
2
+ import { createRequire } from "node:module";
3
+ const require = createRequire(import.meta.url);
4
+ export const updateTypes = async (fns, opts = {}) => {
5
+ const inputClientPath = opts.clientPath ||
6
+ require.resolve("@based/client", { paths: [process.cwd()] });
7
+ const inputFunctionPath = opts.functionPath ||
8
+ require.resolve("@based/functions", { paths: [process.cwd()] });
9
+ let clientPath;
10
+ let functionPath;
11
+ if (inputClientPath) {
12
+ const declarationPath = inputClientPath.replace("/index.js", "/index.d.ts");
13
+ const originalDeclartionPath = inputClientPath.replace("/index.js", "/index_original.d.ts");
14
+ clientPath = await updateTypesPath(fns, {
15
+ imports: opts.imports,
16
+ originalDeclartionPath,
17
+ declarationPath,
18
+ }).catch((e) => {
19
+ console.error(e, {
20
+ imports: opts.imports,
21
+ originalDeclartionPath,
22
+ declarationPath,
23
+ });
24
+ console.error("Cannot find original declaration file - you may need to upgrade to @based/client ^4.8.8");
25
+ });
26
+ }
27
+ if (inputFunctionPath) {
28
+ const declarationPath = inputFunctionPath.replace("/index.js", "/client.d.ts");
29
+ const originalDeclartionPath = inputFunctionPath.replace("/index.js", "/client_original.d.ts");
30
+ functionPath = await updateTypesPath(fns, {
31
+ imports: opts.imports,
32
+ originalDeclartionPath,
33
+ declarationPath,
34
+ isAbstract: true,
35
+ }).catch(() => {
36
+ console.error("Cannot find original declaration file - you may need to upgrade to @based/functions ^2.2.4");
37
+ });
38
+ }
39
+ return {
40
+ functionPath,
41
+ clientPath,
42
+ };
43
+ };
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAE9C,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,GAGG,EACH,OAII,EAAE,EAIL,EAAE;IACH,MAAM,eAAe,GACnB,IAAI,CAAC,UAAU;QACf,OAAO,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;IAE9D,MAAM,iBAAiB,GACrB,IAAI,CAAC,YAAY;QACjB,OAAO,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;IAEjE,IAAI,UAAyB,CAAA;IAC7B,IAAI,YAA2B,CAAA;IAE/B,IAAI,eAAe,EAAE,CAAC;QACpB,MAAM,eAAe,GAAG,eAAe,CAAC,OAAO,CAAC,WAAW,EAAE,aAAa,CAAC,CAAA;QAC3E,MAAM,sBAAsB,GAAG,eAAe,CAAC,OAAO,CACpD,WAAW,EACX,sBAAsB,CACvB,CAAA;QAED,UAAU,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE;YACtC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,sBAAsB;YACtB,eAAe;SAChB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE;gBACf,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,sBAAsB;gBACtB,eAAe;aAChB,CAAC,CAAA;YACF,OAAO,CAAC,KAAK,CACX,yFAAyF,CAC1F,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,iBAAiB,EAAE,CAAC;QACtB,MAAM,eAAe,GAAG,iBAAiB,CAAC,OAAO,CAC/C,WAAW,EACX,cAAc,CACf,CAAA;QACD,MAAM,sBAAsB,GAAG,iBAAiB,CAAC,OAAO,CACtD,WAAW,EACX,uBAAuB,CACxB,CAAA;QACD,YAAY,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE;YACxC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,sBAAsB;YACtB,eAAe;YACf,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CACX,4FAA4F,CAC7F,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,OAAO;QACL,YAAY;QACZ,UAAU;KACX,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -36,6 +36,7 @@ const parseCode = (code) => {
36
36
  }
37
37
  return result;
38
38
  };
39
+ export {};
39
40
  /*
40
41
  import type helloWorld from '../../helloWorld'
41
42
 
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseCode.js","sourceRoot":"","sources":["../../src/parseCode.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;AAC5C,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAA;AAEnD,MAAM,SAAS,GAAG,CAChB,IAAY,EAIZ,EAAE;IACF,MAAM,MAAM,GAAG;QACb,KAAK,EAAE,EAAE;QACT,MAAM,EAAE,EAAE;KACX,CAAA;IAED,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE;QAClC,UAAU,EAAE,QAAQ;QACpB,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC;KAC/B,CAAC,CAAA;IACF,MAAM,CAAC,GAAG,EAAE,CAAA;IACZ,MAAM,WAAW,GAAG,EAAE,CAAA;IAEtB,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAEjC,IAAI,CAAC;QACH,QAAQ,CAAC,GAAG,EAAE;YACZ,UAAU,CAAC,CAAC;gBACV,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;gBAEf,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YAC9B,CAAC;YACD,sBAAsB,EAAE,UAAU,IAAI;gBACpC,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;oBACtE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,CAAA;oBAErC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;oBACnB,CAAC;yBAAM,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;wBACvC,2CAA2C;wBAC3C,gBAAgB;oBAClB,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACpB,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;;AAED;;;;EAIE"}
@@ -1,4 +1,4 @@
1
- import { BasedFunctionConfig } from '@based/functions';
1
+ import { BasedFunctionConfig } from "@based/functions";
2
2
  export declare const updateTypesPath: (fns: ({
3
3
  config: BasedFunctionConfig;
4
4
  path: string;
@@ -12,4 +12,3 @@ export declare const updateTypesPath: (fns: ({
12
12
  originalDeclartionPath: string;
13
13
  declarationPath: string;
14
14
  }) => Promise<string | void>;
15
- //# sourceMappingURL=updateTypesPath.d.ts.map
@@ -1,35 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateTypesPath = void 0;
4
- const fs_extra_1 = require("fs-extra");
5
- const updateTypesPath = async (fns, opts) => {
6
- let decFile = '';
1
+ import { readFile, writeFile } from "fs/promises";
2
+ export const updateTypesPath = async (fns, opts) => {
3
+ let decFile = "";
7
4
  try {
8
- decFile = (await (0, fs_extra_1.readFile)(opts.originalDeclartionPath)).toString('utf-8');
5
+ decFile = (await readFile(opts.originalDeclartionPath)).toString("utf-8");
9
6
  }
10
7
  catch (err) {
11
8
  throw new Error(`Cannot find ${opts.originalDeclartionPath}`);
12
9
  }
13
- let imports = opts.imports ? opts.imports.join('\n') + '\n' : '\n';
14
- let callFns = '\n';
15
- let queryFns = '\n';
10
+ let imports = opts.imports ? opts.imports.join("\n") + "\n" : "\n";
11
+ let callFns = "\n";
12
+ let queryFns = "\n";
16
13
  let fnCnt = 0;
17
14
  let queryCnt = 0;
18
- let queryMap = '\n';
15
+ let queryMap = "\n";
19
16
  let needsParsing = opts.imports ?? false;
20
- const abstractPrefix = opts.isAbstract ? 'abstract ' : '';
17
+ const abstractPrefix = opts.isAbstract ? "abstract " : "";
21
18
  for (const fn of fns) {
22
- if (fn.config.type === 'function') {
19
+ if (fn.config.type === "function") {
23
20
  needsParsing = true;
24
21
  fnCnt++;
25
- if ('path' in fn) {
26
- const name = 'FN_Type_' + fnCnt;
22
+ if ("path" in fn) {
23
+ const name = "FN_Type_" + fnCnt;
27
24
  imports += `import type ${name} from '${fn.path}';\n`;
28
25
  callFns += `
29
26
  ${abstractPrefix}call(
30
27
  name: '${fn.config.name}',
31
28
  payload: Parameters<typeof ${name}>[1],
32
- ${opts.isAbstract ? 'ctx?: Context' : 'opts?: CallOptions'}
29
+ ${opts.isAbstract ? "ctx?: Context" : "opts?: CallOptions"}
33
30
  ): ReturnType<typeof ${name}>;
34
31
  `;
35
32
  }
@@ -38,15 +35,15 @@ const updateTypesPath = async (fns, opts) => {
38
35
  ${abstractPrefix}call(
39
36
  name: '${fn.config.name}',
40
37
  payload: ${fn.payload},
41
- ${opts.isAbstract ? 'ctx?: Context' : 'opts?: CallOptions'}
38
+ ${opts.isAbstract ? "ctx?: Context" : "opts?: CallOptions"}
42
39
  ): Promise<${fn.result}>
43
40
  `;
44
41
  }
45
42
  }
46
- else if (fn.config.type === 'query') {
43
+ else if (fn.config.type === "query") {
47
44
  queryCnt++;
48
- if ('path' in fn) {
49
- const name = 'Q_Type_' + queryCnt;
45
+ if ("path" in fn) {
46
+ const name = "Q_Type_" + queryCnt;
50
47
  imports += `import type ${name} from '${fn.path}';\n`;
51
48
  queryMap += `'${fn.config.name}': { payload: Parameters<typeof ${name}>[1], result: Parameters<Parameters<typeof ${name}>[2]>[0] },`;
52
49
  queryFns += `
@@ -65,10 +62,10 @@ const updateTypesPath = async (fns, opts) => {
65
62
  let x = imports + decFile;
66
63
  if (fnCnt > 0) {
67
64
  if (opts.isAbstract) {
68
- x = x.replace('abstract call(name: string, payload?: any, ctx?: Context): Promise<any>;', callFns);
65
+ x = x.replace("abstract call(name: string, payload?: any, ctx?: Context): Promise<any>;", callFns);
69
66
  }
70
67
  else {
71
- x = x.replace('call(name: string, payload?: any, opts?: CallOptions): Promise<any>;', callFns);
68
+ x = x.replace("call(name: string, payload?: any, opts?: CallOptions): Promise<any>;", callFns);
72
69
  }
73
70
  }
74
71
  if (queryCnt > 0) {
@@ -78,11 +75,10 @@ const updateTypesPath = async (fns, opts) => {
78
75
  else {
79
76
  x = x.replace(`query(name: string, payload?: any, opts?: QueryOptions): BasedQuery;`, queryFns);
80
77
  }
81
- x = x.replace(/export type QueryMap = ([^@]*?)\};([^@]*?)\};/, `export type QueryMap = {${queryMap}}`);
78
+ x = x.replace(/export type QueryMap = ([^@]*?)\};?([^@]*?)\};?\s*\};?/gm, `export type QueryMap = {${queryMap}}`);
82
79
  }
83
- await (0, fs_extra_1.writeFile)(opts.declarationPath, x);
80
+ await writeFile(opts.declarationPath, x);
84
81
  return opts.declarationPath;
85
82
  }
86
83
  };
87
- exports.updateTypesPath = updateTypesPath;
88
84
  //# sourceMappingURL=updateTypesPath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateTypesPath.js","sourceRoot":"","sources":["../../src/updateTypesPath.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEjD,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,GAGG,EACH,IAKC,EACuB,EAAE;IAC1B,IAAI,OAAO,GAAG,EAAE,CAAA;IAEhB,IAAI,CAAC;QACH,OAAO,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC3E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,eAAe,IAAI,CAAC,sBAAsB,EAAE,CAAC,CAAA;IAC/D,CAAC;IAED,IAAI,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAA;IAClE,IAAI,OAAO,GAAG,IAAI,CAAA;IAClB,IAAI,QAAQ,GAAG,IAAI,CAAA;IACnB,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,IAAI,QAAQ,GAAG,IAAI,CAAA;IACnB,IAAI,YAAY,GAAG,IAAI,CAAC,OAAO,IAAI,KAAK,CAAA;IAExC,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAA;IAEzD,KAAK,MAAM,EAAE,IAAI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",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
- "main": "dist/index.js",
5
+ "type": "module",
6
+ "main": "./dist/src/index.js",
6
7
  "scripts": {
7
- "test": "ava --color --node-arguments='--expose-gc' --timeout 3m --verbose",
8
+ "test": "npx ava",
8
9
  "build": "npx tsc",
9
10
  "watch": "npx tsc --watch",
10
11
  "clean": "rimraf {.turbo,dist,node_modules}"
@@ -15,27 +16,27 @@
15
16
  "@babel/parser": "^7.18.6",
16
17
  "@babel/traverse": "^7.18.6",
17
18
  "utility-types": "^3.10.0",
18
- "@saulx/utils": "^3.5.0",
19
- "@based/functions": "^2.2.3"
19
+ "@saulx/utils": "^4.1.0",
20
+ "@based/functions": "^3.0.0"
20
21
  },
21
22
  "devDependencies": {
22
23
  "@types/fs-extra": "11.0.3",
23
24
  "ts-node": "10.9.1",
24
- "typescript": "^4.3.5",
25
+ "typescript": "^5.2.2",
25
26
  "rimraf": "^3.0.2",
26
- "@based/client": "4.8.7",
27
- "ava": "3.15.0"
27
+ "@based/client": "^5.2.0",
28
+ "ava": "5.3.1"
28
29
  },
29
30
  "ava": {
31
+ "timeout": "2m",
32
+ "workerThreads": false,
30
33
  "files": [
31
- "test/*.ts"
32
- ],
33
- "concurrency": 1,
34
- "extensions": [
35
- "ts"
36
- ],
37
- "require": [
38
- "ts-node/register"
34
+ "./dist/test/*.js"
39
35
  ]
40
- }
36
+ },
37
+ "files": [
38
+ "dist/src",
39
+ "README.md",
40
+ "package.json"
41
+ ]
41
42
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAGtD,eAAO,MAAM,WAAW,QACjB,CACD;IAAE,MAAM,EAAE,mBAAmB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC7C;IAAE,MAAM,EAAE,mBAAmB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CACnE,EAAE,SACG;IACJ,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;gBAEW,MAAM,GAAG,IAAI;kBACX,MAAM,GAAG,IAAI;EAwD5B,CAAA"}
package/dist/index.js DELETED
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateTypes = void 0;
4
- const updateTypesPath_1 = require("./updateTypesPath");
5
- const updateTypes = async (fns, opts = {}) => {
6
- const inputClientPath = opts.clientPath ||
7
- require.resolve('@based/client', { paths: [process.cwd()] });
8
- const inputFunctionPath = opts.functionPath ||
9
- require.resolve('@based/functions', { paths: [process.cwd()] });
10
- let clientPath;
11
- let functionPath;
12
- if (inputClientPath) {
13
- const declarationPath = inputClientPath.replace('/index.js', '/index.d.ts');
14
- const originalDeclartionPath = inputClientPath.replace('/index.js', '/index_original.d.ts');
15
- clientPath = await (0, updateTypesPath_1.updateTypesPath)(fns, {
16
- imports: opts.imports,
17
- originalDeclartionPath,
18
- declarationPath,
19
- }).catch(() => {
20
- console.error('Cannot find original declaration file - you may need to upgrade to @based/client ^4.8.8');
21
- });
22
- }
23
- if (inputFunctionPath) {
24
- const declarationPath = inputFunctionPath.replace('/index.js', '/client.d.ts');
25
- const originalDeclartionPath = inputFunctionPath.replace('/index.js', '/client_original.d.ts');
26
- functionPath = await (0, updateTypesPath_1.updateTypesPath)(fns, {
27
- imports: opts.imports,
28
- originalDeclartionPath,
29
- declarationPath,
30
- isAbstract: true,
31
- }).catch(() => {
32
- console.error('Cannot find original declaration file - you may need to upgrade to @based/functions ^2.2.4');
33
- });
34
- }
35
- return {
36
- functionPath,
37
- clientPath,
38
- };
39
- };
40
- exports.updateTypes = updateTypes;
41
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0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sBAAsB;YACtB,eAAe;YACf,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CACX,4FAA4F,CAC7F,CAAA;QACH,CAAC,CAAC,CAAA;KACH;IAED,OAAO;QACL,YAAY;QACZ,UAAU;KACX,CAAA;AACH,CAAC,CAAA;AApEY,QAAA,WAAW,eAoEvB"}
@@ -1,7 +0,0 @@
1
- declare const babelParser: any;
2
- declare const traverse: any;
3
- declare const parseCode: (code: string) => {
4
- input: any[];
5
- output: any[];
6
- };
7
- //# sourceMappingURL=parseCode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parseCode.d.ts","sourceRoot":"","sources":["../src/parseCode.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,WAAW,KAA2B,CAAA;AAC5C,QAAA,MAAM,QAAQ,KAAqC,CAAA;AAEnD,QAAA,MAAM,SAAS,SACP,MAAM,KACX;IACD,KAAK,EAAE,GAAG,EAAE,CAAA;IACZ,MAAM,EAAE,GAAG,EAAE,CAAA;CAuCd,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"parseCode.js","sourceRoot":"","sources":["../src/parseCode.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;AAC5C,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAA;AAEnD,MAAM,SAAS,GAAG,CAChB,IAAY,EAIZ,EAAE;IACF,MAAM,MAAM,GAAG;QACb,KAAK,EAAE,EAAE;QACT,MAAM,EAAE,EAAE;KACX,CAAA;IAED,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE;QAClC,UAAU,EAAE,QAAQ;QACpB,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC;KAC/B,CAAC,CAAA;IACF,MAAM,CAAC,GAAG,EAAE,CAAA;IACZ,MAAM,WAAW,GAAG,EA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AC,MAAM,CAAC,IAAI,eAAe,EAAE,CAAC,OAAO,sCAAsC,EAAE,CAAC,OAAO,IAAI,EAAE,CAAC,MAAM;KACvI,CAAA;aACE;SACF;KACF;IACD,IAAI,YAAY,EAAE;QAChB,IAAI,CAAC,GAAG,OAAO,GAAG,OAAO,CAAA;QACzB,IAAI,KAAK,GAAG,CAAC,EAAE;YACb,IAAI,IAAI,CAAC,UAAU,EAAE;gBACnB,CAAC,GAAG,CAAC,CAAC,OAAO,CACX,0EAA0E,EAC1E,OAAO,CACR,CAAA;aACF;iBAAM;gBACL,CAAC,GAAG,CAAC,CAAC,OAAO,CACX,sEAAsE,EACtE,OAAO,CACR,CAAA;aACF;SACF;QACD,IAAI,QAAQ,GAAG,CAAC,EAAE;YAChB,IAAI,IAAI,CAAC,UAAU,EAAE;gBACnB,CAAC,GAAG,CAAC,CAAC,OAAO,CACX,0DAA0D,EAC1D,QAAQ,CACT,CAAA;aACF;iBAAM;gBACL,CAAC,GAAG,CAAC,CAAC,OAAO,CACX,sEAAsE,EACtE,QAAQ,CACT,CAAA;aACF;YACD,CAAC,GAAG,CAAC,CAAC,OAAO,CACX,+CAA+C,EAC/C,2BAA2B,QAAQ,GAAG,CACvC,CAAA;SACF;QACD,MAAM,IAAA,oBAAS,EAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,CAAA;QACxC,OAAO,IAAI,CAAC,eAAe,CAAA;KAC5B;AACH,CAAC,CAAA;AAzGY,QAAA,eAAe,mBAyG3B"}
package/src/index.ts DELETED
@@ -1,72 +0,0 @@
1
- import { BasedFunctionConfig } from '@based/functions'
2
- import { updateTypesPath } from './updateTypesPath'
3
-
4
- export const updateTypes = async (
5
- fns: (
6
- | { config: BasedFunctionConfig; path: string }
7
- | { config: BasedFunctionConfig; payload: string; result: string }
8
- )[],
9
- opts: {
10
- imports?: string[]
11
- clientPath?: string
12
- functionPath?: string
13
- } = {}
14
- ): Promise<{
15
- clientPath: string | void
16
- functionPath: string | void
17
- }> => {
18
- const inputClientPath =
19
- opts.clientPath ||
20
- require.resolve('@based/client', { paths: [process.cwd()] })
21
-
22
- const inputFunctionPath =
23
- opts.functionPath ||
24
- require.resolve('@based/functions', { paths: [process.cwd()] })
25
-
26
- let clientPath: string | void
27
- let functionPath: string | void
28
-
29
- if (inputClientPath) {
30
- const declarationPath = inputClientPath.replace('/index.js', '/index.d.ts')
31
- const originalDeclartionPath = inputClientPath.replace(
32
- '/index.js',
33
- '/index_original.d.ts'
34
- )
35
-
36
- clientPath = await updateTypesPath(fns, {
37
- imports: opts.imports,
38
- originalDeclartionPath,
39
- declarationPath,
40
- }).catch(() => {
41
- console.error(
42
- 'Cannot find original declaration file - you may need to upgrade to @based/client ^4.8.8'
43
- )
44
- })
45
- }
46
-
47
- if (inputFunctionPath) {
48
- const declarationPath = inputFunctionPath.replace(
49
- '/index.js',
50
- '/client.d.ts'
51
- )
52
- const originalDeclartionPath = inputFunctionPath.replace(
53
- '/index.js',
54
- '/client_original.d.ts'
55
- )
56
- functionPath = await updateTypesPath(fns, {
57
- imports: opts.imports,
58
- originalDeclartionPath,
59
- declarationPath,
60
- isAbstract: true,
61
- }).catch(() => {
62
- console.error(
63
- 'Cannot find original declaration file - you may need to upgrade to @based/functions ^2.2.4'
64
- )
65
- })
66
- }
67
-
68
- return {
69
- functionPath,
70
- clientPath,
71
- }
72
- }
package/src/parseCode.ts DELETED
@@ -1,53 +0,0 @@
1
- const babelParser = require('@babel/parser')
2
- const traverse = require('@babel/traverse').default
3
-
4
- const parseCode = (
5
- code: string
6
- ): {
7
- input: any[]
8
- output: any[]
9
- } => {
10
- const result = {
11
- input: [],
12
- output: [],
13
- }
14
-
15
- const ast = babelParser.parse(code, {
16
- sourceType: 'module',
17
- plugins: ['jsx', 'typescript'],
18
- })
19
- const p = []
20
- const identifiers = {}
21
-
22
- console.dir(ast, { depth: 1000 })
23
-
24
- try {
25
- traverse(ast, {
26
- Identifier(p) {
27
- console.info(p)
28
-
29
- identifiers[p.node.name] = p
30
- },
31
- TSTypeAliasDeclaration: function (path) {
32
- if (path.node.id?.name?.includes('Props') && path.node.typeAnnotation) {
33
- const type = path.node.typeAnnotation
34
-
35
- if (type.members) {
36
- } else if (type.type === 'TSUnionType') {
37
- // console.info('?', path.node, type.types)
38
- // p.push(props)
39
- }
40
- }
41
- },
42
- })
43
- } catch (err) {
44
- console.error(err)
45
- }
46
- return result
47
- }
48
-
49
- /*
50
- import type helloWorld from '../../helloWorld'
51
-
52
- // this to an overload for basedClient
53
- */
@@ -1,109 +0,0 @@
1
- import { BasedFunctionConfig } from '@based/functions'
2
- import { readFile, writeFile } from 'fs-extra'
3
-
4
- export const updateTypesPath = async (
5
- fns: (
6
- | { config: BasedFunctionConfig; path: string }
7
- | { config: BasedFunctionConfig; payload: string; result: string }
8
- )[],
9
- opts: {
10
- isAbstract?: boolean
11
- imports?: string[]
12
- originalDeclartionPath: string
13
- declarationPath: string
14
- }
15
- ): Promise<string | void> => {
16
- let decFile = ''
17
-
18
- try {
19
- decFile = (await readFile(opts.originalDeclartionPath)).toString('utf-8')
20
- } catch (err) {
21
- throw new Error(`Cannot find ${opts.originalDeclartionPath}`)
22
- }
23
-
24
- let imports = opts.imports ? opts.imports.join('\n') + '\n' : '\n'
25
- let callFns = '\n'
26
- let queryFns = '\n'
27
- let fnCnt = 0
28
- let queryCnt = 0
29
- let queryMap = '\n'
30
- let needsParsing = opts.imports ?? false
31
-
32
- const abstractPrefix = opts.isAbstract ? 'abstract ' : ''
33
-
34
- for (const fn of fns) {
35
- if (fn.config.type === 'function') {
36
- needsParsing = true
37
- fnCnt++
38
- if ('path' in fn) {
39
- const name = 'FN_Type_' + fnCnt
40
- imports += `import type ${name} from '${fn.path}';\n`
41
- callFns += `
42
- ${abstractPrefix}call(
43
- name: '${fn.config.name}',
44
- payload: Parameters<typeof ${name}>[1],
45
- ${opts.isAbstract ? 'ctx?: Context' : 'opts?: CallOptions'}
46
- ): ReturnType<typeof ${name}>;
47
- `
48
- } else {
49
- callFns += `
50
- ${abstractPrefix}call(
51
- name: '${fn.config.name}',
52
- payload: ${fn.payload},
53
- ${opts.isAbstract ? 'ctx?: Context' : 'opts?: CallOptions'}
54
- ): Promise<${fn.result}>
55
- `
56
- }
57
- } else if (fn.config.type === 'query') {
58
- queryCnt++
59
- if ('path' in fn) {
60
- const name = 'Q_Type_' + queryCnt
61
- imports += `import type ${name} from '${fn.path}';\n`
62
- queryMap += `'${fn.config.name}': { payload: Parameters<typeof ${name}>[1], result: Parameters<Parameters<typeof ${name}>[2]>[0] },`
63
- queryFns += `
64
- ${abstractPrefix}query(name: '${fn.config.name}', payload: Parameters<typeof ${name}>[1], opts?: QueryOptions): BasedQuery<Parameters<typeof ${name}>[1],Parameters<Parameters<typeof ${name}>[2]>[0]>;
65
- `
66
- } else {
67
- queryMap += `'${fn.config.name}': { payload: ${fn.payload}, result: ${fn.result} },`
68
- queryFns += `
69
- ${abstractPrefix}query(name: '${fn.config.name}', payload: ${fn.payload}, opts?: QueryOptions): BasedQuery<${fn.payload},${fn.result}>;
70
- `
71
- }
72
- }
73
- }
74
- if (needsParsing) {
75
- let x = imports + decFile
76
- if (fnCnt > 0) {
77
- if (opts.isAbstract) {
78
- x = x.replace(
79
- 'abstract call(name: string, payload?: any, ctx?: Context): Promise<any>;',
80
- callFns
81
- )
82
- } else {
83
- x = x.replace(
84
- 'call(name: string, payload?: any, opts?: CallOptions): Promise<any>;',
85
- callFns
86
- )
87
- }
88
- }
89
- if (queryCnt > 0) {
90
- if (opts.isAbstract) {
91
- x = x.replace(
92
- `abstract query(name: string, payload?: any): BasedQuery;`,
93
- queryFns
94
- )
95
- } else {
96
- x = x.replace(
97
- `query(name: string, payload?: any, opts?: QueryOptions): BasedQuery;`,
98
- queryFns
99
- )
100
- }
101
- x = x.replace(
102
- /export type QueryMap = ([^@]*?)\};([^@]*?)\};/,
103
- `export type QueryMap = {${queryMap}}`
104
- )
105
- }
106
- await writeFile(opts.declarationPath, x)
107
- return opts.declarationPath
108
- }
109
- }
@@ -1,4 +0,0 @@
1
- {
2
- "name": "hello-world",
3
- "type": "function"
4
- }
@@ -1,30 +0,0 @@
1
- import { BasedFunction } from '@based/functions'
2
-
3
- type Flap<T extends string> = {
4
- bla: T
5
- }
6
-
7
- const helloWorld: BasedFunction<
8
- {
9
- msg: string
10
- gurt: number
11
- },
12
- {
13
- bla: number
14
- msg: string
15
- f: Flap<'snurp'>
16
- }
17
- > = async (based, payload) => {
18
- return { msg: 'hello ' + payload.msg, bla: 0, f: { bla: 'snurp' } }
19
- }
20
-
21
- export default helloWorld
22
-
23
- /*
24
- import type HelloWorld from '../../type-gen/test/examples/helloWorld/index.ts'
25
- call(
26
- name: 'hello-world',
27
- payload: Parameters<typeof HelloWorld>[1],
28
- opts?: CallOptions
29
- ): ReturnType<typeof HelloWorld>
30
- */
@@ -1,4 +0,0 @@
1
- {
2
- "name": "counter",
3
- "type": "query"
4
- }
@@ -1,28 +0,0 @@
1
- import { BasedQueryFunction } from '@based/functions'
2
-
3
- const counter: BasedQueryFunction<
4
- {
5
- msg: string
6
- gurt: number
7
- } | void,
8
- { cnt: number }
9
- > = async (based, payload, update) => {
10
- let cnt = 0
11
- const timer = setInterval(() => {
12
- update({ cnt: ++cnt })
13
- }, 100)
14
- return () => {
15
- clearInterval(timer)
16
- }
17
- }
18
-
19
- export default counter
20
-
21
- /*
22
- import type HelloWorld from '../../type-gen/test/examples/helloWorld/index.ts'
23
- call(
24
- name: 'hello-world',
25
- payload: Parameters<typeof HelloWorld>[1],
26
- opts?: CallOptions
27
- ): Parameters<Parameters<typeof HelloWorld>[2]>[0],
28
- */
package/test/types.ts DELETED
@@ -1,56 +0,0 @@
1
- import test from 'ava'
2
- import { updateTypes } from '../src'
3
- import { join } from 'path'
4
- import { readFile } from 'fs-extra'
5
-
6
- test.serial('Generate types file from examples', async (t) => {
7
- const result = await updateTypes([
8
- {
9
- config: require('./examples/helloWorld/based.config.json'),
10
- path: join(__dirname, '/examples/helloWorld/index.ts'),
11
- },
12
- {
13
- config: require('./examples/query/based.config.json'),
14
- path: join(__dirname, '/examples/query/index.ts'),
15
- },
16
- {
17
- config: { name: 'db:set', type: 'function' },
18
- payload: 'any',
19
- result: 'any',
20
- },
21
- {
22
- config: { name: 'db:update-schema', type: 'function' },
23
- payload: 'any',
24
- result: 'any',
25
- },
26
- {
27
- config: { name: 'db', type: 'query' },
28
- payload: 'any',
29
- result: 'any',
30
- },
31
- {
32
- config: { name: 'db:schema', type: 'query' },
33
- payload: 'any',
34
- result: 'any',
35
- },
36
- ])
37
-
38
- const files = await Promise.all(
39
- ['client/dist/index.d.ts', 'functions/dist/client.d.ts'].map((f) =>
40
- readFile(join(__dirname, '../../' + f), {
41
- encoding: 'utf-8',
42
- })
43
- )
44
- )
45
-
46
- t.is(result.clientPath, join(__dirname, '../../client/dist/index.d.ts'))
47
- t.is(result.functionPath, join(__dirname, '../../functions/dist/client.d.ts'))
48
-
49
- for (const file of files) {
50
- t.true(file.includes('counter'))
51
- t.true(file.includes('db:schema'))
52
- t.true(file.includes('db:update-schema'))
53
- t.true(file.includes('db:set'))
54
- t.true(file.includes('hello-world'))
55
- }
56
- })
package/tsconfig.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "dist",
6
- "declarationMap": true
7
- },
8
- "include": ["src/**/*", "src/**/*.json"],
9
- "exclude": ["node_modules", "test", "dist", "tmp", "examples"]
10
- }