@voxgig/sdkgen 0.0.7 → 0.0.8

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.
@@ -0,0 +1,2 @@
1
+ declare function PrepareOpenAPI(inspec: any, ctx: any): Promise<boolean>;
2
+ export { PrepareOpenAPI };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PrepareOpenAPI = PrepareOpenAPI;
4
+ async function PrepareOpenAPI(inspec, ctx) {
5
+ // TODO: avoid rebuilding if unchanged
6
+ // const source = Fs.readFileSync(ctx.def, 'utf8')
7
+ // const config = await createConfig({})
8
+ // const bundle = await bundleFromString({
9
+ // source,
10
+ // config,
11
+ // dereference: true,
12
+ // })
13
+ // // console.log('BUNDLE', bundle)
14
+ // Fs.writeFileSync(
15
+ // ctx.folder + '/../model/def.jsonic',
16
+ // JSON.stringify(bundle.bundle.parsed, null, 2)
17
+ // )
18
+ // const spec: any = {}
19
+ // spec.main = {
20
+ // sdk: {
21
+ // api: {
22
+ // // cmap
23
+ // /*
24
+ // path: each(bundle.bundle.parsed.paths, (path: any) => ({
25
+ // param: {}
26
+ // }))
27
+ // */
28
+ // }
29
+ // }
30
+ // }
31
+ // Fs.writeFileSync(
32
+ // ctx.folder + '/../model/spec.jsonic',
33
+ // JSON.stringify(spec, null, 2)
34
+ // )
35
+ return false;
36
+ }
37
+ //# sourceMappingURL=prepare-openapi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare-openapi.js","sourceRoot":"","sources":["../src/prepare-openapi.ts"],"names":[],"mappings":";;AAyDE,wCAAc;AAjDhB,KAAK,UAAU,cAAc,CAAC,MAAW,EAAE,GAAQ;IAEjD,sCAAsC;IAEtC,kDAAkD;IAElD,wCAAwC;IACxC,0CAA0C;IAC1C,YAAY;IACZ,YAAY;IACZ,uBAAuB;IACvB,KAAK;IAEL,mCAAmC;IAEnC,oBAAoB;IACpB,yCAAyC;IACzC,kDAAkD;IAClD,IAAI;IAGJ,uBAAuB;IAEvB,gBAAgB;IAChB,WAAW;IACX,aAAa;IACb,gBAAgB;IAChB,WAAW;IACX,yEAAyE;IACzE,4BAA4B;IAC5B,sBAAsB;IACtB,qBAAqB;IACrB,QAAQ;IACR,MAAM;IACN,IAAI;IAGJ,oBAAoB;IACpB,0CAA0C;IAC1C,kCAAkC;IAClC,IAAI;IAGJ,OAAO,KAAK,CAAA;AACd,CAAC"}
package/dist/sdkgen.d.ts CHANGED
@@ -1,12 +1,17 @@
1
1
  type SdkGenOptions = {
2
2
  folder: string;
3
+ def?: string;
3
4
  fs: any;
5
+ model?: {
6
+ folder: string;
7
+ entity: any;
8
+ };
4
9
  };
5
10
  declare function SdkGen(opts: SdkGenOptions): {
6
- generate: (spec: any) => void;
11
+ generate: (spec: any) => Promise<void>;
7
12
  };
8
13
  declare namespace SdkGen {
9
- var makeBuild: (root: any, opts: SdkGenOptions) => (model: any, build: any) => void;
14
+ var makeBuild: (root: any, opts: SdkGenOptions) => Promise<(model: any, build: any) => Promise<void>>;
10
15
  }
11
16
  export type { SdkGenOptions, };
12
17
  export { SdkGen, };
package/dist/sdkgen.js CHANGED
@@ -27,24 +27,47 @@ Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.SdkGen = SdkGen;
28
28
  const Fs = __importStar(require("node:fs"));
29
29
  const jostraca_1 = require("jostraca");
