@based/type-gen 0.0.5 → 0.0.7
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/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { updateTypesPath } from
|
|
2
|
-
import { createRequire } from
|
|
1
|
+
import { updateTypesPath } from './updateTypesPath.js';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
3
|
const require = createRequire(import.meta.url);
|
|
4
4
|
export const updateTypes = async (fns, opts = {}) => {
|
|
5
5
|
const inputClientPath = opts.clientPath ||
|
|
6
|
-
require.resolve(
|
|
6
|
+
require.resolve('@based/client', { paths: [process.cwd()] });
|
|
7
7
|
const inputFunctionPath = opts.functionPath ||
|
|
8
|
-
require.resolve(
|
|
8
|
+
require.resolve('@based/functions', { paths: [process.cwd()] });
|
|
9
9
|
let clientPath;
|
|
10
10
|
let functionPath;
|
|
11
11
|
if (inputClientPath) {
|
|
12
|
-
const declarationPath = inputClientPath.replace(
|
|
13
|
-
const
|
|
12
|
+
const declarationPath = inputClientPath.replace('/index.js', '/index.d.ts');
|
|
13
|
+
const originalDeclarationPath = inputClientPath.replace('/index.js', '/index_original.d.ts');
|
|
14
14
|
clientPath = await updateTypesPath(fns, {
|
|
15
15
|
imports: opts.imports,
|
|
16
|
-
|
|
16
|
+
originalDeclarationPath,
|
|
17
17
|
declarationPath,
|
|
18
18
|
}).catch((e) => {
|
|
19
19
|
console.error(e, {
|
|
20
20
|
imports: opts.imports,
|
|
21
|
-
|
|
21
|
+
originalDeclarationPath,
|
|
22
22
|
declarationPath,
|
|
23
23
|
});
|
|
24
|
-
console.error(
|
|
24
|
+
console.error('Cannot find original declaration file - you may need to upgrade to @based/client ^4.8.8');
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
if (inputFunctionPath) {
|
|
28
|
-
const declarationPath = inputFunctionPath.replace(
|
|
29
|
-
const
|
|
28
|
+
const declarationPath = inputFunctionPath.replace('/index.js', '/client.d.ts');
|
|
29
|
+
const originalDeclarationPath = inputFunctionPath.replace('/index.js', '/client_original.d.ts');
|
|
30
30
|
functionPath = await updateTypesPath(fns, {
|
|
31
31
|
imports: opts.imports,
|
|
32
|
-
|
|
32
|
+
originalDeclarationPath,
|
|
33
33
|
declarationPath,
|
|
34
34
|
isAbstract: true,
|
|
35
35
|
}).catch(() => {
|
|
36
|
-
console.error(
|
|
36
|
+
console.error('Cannot find original declaration file - you may need to upgrade to @based/functions ^2.2.4');
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
return {
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +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,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X,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,uBAAuB,GAAG,iBAAiB,CAAC,OAAO,CACvD,WAAW,EACX,uBAAuB,CACxB,CAAA;QACD,YAAY,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE;YACxC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,uBAAuB;YACvB,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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BasedFunctionConfig } from
|
|
1
|
+
import { BasedFunctionConfig } from '@based/functions';
|
|
2
2
|
export declare const updateTypesPath: (fns: ({
|
|
3
3
|
config: BasedFunctionConfig;
|
|
4
4
|
path: string;
|
|
@@ -9,6 +9,6 @@ export declare const updateTypesPath: (fns: ({
|
|
|
9
9
|
})[], opts: {
|
|
10
10
|
isAbstract?: boolean;
|
|
11
11
|
imports?: string[];
|
|
12
|
-
|
|
12
|
+
originalDeclarationPath: string;
|
|
13
13
|
declarationPath: string;
|
|
14
14
|
}) => Promise<string | void>;
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { readFile, writeFile } from
|
|
1
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
2
2
|
export const updateTypesPath = async (fns, opts) => {
|
|
3
|
-
let decFile =
|
|
3
|
+
let decFile = '';
|
|
4
4
|
try {
|
|
5
|
-
decFile = (await readFile(opts.
|
|
5
|
+
decFile = (await readFile(opts.originalDeclarationPath)).toString('utf-8');
|
|
6
6
|
}
|
|
7
7
|
catch (err) {
|
|
8
|
-
throw new Error(`Cannot find ${opts.
|
|
8
|
+
throw new Error(`Cannot find ${opts.originalDeclarationPath}`);
|
|
9
9
|
}
|
|
10
|
-
let imports = opts.imports ? opts.imports.join(
|
|
11
|
-
let callFns =
|
|
12
|
-
let queryFns =
|
|
10
|
+
let imports = opts.imports ? opts.imports.join('\n') + '\n' : '\n';
|
|
11
|
+
let callFns = '\n';
|
|
12
|
+
let queryFns = '\n';
|
|
13
13
|
let fnCnt = 0;
|
|
14
14
|
let queryCnt = 0;
|
|
15
|
-
let queryMap =
|
|
15
|
+
let queryMap = '\n';
|
|
16
16
|
let needsParsing = opts.imports ?? false;
|
|
17
|
-
const abstractPrefix = opts.isAbstract ?
|
|
17
|
+
const abstractPrefix = opts.isAbstract ? 'abstract ' : '';
|
|
18
18
|
for (const fn of fns) {
|
|
19
|
-
if (fn.config.type ===
|
|
19
|
+
if (fn.config.type === 'function') {
|
|
20
20
|
needsParsing = true;
|
|
21
21
|
fnCnt++;
|
|
22
|
-
if (
|
|
23
|
-
const name =
|
|
22
|
+
if ('path' in fn) {
|
|
23
|
+
const name = 'FN_Type_' + fnCnt;
|
|
24
24
|
imports += `import type ${name} from '${fn.path}';\n`;
|
|
25
25
|
callFns += `
|
|
26
26
|
${abstractPrefix}call(
|
|
27
27
|
name: '${fn.config.name}',
|
|
28
28
|
payload: Parameters<typeof ${name}>[1],
|
|
29
|
-
${opts.isAbstract ?
|
|
29
|
+
${opts.isAbstract ? 'ctx?: BasedProvider' : 'opts?: CallOptions'}
|
|
30
30
|
): ReturnType<typeof ${name}>;
|
|
31
31
|
`;
|
|
32
32
|
}
|
|
@@ -35,15 +35,15 @@ export const updateTypesPath = async (fns, opts) => {
|
|
|
35
35
|
${abstractPrefix}call(
|
|
36
36
|
name: '${fn.config.name}',
|
|
37
37
|
payload: ${fn.payload},
|
|
38
|
-
${opts.isAbstract ?
|
|
38
|
+
${opts.isAbstract ? 'ctx?: BasedProvider' : 'opts?: CallOptions'}
|
|
39
39
|
): Promise<${fn.result}>
|
|
40
40
|
`;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
else if (fn.config.type ===
|
|
43
|
+
else if (fn.config.type === 'query') {
|
|
44
44
|
queryCnt++;
|
|
45
|
-
if (
|
|
46
|
-
const name =
|
|
45
|
+
if ('path' in fn) {
|
|
46
|
+
const name = 'Q_Type_' + queryCnt;
|
|
47
47
|
imports += `import type ${name} from '${fn.path}';\n`;
|
|
48
48
|
queryMap += `'${fn.config.name}': { payload: Parameters<typeof ${name}>[1], result: Parameters<Parameters<typeof ${name}>[2]>[0] },`;
|
|
49
49
|
queryFns += `
|
|
@@ -62,10 +62,10 @@ export const updateTypesPath = async (fns, opts) => {
|
|
|
62
62
|
let x = imports + decFile;
|
|
63
63
|
if (fnCnt > 0) {
|
|
64
64
|
if (opts.isAbstract) {
|
|
65
|
-
x = x.replace(
|
|
65
|
+
x = x.replace('abstract call(name: string, payload?: any, ctx?: BasedProvider): Promise<any>;', callFns);
|
|
66
66
|
}
|
|
67
67
|
else {
|
|
68
|
-
x = x.replace(
|
|
68
|
+
x = x.replace('call(name: string, payload?: any, opts?: CallOptions): Promise<any>;', callFns);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
if (queryCnt > 0) {
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"updateTypesPath.js","sourceRoot":"","sources":["../../src/update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C,MAAM;KACvI,CAAA;YACC,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,YAAY,EAAE,CAAC;QACjB,IAAI,CAAC,GAAG,OAAO,GAAG,OAAO,CAAA;QACzB,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACd,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACpB,CAAC,GAAG,CAAC,CAAC,OAAO,CACX,gFAAgF,EAChF,OAAO,CACR,CAAA;YACH,CAAC;iBAAM,CAAC;gBACN,CAAC,GAAG,CAAC,CAAC,OAAO,CACX,sEAAsE,EACtE,OAAO,CACR,CAAA;YACH,CAAC;QACH,CAAC;QACD,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;YACjB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACpB,CAAC,GAAG,CAAC,CAAC,OAAO,CACX,0DAA0D,EAC1D,QAAQ,CACT,CAAA;YACH,CAAC;iBAAM,CAAC;gBACN,CAAC,GAAG,CAAC,CAAC,OAAO,CACX,sEAAsE,EACtE,QAAQ,CACT,CAAA;YACH,CAAC;YACD,CAAC,GAAG,CAAC,CAAC,OAAO,CACX,0DAA0D,EAC1D,2BAA2B,QAAQ,GAAG,CACvC,CAAA;QACH,CAAC;QACD,MAAM,SAAS,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,CAAA;QACxC,OAAO,IAAI,CAAC,eAAe,CAAA;IAC7B,CAAC;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@based/type-gen",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
"@babel/parser": "^7.18.6",
|
|
17
17
|
"@babel/traverse": "^7.18.6",
|
|
18
18
|
"utility-types": "^3.10.0",
|
|
19
|
-
"@saulx/utils": "^
|
|
20
|
-
"@based/functions": "^3.0.
|
|
19
|
+
"@saulx/utils": "^5.0.0",
|
|
20
|
+
"@based/functions": "^3.0.2"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/fs-extra": "11.0.3",
|
|
24
24
|
"ts-node": "10.9.1",
|
|
25
25
|
"typescript": "^5.2.2",
|
|
26
26
|
"rimraf": "^3.0.2",
|
|
27
|
-
"@based/client": "^
|
|
27
|
+
"@based/client": "^6.1.0",
|
|
28
28
|
"ava": "5.3.1"
|
|
29
29
|
},
|
|
30
30
|
"ava": {
|