@voxgig/model 3.5.0 → 5.0.0

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 (47) hide show
  1. package/bin/voxgig-model +150 -31
  2. package/dist/{lib/build.d.ts → build.d.ts} +6 -5
  3. package/dist/{lib/build.js → build.js} +4 -3
  4. package/dist/build.js.map +1 -0
  5. package/dist/{lib/builder → builder}/local.js +13 -34
  6. package/dist/builder/local.js.map +1 -0
  7. package/dist/{lib/builder → builder}/model.js +5 -0
  8. package/dist/builder/model.js.map +1 -0
  9. package/dist/config.d.ts +12 -0
  10. package/dist/{lib/config.js → config.js} +6 -4
  11. package/dist/config.js.map +1 -0
  12. package/dist/model.d.ts +8 -7
  13. package/dist/model.js +35 -20
  14. package/dist/model.js.map +1 -1
  15. package/dist/tsconfig.tsbuildinfo +1 -0
  16. package/dist/{lib/types.d.ts → types.d.ts} +25 -3
  17. package/dist/types.js +4 -0
  18. package/dist/types.js.map +1 -0
  19. package/dist/{lib/watch.d.ts → watch.d.ts} +15 -18
  20. package/dist/watch.js +227 -0
  21. package/dist/watch.js.map +1 -0
  22. package/package.json +19 -20
  23. package/dist/lib/build.js.map +0 -1
  24. package/dist/lib/builder/local.js.map +0 -1
  25. package/dist/lib/builder/model.js.map +0 -1
  26. package/dist/lib/config.d.ts +0 -11
  27. package/dist/lib/config.js.map +0 -1
  28. package/dist/lib/model-builder.d.ts +0 -0
  29. package/dist/lib/model-builder.js +0 -2
  30. package/dist/lib/model-builder.js.map +0 -1
  31. package/dist/lib/types.js +0 -3
  32. package/dist/lib/types.js.map +0 -1
  33. package/dist/lib/util.d.ts +0 -7
  34. package/dist/lib/util.js +0 -94
  35. package/dist/lib/util.js.map +0 -1
  36. package/dist/lib/watch.js +0 -172
  37. package/dist/lib/watch.js.map +0 -1
  38. package/dist/model.min.js +0 -94
  39. package/lib/build.ts +0 -138
  40. package/lib/builder/local.ts +0 -130
  41. package/lib/builder/model.ts +0 -37
  42. package/lib/config.ts +0 -50
  43. package/lib/types.ts +0 -67
  44. package/lib/watch.ts +0 -250
  45. package/model.ts +0 -145
  46. /package/dist/{lib/builder → builder}/local.d.ts +0 -0
  47. /package/dist/{lib/builder → builder}/model.d.ts +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"watch.js","sourceRoot":"","sources":["../../lib/watch.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;AAEpD,0DAA4B;AAK5B,mCAAmC;AACnC,uCAAoC;AAEpC,0CAA4C;AAG5C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAA;AACzB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;AAgBzB,MAAM,KAAK;IAWT,YAAY,IAAS;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,GAAG,GAAG,IAAI,oBAAS,EAAE,CAAA;QAC1B,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAA;QACzB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAA;QACd,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;QACf,IAAI,CAAC,MAAM,GAAG,EAAE,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QAEpB,kCAAkC;QAClC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEnC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAY,EAAE,EAAE;YAC3C,6DAA6D;YAC7D,iEAAiE;YACjE,oEAAoE;YACpE,0DAA0D;YAC1D,4DAA4D;YAE5D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YAE9B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,KAAK,CAAC,CAAA;YACjE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AAS,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACxC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,CAAA;YAC3B,KAAK,IAAI,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;gBACjD,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,CAAA;YAC7B,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACxB,CAAC;CACF;AAIC,sBAAK"}