30
+ const apidef_1 = require("@voxgig/apidef");
31
+ const prepare_openapi_1 = require("./prepare-openapi");
30
32
  function SdkGen(opts) {
31
33
  const fs = opts.fs || Fs;
32
34
  const folder = opts.folder || '.';
35
+ const def = opts.def || 'def.yml';
33
36
  const jostraca = (0, jostraca_1.Jostraca)();
34
37
  // const { cmp, each, Project, Folder, File, Code } = jostraca
35
- function generate(spec) {
38
+ async function generate(spec) {
36
39
  const { model, root } = spec;
40
+ /*
41
+ if (await prepare(spec, { fs, folder, def })) {
42
+ return
43
+ }
44
+ */
37
45
  jostraca.generate({ fs, folder }, () => root({ model }));
38
46
  }
47
+ async function prepare(spec, ctx) {
48
+ return await (0, prepare_openapi_1.PrepareOpenAPI)(spec, ctx);
49
+ }
39
50
  return {
40
51
  generate,
41
52
  // cmp, each,
42
53
  // Project, Folder, File, Code
43
54
  };
44
55
  }
45
- SdkGen.makeBuild = function (root, opts) {
56
+ SdkGen.makeBuild = async function (root, opts) {
57
+ console.log('SDKGEN makeBuild');
46
58
  const sdkgen = SdkGen(opts);
47
- return function build(model, build) {
59
+ const apidef = (0, apidef_1.ApiDef)();
60
+ const spec = {
61
+ def: opts.def,
62
+ kind: 'openapi-3',
63
+ model: opts.model ? (opts.model.folder + '/api.jsonic') : undefined,
64
+ meta: {
65
+ name: 'foo'
66
+ },
67
+ entity: opts.model ? opts.model.entity : undefined,
68
+ };
69
+ await apidef.watch(spec);
70
+ return async function build(model, build) {
48
71
  return sdkgen.generate({ model, build, root });
49
72
  };
50
73
  };
@@ -1 +1 @@
1
- {"version":3,"file":"sdkgen.js","sourceRoot":"","sources":["../src/sdkgen.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;;;;;;;;;;;;;;;;;;;;AA0DlD,wBAAM;AAxDR,4CAA6B;AAE7B,uCAAmC;AAWnC,SAAS,MAAM,CAAC,IAAmB;IACjC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,IAAI,EAAE,CAAA;IACxB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,GAAG,CAAA;IACjC,MAAM,QAAQ,GAAG,IAAA,mBAAQ,GAAE,CAAA;IAE3B,8DAA8D;IAE9D,SAAS,QAAQ,CAAC,IAAS;QACzB,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;QAE5B,QAAQ,CAAC,QAAQ,CACf,EAAE,EAAE,EAAE,MAAM,EAAE,EACd,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CACtB,CAAA;IACH,CAAC;IAED,OAAO;QACL,QAAQ;QA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QAEb,8BAA8B;KAC/B,CAAA;AAEH,CAAC;AAGD,MAAM,CAAC,SAAS,GAAG,KAAK,WAAU,IAAS,EAAE,IAAmB;IAC9D,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;IAC/B,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IAE3B,MAAM,MAAM,GAAG,IAAA,eAAM,GAAE,CAAA;IAEvB,MAAM,IAAI,GAAG;QACX,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS;QACnE,IAAI,EAAE;YACJ,IAAI,EAAE,KAAK;SACZ;QACD,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;KACnD,CAAA;IAED,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAExB,OAAO,KAAK,UAAU,KAAK,CAAC,KAAU,EAAE,KAAU;QAChD,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAChD,CAAC,CAAA;AACH,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxgig/sdkgen",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "main": "dist/sdkgen.js",
5
5
  "type": "commonjs",
6
6
  "types": "dist/sdkgen.d.ts",
@@ -34,13 +34,17 @@
34
34
  ],
35
35
  "devDependencies": {
36
36
  "@hapi/code": "^9.0.3",
37
- "@types/node": "22.3.0",
37
+ "@types/js-yaml": "^4.0.9",
38
+ "@types/node": "22.5.0",
38
39
  "aontu": "^0.21.1",
39
- "esbuild": "^0.23.0",
40
+ "esbuild": "^0.23.1",
41
+ "json-schema-to-ts": "^3.1.0",
40
42
  "memfs": "^4.11.1",
41
43
  "typescript": "^5.5.4"
42
44
  },
43
45
  "dependencies": {
44
- "jostraca": "^0.1.6"
46
+ "@redocly/openapi-core": "^1.20.1",
47
+ "@voxgig/apidef": "^0.0.2",
48
+ "jostraca": "^0.2.0"
45
49
  }
46
50
  }
@@ -0,0 +1,59 @@
1
+
2
+ import * as Fs from 'node:fs'
3
+
4
+ import { each } from 'jostraca'
5
+
6
+ import { bundleFromString, createConfig } from '@redocly/openapi-core'
7
+
8
+
9
+ async function PrepareOpenAPI(inspec: any, ctx: any) {
10
+
11
+ // TODO: avoid rebuilding if unchanged
12
+
13
+ // const source = Fs.readFileSync(ctx.def, 'utf8')
14
+
15
+ // const config = await createConfig({})
16
+ // const bundle = await bundleFromString({
17
+ // source,
18
+ // config,
19
+ // dereference: true,
20
+ // })
21
+
22
+ // // console.log('BUNDLE', bundle)
23
+
24
+ // Fs.writeFileSync(
25
+ // ctx.folder + '/../model/def.jsonic',
26
+ // JSON.stringify(bundle.bundle.parsed, null, 2)
27
+ // )
28
+
29
+
30
+ // const spec: any = {}
31
+
32
+ // spec.main = {
33
+ // sdk: {
34
+ // api: {
35
+ // // cmap
36
+ // /*
37
+ // path: each(bundle.bundle.parsed.paths, (path: any) => ({
38
+ // param: {}
39
+ // }))
40
+ // */
41
+ // }
42
+ // }
43
+ // }
44
+
45
+
46
+ // Fs.writeFileSync(
47
+ // ctx.folder + '/../model/spec.jsonic',
48
+ // JSON.stringify(spec, null, 2)
49
+ // )
50
+
51
+
52
+ return false
53
+ }
54
+
55
+
56
+
57
+ export {
58
+ PrepareOpenAPI
59
+ }
package/src/sdkgen.ts CHANGED
@@ -4,31 +4,53 @@ import * as Fs from 'node:fs'
4
4
 
5
5
  import { Jostraca } from 'jostraca'
6
6
 
7
+ import { ApiDef } from '@voxgig/apidef'
8
+
9
+
10
+ import { PrepareOpenAPI } from './prepare-openapi'
11
+
7
12
 
8
13
  type SdkGenOptions = {
9
14
  folder: string
15
+ def?: string
10
16
  fs: any
17
+ model?: {
18
+ folder: string
19
+ entity: any
20
+ }
11
21
  }
12
22
 
13
23
 
14
24
 
15
-
16
25
  function SdkGen(opts: SdkGenOptions) {
17
26
  const fs = opts.fs || Fs
18
27
  const folder = opts.folder || '.'
28
+ const def = opts.def || 'def.yml'
19
29
  const jostraca = Jostraca()
20
30
 
21
31
  // const { cmp, each, Project, Folder, File, Code } = jostraca
22
32
 
23
- function generate(spec: any) {
33
+ async function generate(spec: any) {
24
34
  const { model, root } = spec
25
35
 
36
+ /*
37
+ if (await prepare(spec, { fs, folder, def })) {
38
+ return
39
+ }
40
+ */
41
+
26
42
  jostraca.generate(
27
43
  { fs, folder },
28
44
  () => root({ model })
29
45
  )
30
46
  }
31
47
 
48
+
49
+ async function prepare(spec: any, ctx: any) {
50
+ return await PrepareOpenAPI(spec, ctx)
51
+ }
52
+
53
+
32
54
  return {
33
55
  generate,
34
56
 
@@ -40,10 +62,25 @@ function SdkGen(opts: SdkGenOptions) {
40
62
  }
41
63
 
42
64
 
43
- SdkGen.makeBuild = function(root: any, opts: SdkGenOptions) {
65
+ SdkGen.makeBuild = async function(root: any, opts: SdkGenOptions) {
66
+ console.log('SDKGEN makeBuild')
44
67
  const sdkgen = SdkGen(opts)
45
68
 
46
- return function build(model: any, build: any) {
69
+ const apidef = ApiDef()
70
+
71
+ const spec = {
72
+ def: opts.def,
73
+ kind: 'openapi-3',
74
+ model: opts.model ? (opts.model.folder + '/api.jsonic') : undefined,
75
+ meta: {
76
+ name: 'foo'
77
+ },
78
+ entity: opts.model ? opts.model.entity : undefined,
79
+ }
80
+
81
+ await apidef.watch(spec)
82
+
83
+ return async function build(model: any, build: any) {
47
84
  return sdkgen.generate({ model, build, root })
48
85
  }
49
86
  }