package/dist/model.min.js DELETED
@@ -1,94 +0,0 @@
1
- "use strict";
2
- /* Copyright © 2021-2022 Voxgig Ltd, MIT License. */
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.Model = void 0;
8
- // TODO: remove need for this
9
- const fs_1 = __importDefault(require("fs"));
10
- const config_1 = require("./lib/config");
11
- const watch_1 = require("./lib/watch");
12
- const model_1 = require("./lib/builder/model");
13
- const local_1 = require("./lib/builder/local");
14
- const intern = makeIntern();
15
- class Model {
16
- constructor(spec) {
17
- this.trigger_model = false;
18
- this.config = intern.makeConfig(spec, {
19
- path: '/',
20
- build: async (build) => {
21
- console.log('TRIGGER MODEL', this.trigger_model);
22
- if (this.trigger_model) {
23
- console.log('CONFIG CHANGE'); //, this)
24
- // console.trace()
25
- // rebuild if config changes
26
- // TODO: fix!!!
27
- this.build.use.config.watch.last.build = build;
28
- return this.watch.run(true);
29
- }
30
- else {
31
- this.trigger_model = true;
32
- return { ok: true };
33
- }
34
- }
35
- });
36
- this.build = {
37
- src: spec.src,
38
- path: spec.path,
39
- base: spec.base,
40
- use: { config: this.config },
41
- res: [
42
- {
43
- path: '/',
44
- build: model_1.model_builder
45
- },
46
- {
47
- path: '/',
48
- build: local_1.local_builder
49
- }
50
- ]
51
- };
52
- this.watch = new watch_1.Watch(this.build);
53
- }
54
- async run() {
55
- this.trigger_model = false;
56
- let br = await this.config.run();
57
- return br.ok ? this.watch.run(true) : br;
58
- }
59
- async start() {
60
- console.log('MODEL START');
61
- this.trigger_model = false;
62
- await this.config.start();
63
- return this.watch.start();
64
- }
65
- async stop() {
66
- return this.watch.stop();
67
- }
68
- }
69
- exports.Model = Model;
70
- function makeIntern() {
71
- return {
72
- makeConfig(spec, trigger_model_build) {
73
- let cbase = spec.base + '/config';
74
- let cpath = cbase + '/config.jsonic';
75
- // Build should load file
76
- let src = fs_1.default.readFileSync(cpath).toString();
77
- let cspec = {
78
- src: src,
79
- path: cpath,
80
- base: cbase,
81
- res: [
82
- // Generate full config model and save as a file.
83
- {
84
- path: '/',
85
- build: model_1.model_builder
86
- },
87
- trigger_model_build
88
- ]
89
- };
90
- return new config_1.Config(cspec);
91
- }
92
- };
93
- }
94
- //# sourceMappingURL=model.js.map
package/lib/build.ts DELETED
@@ -1,138 +0,0 @@
1
- /* Copyright © 2021-2023 Voxgig Ltd, MIT License. */
2
-
3
-
4
- import { Aontu, Val, Nil, Context } from 'aontu'
5
-
6
-
7
- import type {
8
- Build,
9
- BuildResult,
10
- BuildAction,
11
- Builder,
12
- BuildContext,
13
- Spec,
14
- } from './types'
15
-
16
-
17
-
18
-
19
- class BuildImpl implements Build {
20
- id
21
- src
22
- base
23
- path
24
- root: any = Nil.make()
25
- opts: any
26
- res
27
- spec
28
- model: any
29
- use = {}
30
- err: any[] = []
31
- ctx: BuildContext
32
-
33
-
34
- constructor(spec: Spec) {
35
- this.id = String(Math.random()).substring(3, 9)
36
-
37
- this.spec = spec
38
- this.src = spec.src
39
- this.base = null == spec.base ? '' : spec.base
40
- this.path = null == spec.path ? '' : spec.path
41
- this.opts = {}
42
- this.ctx = { step: 'pre', state: {} }
43
-
44
- if (null != spec.base) {
45
- this.opts.base = spec.base
46
- this.opts.path = spec.path
47
- }
48
-
49
- if (null != spec.require) {
50
- this.opts.require = spec.require
51
- }
52
-
53
- this.res = spec.res || []
54
-
55
- Object.assign(this.use, spec.use || {})
56
- }
57
-
58
-
59
- async run(): Promise<BuildResult> {
60
- let hasErr = false
61
-
62
- // this.ctx.step = 'pre'
63
- this.ctx = { step: 'pre', state: {} }
64
- const brlog = []
65
-
66
- for (let builder of this.res) {
67
- try {
68
- let br = await builder.build(this, this.ctx)
69
- br.step = this.ctx.step
70
- br.path = builder.path
71
- br.builder = builder.build.name
72
- brlog.push(br)
73
- }
74
- catch (e: any) {
75
- this.err.push(e)
76
- hasErr = true
77
- break
78
- }
79
- }
80
-
81
-
82
- if (!hasErr) {
83
- this.root = Aontu(this.src, this.opts)
84
- hasErr = this.root.err && 0 < this.root.err.length
85
-
86
- if (hasErr) {
87
- this.err.push(...this.root.err)
88
- }
89
- }
90
-
91
-
92
- if (!hasErr) {
93
- let genctx = new Context({ root: this.root })
94
- this.model = this.root.gen(genctx)
95
-
96
- hasErr = genctx.err && 0 < genctx.err.length
97
- if (hasErr) {
98
- this.err.push(...genctx.err)
99
- }
100
- else {
101
- // TODO: only call if path value has changed
102
-
103
- this.ctx.step = 'post'
104
-
105
- for (let builder of this.res) {
106
- try {
107
- let br = await builder.build(this, this.ctx)
108
- br.step = this.ctx.step
109
- br.path = builder.path
110
- br.builder = builder.build.name
111
- brlog.push(br)
112
- }
113
- catch (e: any) {
114
- this.err.push(e)
115
- break
116
- }
117
- }
118
- }
119
- }
120
-
121
- const br = { ok: !hasErr, build: this, builders: brlog, err: this.err }
122
-
123
- return br
124
- }
125
- }
126
-
127
-
128
- function makeBuild(spec: Spec) {
129
- return new BuildImpl(spec)
130
- }
131
-
132
- export {
133
- makeBuild,
134
- Spec,
135
- Val
136
- }
137
-
138
-
@@ -1,130 +0,0 @@
1
-
2
- import Path from 'path'
3
-
4
- import type { Build, Builder, BuildContext } from '../types'
5
-
6
-
7
- // Runs any builders local to the repo.
8
- const local_builder: Builder = async (build: Build, ctx: BuildContext) => {
9
- ctx.state.local = (ctx.state.local || {})
10
- let actionDefs = ctx.state.local.actionDefs
11
-
12
- if (null == actionDefs) {
13
- try {
14
- actionDefs = ctx.state.local.actionDefs = []
15
-
16
- // TODO: need to provide project root via build
17
- let root = Path.resolve(build.path, '..', '..')
18
-
19
-
20
- // TODO: build should do this
21
- let configbuild = build.use.config
22
-
23
- let config = configbuild.watch.last.build.model
24
-
25
- let builders = config.sys.model.builders
26
-
27
- // TODO: order by comma sep string
28
- // Load builders
29
- for (let name in builders) {
30
- let builder = builders[name]
31
- let action_path = Path.join(root, builder.load)
32
-
33
-
34
- // clear(action_path)
35
-
36
-
37
- let action = require(action_path)
38
-
39
- if (action instanceof Promise) {
40
- action = await action
41
- }
42
-
43
- const step = action.step || 'post'
44
-
45
- actionDefs.push({ name, builder, action, step })
46
- }
47
- }
48
- catch (e: any) {
49
- throw e
50
- }
51
- }
52
-
53
-
54
- if ('pre' === ctx.step) {
55
- try {
56
- let ok = true
57
- let brlog = []
58
-
59
- for (let actionDef of actionDefs) {
60
- if ('pre' === actionDef.step || 'all' === actionDef.step) {
61
- let br = await actionDef.action(build.model, build)
62
- ok = ok && null != br && br.ok
63
- brlog.push(br)
64
- }
65
- }
66
-
67
- return { ok: true, step: ctx.step, active: true }
68
- }
69
- catch (e: any) {
70
- throw e
71
- }
72
- }
73
-
74
- else if ('post' === ctx.step) {
75
- try {
76
- let ok = true
77
- let brlog = []
78
-
79
- for (let actionDef of actionDefs) {
80
- if ('post' === actionDef.step || 'all' === actionDef.step) {
81
- let br = await actionDef.action(build.model, build)
82
- ok = ok && null != br && br.ok
83
- brlog.push(br)
84
- }
85
- }
86
-
87
- return { ok: true, step: ctx.step, active: true }
88
- }
89
- catch (e: any) {
90
- throw e
91
- }
92
- }
93
-
94
- return { ok: false, why: 'bad-step', step: ctx.step, active: false }
95
- }
96
-
97
- /*
98
- // Adapted from https://github.com/sindresorhus/import-fresh - Thanks!
99
- function clear(path: string) {
100
- let filePath = require.resolve(path)
101
-
102
- if (require.cache[filePath]) {
103
- const children = require.cache[filePath].children.map(child => child.id)
104
-
105
- // Delete module from cache
106
- delete require.cache[filePath]
107
-
108
- for (const id of children) {
109
- clear(id)
110
- }
111
- }
112
-
113
-
114
- if (require.cache[filePath] && require.cache[filePath].parent) {
115
- let i = require.cache[filePath].parent.children.length
116
-
117
- while (i--) {
118
- if (require.cache[filePath].parent.children[i].id === filePath) {
119
- require.cache[filePath].parent.children.splice(i, 1)
120
- }
121
- }
122
- }
123
-
124
- }
125
- */
126
-
127
-
128
- export {
129
- local_builder
130
- }
@@ -1,37 +0,0 @@
1
-
2
- import Path from 'path'
3
-
4
- import { writeFile } from 'fs/promises'
5
-
6
- import type { Build, Builder, BuildContext } from '../types'
7
-
8
-
9
- // Builds the main model file, after unification.
10
- const model_builder: Builder = async (build: Build, ctx: BuildContext) => {
11
- if ('post' !== ctx.step) {
12
- return { ok: true, step: ctx.step, active: false }
13
- }
14
-
15
- try {
16
- let json = JSON.stringify(build.root.gen(), null, 2)
17
-
18
- let filename = Path.basename(build.path)
19
- let filenameparts = filename.match(/^(.*)\.[^.]+$/)
20
- if (filenameparts) {
21
- filename = filenameparts[1]
22
- }
23
-
24
- let file = build.opts.base + '/' + filename + '.json'
25
-
26
- await writeFile(file, json)
27
-
28
- return { ok: true, step: ctx.step, active: true }
29
- }
30
- catch (e: any) {
31
- throw e
32
- }
33
- }
34
-
35
- export {
36
- model_builder
37
- }
package/lib/config.ts DELETED
@@ -1,50 +0,0 @@
1
- /* Copyright © 2021-2024 Voxgig Ltd, MIT License. */
2
-
3
-
4
- import type { BuildResult, Spec } from './types'
5
-
6
- import { Watch } from './watch'
7
-
8
- import { model_builder } from './builder/model'
9
-
10
-
11
-
12
-
13
-
14
-
15
- class Config {
16
- build: any
17
- watch: Watch
18
-
19
- constructor(spec: Spec) {
20
- this.build = {
21
- src: spec.src,
22
- path: spec.path,
23
- base: spec.base,
24
- res: [
25
- ...(spec.res || [])
26
- ],
27
- require: spec.require
28
- }
29
-
30
- this.watch = new Watch(this.build)
31
- }
32
-
33
- async run(): Promise<BuildResult> {
34
- return this.watch.run(true)
35
- }
36
-
37
- async start() {
38
- return this.watch.start()
39
- }
40
-
41
- async stop() {
42
- return this.watch.stop()
43
- }
44
- }
45
-
46
-
47
- export { Config, Spec }
48
-
49
-
50
-
package/lib/types.ts DELETED
@@ -1,67 +0,0 @@
1
-
2
-
3
-
4
- interface Build {
5
- id: string
6
- src: string
7
- base: string
8
- path: string
9
- root: any
10
- opts: { [key: string]: any }
11
- res: BuildAction[]
12
- spec: Spec
13
- model: any
14
- use: { [name: string]: any }
15
- err: any[]
16
- ctx: BuildContext
17
-
18
- run: () => Promise<BuildResult>
19
- }
20
-
21
-
22
- interface BuildResult {
23
- ok: boolean
24
- builder?: string
25
- path?: string
26
- build?: Build
27
- builders?: BuildResult[]
28
- step?: string
29
- err?: any[]
30
- }
31
-
32
- interface BuildAction {
33
- path: string
34
- build: Builder
35
- }
36
-
37
-
38
- interface BuildContext {
39
- step: 'pre' | 'post'
40
- state: Record<string, any>
41
- }
42
-
43
- type Builder = (
44
- build: Build,
45
- ctx: BuildContext,
46
- ) => Promise<BuildResult>
47
-
48
-
49
- interface Spec {
50
- src: string
51
- path?: string
52
- base?: string
53
- res?: BuildAction[]
54
- require?: any
55
- use?: { [name: string]: any }
56
- }
57
-
58
-
59
-
60
- export type {
61
- Build,
62
- BuildResult,
63
- BuildAction,
64
- Builder,
65
- BuildContext,
66
- Spec,
67
- }