@voxgig/model 11.1.1 → 12.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.
- package/bin/voxgig-model +7 -5
- package/dist/build.js +0 -7
- package/dist/build.js.map +1 -1
- package/dist/config.d.ts +14 -2
- package/dist/config.js +179 -3
- package/dist/config.js.map +1 -1
- package/dist/init.js +4 -4
- package/dist/init.js.map +1 -1
- package/dist/model.js +6 -50
- package/dist/model.js.map +1 -1
- package/dist/producer/local.js +0 -5
- package/dist/producer/local.js.map +1 -1
- package/dist/producer/model.js +0 -14
- package/dist/producer/model.js.map +1 -1
- package/dist/producer/msg.js +0 -63
- package/dist/producer/msg.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/watch.js +4 -6
- package/dist/watch.js.map +1 -1
- package/model/{sys.aon → sys.aontu} +3 -51
- package/package.json +8 -8
- package/src/build.ts +0 -7
- package/src/config.ts +220 -3
- package/src/init.ts +4 -4
- package/src/model.ts +7 -50
- package/src/producer/local.ts +0 -5
- package/src/producer/model.ts +0 -14
- package/src/producer/msg.ts +0 -63
- package/src/types.ts +0 -3
- package/src/watch.ts +4 -6
- /package/model/.model-config/{model-config.aon → model-config.aontu} +0 -0
|
@@ -8,8 +8,6 @@ sys: shape: type({})
|
|
|
8
8
|
# Service base has no defaults.
|
|
9
9
|
sys: shape: srv: base: {
|
|
10
10
|
in: {
|
|
11
|
-
# TODO: validate leaf?
|
|
12
|
-
# &&: => &:, &: &:, &: &: &:, etc
|
|
13
11
|
}
|
|
14
12
|
out: {}
|
|
15
13
|
deps: {
|
|
@@ -20,7 +18,7 @@ sys: shape: srv: base: {
|
|
|
20
18
|
path: {
|
|
21
19
|
prefix?: string
|
|
22
20
|
area?: string
|
|
23
|
-
suffix?: string
|
|
21
|
+
suffix?: string
|
|
24
22
|
}
|
|
25
23
|
method: string
|
|
26
24
|
cors: {
|
|
@@ -38,7 +36,6 @@ sys: shape: srv: base: {
|
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
|
|
41
|
-
# Shared service defaults
|
|
42
39
|
sys: shape: srv: std: $.sys.shape.srv.base & {
|
|
43
40
|
api: web: {
|
|
44
41
|
active: *true | boolean
|
|
@@ -91,36 +88,15 @@ sys: shape: ent: {
|
|
|
91
88
|
}
|
|
92
89
|
}
|
|
93
90
|
|
|
94
|
-
# sys: shape: ent: field: &: {
|
|
95
|
-
# active: *true | boolean
|
|
96
|
-
# kind: *'Text' | string
|
|
97
|
-
# title: string
|
|
98
|
-
|
|
99
|
-
# # Developer model (backend)
|
|
100
|
-
# dx: {}
|
|
101
91
|
|
|
102
|
-
# # User inerface model (frontend)
|
|
103
|
-
# ux: {
|
|
104
|
-
# desc: string
|
|
105
|
-
# }
|
|
106
|
-
# }
|
|
107
92
|
|
|
108
93
|
|
|
109
94
|
|
|
110
|
-
|
|
111
|
-
# --------------
|
|
95
|
+
|
|
112
96
|
|
|
113
97
|
sys: shape: app: {
|
|
114
98
|
name: string
|
|
115
99
|
layout: string
|
|
116
|
-
# TODO: test
|
|
117
|
-
# parts: {
|
|
118
|
-
# &: {
|
|
119
|
-
# part: string
|
|
120
|
-
# active: boolean
|
|
121
|
-
# # active: *true | boolean
|
|
122
|
-
# }
|
|
123
|
-
# }
|
|
124
100
|
}
|
|
125
101
|
|
|
126
102
|
sys: shape: part: img: {
|
|
@@ -128,29 +104,5 @@ sys: shape: part: img: {
|
|
|
128
104
|
svg: string
|
|
129
105
|
}
|
|
130
106
|
|
|
131
|
-
|
|
132
|
-
# app: web: basic: .sys.shape.app
|
|
133
|
-
|
|
134
|
-
# app: web: basic: {
|
|
135
|
-
# name: basic
|
|
136
|
-
# layout: BasicAdmin
|
|
137
|
-
# }
|
|
138
|
-
|
|
139
|
-
# app: web: basic: parts: {
|
|
140
|
-
# head: {
|
|
141
|
-
# part: BasicHead
|
|
142
|
-
# }
|
|
143
|
-
|
|
144
|
-
# side: {
|
|
145
|
-
# part: BasicSide
|
|
146
|
-
# }
|
|
147
|
-
|
|
148
|
-
# main: {
|
|
149
|
-
# part: BasicMain
|
|
150
|
-
# }
|
|
151
|
-
|
|
152
|
-
# foot: {
|
|
153
|
-
# part: BasicFoot
|
|
154
|
-
# }
|
|
155
|
-
# }
|
|
156
107
|
|
|
108
|
+
# app: web: basic: .sys.shape.app
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voxgig/model",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"main": "dist/model.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"types": "dist/model.d.ts",
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"url": "git://github.com/voxgig/model.git"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
-
"test": "node --test --experimental-test-coverage --test-coverage-include='dist/**' --test-coverage-lines=95 --test-coverage-functions=95 --test-coverage-branches=90 \"dist-test/**/*.test.js\"",
|
|
22
|
+
"test": "node ../tools/comment-gate.cjs && node --test --experimental-test-coverage --test-coverage-include='dist/**' --test-coverage-lines=95 --test-coverage-functions=95 --test-coverage-branches=90 \"dist-test/**/*.test.js\"",
|
|
23
23
|
"test-some": "node --enable-source-maps --test-name-pattern=\"$TEST_PATTERN\" --test dist-test/**/*.test.js",
|
|
24
24
|
"test-cov": "rm -rf ./coverage && mkdir -p ./coverage && node --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --enable-source-maps --test \"dist-test/*.test.js\"",
|
|
25
25
|
"watch": "tsc --build src test -w",
|
|
26
26
|
"build": "tsc --build src test",
|
|
27
|
-
"test-model": "voxgig-model test/sys01/model/model.
|
|
28
|
-
"model": "voxgig-model -w model/sys.
|
|
29
|
-
"model-build": "voxgig-model -g debug model/sys.
|
|
27
|
+
"test-model": "voxgig-model test/sys01/model/model.aontu",
|
|
28
|
+
"model": "voxgig-model -w model/sys.aontu",
|
|
29
|
+
"model-build": "voxgig-model -g debug model/sys.aontu",
|
|
30
30
|
"clean": "rm -rf node_modules dist dist-test yarn.lock package-lock.json",
|
|
31
31
|
"reset": "npm run clean && npm i && npm run build && npm test",
|
|
32
32
|
"repo-bump": "npm version patch --no-git-tag-version && node -e \"console.log('bumped to v' + require('./package.json').version + ' (package.json only - commit via repo-tag / repo-release)')\"",
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"LICENSE"
|
|
56
56
|
],
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@tabnas/jsonic": ">=0.
|
|
59
|
-
"@tabnas/parser": ">=0.
|
|
60
|
-
"aontu": ">=0.
|
|
58
|
+
"@tabnas/jsonic": ">=0.7.1",
|
|
59
|
+
"@tabnas/parser": ">=0.12.2",
|
|
60
|
+
"aontu": ">=0.75.0",
|
|
61
61
|
"chokidar": "5.0.0",
|
|
62
62
|
"memfs": "4.64.0",
|
|
63
63
|
"shape": ">=10"
|
package/src/build.ts
CHANGED
|
@@ -81,10 +81,6 @@ class BuildImpl implements Build {
|
|
|
81
81
|
let hasErr = false
|
|
82
82
|
let runlog = []
|
|
83
83
|
|
|
84
|
-
// Reset per-run error state. The BuildImpl is reused across watch
|
|
85
|
-
// rebuilds, so without this a single failure would stick to every
|
|
86
|
-
// later build. Reassign (don't clear in place) so a previously
|
|
87
|
-
// returned BuildResult keeps its own errors.
|
|
88
84
|
this.errs = []
|
|
89
85
|
|
|
90
86
|
this.ctx = { step: 'pre', state: {}, watch: rspec.watch }
|
|
@@ -117,8 +113,6 @@ class BuildImpl implements Build {
|
|
|
117
113
|
}
|
|
118
114
|
}
|
|
119
115
|
|
|
120
|
-
// Only reload when a pre-producer actually modified model sources
|
|
121
|
-
// (signalled via pr.reload). Previously this always ran on success.
|
|
122
116
|
const reload = forceReload && !hasErr
|
|
123
117
|
|
|
124
118
|
if (reload) {
|
|
@@ -150,7 +144,6 @@ class BuildImpl implements Build {
|
|
|
150
144
|
|
|
151
145
|
const br: BuildResult =
|
|
152
146
|
{
|
|
153
|
-
// TODO: remove need for this
|
|
154
147
|
build: () => this,
|
|
155
148
|
|
|
156
149
|
ok: !hasErr,
|
package/src/config.ts
CHANGED
|
@@ -1,19 +1,45 @@
|
|
|
1
1
|
/* Copyright © 2021-2025 Voxgig Ltd, MIT License. */
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
import Path from 'node:path'
|
|
5
|
+
|
|
4
6
|
import type { BuildResult, BuildSpec, Log } from './types'
|
|
5
7
|
|
|
6
8
|
import { Watch } from './watch'
|
|
7
9
|
|
|
8
10
|
|
|
11
|
+
const CONFIG_FILE = 'model-config.aontu'
|
|
12
|
+
const LEGACY_CONFIG_FILE = 'model-config.aon'
|
|
13
|
+
|
|
14
|
+
const DEFAULT_CONFIG = `
|
|
15
|
+
@"@voxgig/model/model/.model-config/model-config.aontu"
|
|
16
|
+
|
|
17
|
+
sys: model: action: {}
|
|
18
|
+
`
|
|
19
|
+
|
|
20
|
+
const QUOTES = '"\'`'
|
|
21
|
+
const SPACE = ' \t\r\n'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// What the Model prepared before the config build: a failure to report, or,
|
|
26
|
+
// for a dry run, the config text to serve and the legacy file it comes from.
|
|
27
|
+
type ConfigPrep = {
|
|
28
|
+
err?: Error
|
|
29
|
+
text?: () => string
|
|
30
|
+
from?: string
|
|
31
|
+
}
|
|
32
|
+
|
|
9
33
|
|
|
10
34
|
class Config {
|
|
11
35
|
build: BuildSpec
|
|
12
36
|
watch: Watch
|
|
13
37
|
log: Log
|
|
38
|
+
prep: ConfigPrep
|
|
14
39
|
|
|
15
|
-
constructor(spec: BuildSpec, log: Log) {
|
|
40
|
+
constructor(spec: BuildSpec, log: Log, prep: ConfigPrep = {}) {
|
|
16
41
|
this.log = log
|
|
42
|
+
this.prep = prep
|
|
17
43
|
|
|
18
44
|
this.build = {
|
|
19
45
|
path: spec.path,
|
|
@@ -30,7 +56,14 @@ class Config {
|
|
|
30
56
|
}
|
|
31
57
|
|
|
32
58
|
async run(watch: boolean): Promise<BuildResult> {
|
|
33
|
-
|
|
59
|
+
if (this.prep.err) {
|
|
60
|
+
return { ok: false, errs: [this.prep.err], runlog: [] }
|
|
61
|
+
}
|
|
62
|
+
const br = await this.watch.run('config', watch, '<config>')
|
|
63
|
+
if (watch && this.prep.from) {
|
|
64
|
+
await this.watch.add(this.prep.from)
|
|
65
|
+
}
|
|
66
|
+
return br
|
|
34
67
|
}
|
|
35
68
|
|
|
36
69
|
async start(initial: boolean = true) {
|
|
@@ -43,7 +76,191 @@ class Config {
|
|
|
43
76
|
}
|
|
44
77
|
|
|
45
78
|
|
|
46
|
-
|
|
79
|
+
// Creates the config when there is none, migrating a legacy
|
|
80
|
+
// model-config.aon forward if one is present. A dry run writes nothing: the
|
|
81
|
+
// config text is derived afresh from its source on every read instead.
|
|
82
|
+
function prepareConfig(
|
|
83
|
+
fs: any, cbase: string, log: Log, dryrun?: boolean
|
|
84
|
+
): ConfigPrep {
|
|
85
|
+
const cpath = cbase + '/' + CONFIG_FILE
|
|
86
|
+
const legacy = cbase + '/' + LEGACY_CONFIG_FILE
|
|
87
|
+
|
|
88
|
+
if (fs.existsSync(cpath)) {
|
|
89
|
+
if (fs.existsSync(legacy)) {
|
|
90
|
+
log.warn({
|
|
91
|
+
point: 'config-legacy-ignored', legacy,
|
|
92
|
+
note: 'ignoring ' + legacy + ': ' + cpath + ' takes precedence'
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
return {}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let old: string | undefined
|
|
99
|
+
try {
|
|
100
|
+
old = fs.readFileSync(legacy, 'utf8')
|
|
101
|
+
}
|
|
102
|
+
catch (err: any) {
|
|
103
|
+
if ('ENOENT' !== err?.code) {
|
|
104
|
+
return { err: configError('cannot read ' + legacy, err) }
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (null != old) {
|
|
109
|
+
log.info({
|
|
110
|
+
point: 'config-migrate', legacy, path: cpath,
|
|
111
|
+
note: 'migrated ' + legacy + ' to ' + cpath +
|
|
112
|
+
(dryrun ? ' (dry run: in memory only)' : '')
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (dryrun) {
|
|
117
|
+
return null == old ? { text: () => DEFAULT_CONFIG } : {
|
|
118
|
+
text: () => rewriteAonIncludes(fs.readFileSync(legacy, 'utf8')),
|
|
119
|
+
from: legacy,
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
fs.mkdirSync(cbase, { recursive: true })
|
|
125
|
+
writeAtomic(fs, cpath, null == old ? DEFAULT_CONFIG : rewriteAonIncludes(old))
|
|
126
|
+
}
|
|
127
|
+
catch (err: any) {
|
|
128
|
+
return { err: configError('cannot write ' + cpath, err) }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (null != old) {
|
|
132
|
+
try { fs.unlinkSync(legacy) } catch (_err: any) { }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return {}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
function configError(what: string, cause: any): Error {
|
|
140
|
+
return Object.assign(
|
|
141
|
+
new Error('model config: ' + what + ': ' + (cause?.message || cause)),
|
|
142
|
+
{ code: cause?.code, cause })
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
// A reader never sees a partial file: the text lands beside the target and
|
|
147
|
+
// is renamed over it.
|
|
148
|
+
function writeAtomic(fs: any, path: string, src: string) {
|
|
149
|
+
const tmp = path + '.' + process.pid + '.' +
|
|
150
|
+
Math.random().toString(36).slice(2) + '.tmp'
|
|
151
|
+
try {
|
|
152
|
+
fs.writeFileSync(tmp, src)
|
|
153
|
+
fs.renameSync(tmp, path)
|
|
154
|
+
}
|
|
155
|
+
catch (err: any) {
|
|
156
|
+
try { fs.unlinkSync(tmp) } catch (_err: any) { }
|
|
157
|
+
throw err
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
// A dry run writes nothing, so its config is served from memory, derived on
|
|
163
|
+
// each read; its mtime is that of the legacy source, so an edit there
|
|
164
|
+
// invalidates the build cache. Matched by resolved path: callers join with
|
|
165
|
+
// '/', which a Windows path does not spell the same way.
|
|
166
|
+
function readBack(fs: any, path: string, text: () => string, from?: string) {
|
|
167
|
+
const at = Path.resolve(path)
|
|
168
|
+
const mtimeMs = Date.now()
|
|
169
|
+
const mine = (p: any) => Path.resolve(String(p)) === at
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
...fs,
|
|
173
|
+
readFileSync: (p: any, opts?: any) => {
|
|
174
|
+
if (!mine(p)) {
|
|
175
|
+
return fs.readFileSync(p, opts)
|
|
176
|
+
}
|
|
177
|
+
const enc = 'string' === typeof opts ? opts : opts?.encoding
|
|
178
|
+
const src = text()
|
|
179
|
+
return null == enc ? Buffer.from(src) : src
|
|
180
|
+
},
|
|
181
|
+
statSync: (p: any, ...rest: any[]) => !mine(p) ? fs.statSync(p, ...rest) :
|
|
182
|
+
from ? fs.statSync(from, ...rest) :
|
|
183
|
+
{ mtimeMs, isFile: () => true, isDirectory: () => false },
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
// Points each include of a .aon file at its .aontu successor. Strings and
|
|
189
|
+
// comments are skipped, so a path held as data or commented out is kept.
|
|
190
|
+
function rewriteAonIncludes(src: string): string {
|
|
191
|
+
let out = ''
|
|
192
|
+
let i = 0
|
|
193
|
+
|
|
194
|
+
while (i < src.length) {
|
|
195
|
+
const c = src[i]
|
|
196
|
+
let end = i + 1
|
|
197
|
+
let retarget = false
|
|
198
|
+
|
|
199
|
+
if ('#' === c) {
|
|
200
|
+
end = src.indexOf('\n', i)
|
|
201
|
+
end = -1 === end ? src.length : end
|
|
202
|
+
}
|
|
203
|
+
else if (QUOTES.includes(c)) {
|
|
204
|
+
end = stringEnd(src, i).end
|
|
205
|
+
}
|
|
206
|
+
else if ('@' === c) {
|
|
207
|
+
let q = end
|
|
208
|
+
while (q < src.length && SPACE.includes(src[q])) {
|
|
209
|
+
q++
|
|
210
|
+
}
|
|
211
|
+
if (q < src.length && QUOTES.includes(src[q])) {
|
|
212
|
+
const str = stringEnd(src, q)
|
|
213
|
+
end = str.end
|
|
214
|
+
retarget = str.closed && src.slice(q + 1, end - 1).endsWith('.aon')
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
out += retarget ?
|
|
219
|
+
src.slice(i, end - 1) + 'tu' + src[end - 1] : src.slice(i, end)
|
|
220
|
+
i = end
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return out
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
// A string ends at its unescaped closing quote, or, unterminated, at its
|
|
228
|
+
// line; a backtick string may span lines.
|
|
229
|
+
function stringEnd(src: string, start: number): { end: number, closed: boolean } {
|
|
230
|
+
const quote = src[start]
|
|
231
|
+
let i = start + 1
|
|
232
|
+
while (i < src.length) {
|
|
233
|
+
const c = src[i]
|
|
234
|
+
if ('\\' === c) {
|
|
235
|
+
i += 2
|
|
236
|
+
}
|
|
237
|
+
else if (quote === c) {
|
|
238
|
+
return { end: i + 1, closed: true }
|
|
239
|
+
}
|
|
240
|
+
else if ('\n' === c && '`' !== quote) {
|
|
241
|
+
return { end: i, closed: false }
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
i++
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return { end: src.length, closed: false }
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
export {
|
|
252
|
+
Config,
|
|
253
|
+
BuildSpec,
|
|
254
|
+
CONFIG_FILE,
|
|
255
|
+
LEGACY_CONFIG_FILE,
|
|
256
|
+
prepareConfig,
|
|
257
|
+
readBack,
|
|
258
|
+
rewriteAonIncludes,
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export type {
|
|
262
|
+
ConfigPrep,
|
|
263
|
+
}
|
|
47
264
|
|
|
48
265
|
|
|
49
266
|
|
package/src/init.ts
CHANGED
|
@@ -4,9 +4,9 @@ import Path from 'node:path'
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
const STARTER_MODEL = `# Voxgig model. Edit this file, then build it:
|
|
7
|
-
# voxgig-model model/model.
|
|
7
|
+
# voxgig-model model/model.aontu
|
|
8
8
|
#
|
|
9
|
-
# Models are unified .
|
|
9
|
+
# Models are unified .aontu - add types, defaults, references, imports.
|
|
10
10
|
# Tutorial: https://github.com/voxgig/model/blob/main/docs/tutorial.md
|
|
11
11
|
|
|
12
12
|
name: 'my-model'
|
|
@@ -35,8 +35,8 @@ type InitResult = {
|
|
|
35
35
|
function initModel(dir: string, fs: any): InitResult {
|
|
36
36
|
const d = dir || '.'
|
|
37
37
|
const files: [string, string][] = [
|
|
38
|
-
[Path.join(d, 'model', 'model.
|
|
39
|
-
[Path.join(d, 'model', '.model-config', 'model-config.
|
|
38
|
+
[Path.join(d, 'model', 'model.aontu'), STARTER_MODEL],
|
|
39
|
+
[Path.join(d, 'model', '.model-config', 'model-config.aontu'), STARTER_CONFIG],
|
|
40
40
|
]
|
|
41
41
|
|
|
42
42
|
const created: string[] = []
|
package/src/model.ts
CHANGED
|
@@ -20,7 +20,7 @@ import type {
|
|
|
20
20
|
} from './types'
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
import { Config } from './config'
|
|
23
|
+
import { Config, CONFIG_FILE, prepareConfig, readBack } from './config'
|
|
24
24
|
import { Watch } from './watch'
|
|
25
25
|
|
|
26
26
|
import { model_producer } from './producer/model'
|
|
@@ -83,10 +83,6 @@ class Model {
|
|
|
83
83
|
|
|
84
84
|
if (self.trigger_model) {
|
|
85
85
|
|
|
86
|
-
// TODO: better design
|
|
87
|
-
// Point the config's last result at the current build so the model
|
|
88
|
-
// producer reads fresh config state. It must be a thunk to satisfy
|
|
89
|
-
// BuildResult.build's `() => Build` contract (consumers call it).
|
|
90
86
|
const lastConfig = self.build.use?.config?.watch?.last
|
|
91
87
|
if (lastConfig) {
|
|
92
88
|
lastConfig.build = () => build
|
|
@@ -191,50 +187,11 @@ class Model {
|
|
|
191
187
|
|
|
192
188
|
|
|
193
189
|
function makeConfig(mspec: ModelSpec, log: Log, fs: any, trigger_model_build: ProducerDef) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
// MIGRATE A LEGACY .aontu CONFIG RATHER THAN WRITING OVER IT. This block
|
|
198
|
-
// CREATES the config when it finds none, so looking only for `.aon` in a
|
|
199
|
-
// project that has a `model-config.aontu` would not read the old file — it
|
|
200
|
-
// would decide there is no config and write a fresh default beside it,
|
|
201
|
-
// silently discarding whatever the project had declared there.
|
|
202
|
-
const legacycpath = cbase + '/model-config.aontu'
|
|
203
|
-
if (!fs.existsSync(cpath) && fs.existsSync(legacycpath)) {
|
|
204
|
-
// NOT A VERBATIM COPY. This package's OWN config moved to .aon in v10, so
|
|
205
|
-
// a legacy config's import of it names a file that no longer ships and the
|
|
206
|
-
// migrated config fails to resolve - `aontu/multisource_not_found:
|
|
207
|
-
// @voxgig/model/model/.model-config/model-config.aontu` - on the first
|
|
208
|
-
// build after upgrading. Renaming the file without retargeting that import
|
|
209
|
-
// just moves the breakage.
|
|
210
|
-
//
|
|
211
|
-
// Only THIS package's import is retargeted, and only where it is an
|
|
212
|
-
// IMPORT. Two things are deliberately left alone:
|
|
213
|
-
//
|
|
214
|
-
// - a project's own `.aontu` imports, which still name real files on
|
|
215
|
-
// its disk that nothing here renamed;
|
|
216
|
-
// - this same pathname held as ordinary string DATA (a note, a
|
|
217
|
-
// compatibility path in action metadata).
|
|
218
|
-
//
|
|
219
|
-
// Hence the match is anchored to aontu's `@"..."` import syntax, closing
|
|
220
|
-
// quote included, rather than to the bare pathname. Both are declarations
|
|
221
|
-
// the migration exists to preserve, and silently editing one during a
|
|
222
|
-
// one-time migration is precisely the failure this whole block guards
|
|
223
|
-
// against.
|
|
224
|
-
const legacy = fs.readFileSync(legacycpath, 'utf8')
|
|
225
|
-
fs.writeFileSync(cpath, legacy.replace(
|
|
226
|
-
/@(\s*)"(@voxgig\/model\/[^"]*model-config)\.aontu"/g, '@$1"$2.aon"'))
|
|
227
|
-
try { fs.unlinkSync(legacycpath) } catch (_err: any) { }
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (!fs.existsSync(cpath)) {
|
|
231
|
-
fs.mkdirSync(cbase, { recursive: true })
|
|
232
|
-
fs.writeFileSync(cpath, `
|
|
233
|
-
@"@voxgig/model/model/.model-config/model-config.aon"
|
|
190
|
+
const cbase = mspec.base + '/.model-config'
|
|
191
|
+
const cpath = cbase + '/' + CONFIG_FILE
|
|
234
192
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
193
|
+
const prep = prepareConfig(fs, cbase, log, mspec.dryrun)
|
|
194
|
+
const cfs = null == prep.text ? fs : readBack(fs, cpath, prep.text, prep.from)
|
|
238
195
|
|
|
239
196
|
let cspec: BuildSpec = {
|
|
240
197
|
name: 'config',
|
|
@@ -254,10 +211,10 @@ sys: model: action: {}
|
|
|
254
211
|
],
|
|
255
212
|
require: mspec.require,
|
|
256
213
|
log,
|
|
257
|
-
fs,
|
|
214
|
+
fs: cfs,
|
|
258
215
|
}
|
|
259
216
|
|
|
260
|
-
return new Config(cspec, log)
|
|
217
|
+
return new Config(cspec, log, prep)
|
|
261
218
|
}
|
|
262
219
|
|
|
263
220
|
|
package/src/producer/local.ts
CHANGED
|
@@ -14,12 +14,8 @@ const local_producer: Producer = async (build: Build, ctx: BuildContext) => {
|
|
|
14
14
|
if (null == actionDefs) {
|
|
15
15
|
actionDefs = ctx.state.local.actionDefs = []
|
|
16
16
|
|
|
17
|
-
// TODO: need to provide project root via build
|
|
18
17
|
let root = Path.resolve(build.path, '..', '..')
|
|
19
18
|
|
|
20
|
-
// TODO: build should do this
|
|
21
|
-
// Config is optional: with no .model-config build linked in, there are no
|
|
22
|
-
// declared actions and the model runs on its own.
|
|
23
19
|
let configBuildResult = build.use.config?.watch?.last
|
|
24
20
|
let configBuild = configBuildResult?.build()
|
|
25
21
|
let config = configBuild?.model || {}
|
|
@@ -75,7 +71,6 @@ const local_producer: Producer = async (build: Build, ctx: BuildContext) => {
|
|
|
75
71
|
|
|
76
72
|
for (let actionDef of runActionDefs) {
|
|
77
73
|
try {
|
|
78
|
-
// TODO: this call signature needs to be well-defined as it is an external interface
|
|
79
74
|
let ares = await actionDef.action(build.model, build, ctx)
|
|
80
75
|
ok = ok && (null == ares || !!ares.ok)
|
|
81
76
|
reload = reload || ares?.reload
|
package/src/producer/model.ts
CHANGED
|
@@ -4,17 +4,6 @@ import Path from 'path'
|
|
|
4
4
|
import type { Build, Producer, BuildContext, ProducerResult } from '../types'
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
// Serialize the model to two-space-indented JSON with object keys in strictly
|
|
8
|
-
// lexical (UTF-8 byte) order, byte-for-byte identical to the Go
|
|
9
|
-
// implementation's encoding/json. JSON.stringify cannot express this: JS
|
|
10
|
-
// objects iterate integer-like keys ("9", "10") in numeric order ahead of the
|
|
11
|
-
// other keys regardless of insertion order, so the order must be imposed
|
|
12
|
-
// during serialization, and the default JS string sort compares UTF-16 code
|
|
13
|
-
// units, which disagrees with Go's byte order for astral-plane keys. Arrays
|
|
14
|
-
// keep their order. Values only producer mutation can introduce mirror
|
|
15
|
-
// JSON.stringify: undefined, functions, and symbols are dropped from objects
|
|
16
|
-
// and become null in arrays (sparse holes too), and toJSON results are fed
|
|
17
|
-
// back through the canonical serializer.
|
|
18
7
|
function jsonify(value: any, indent: string): string {
|
|
19
8
|
if (Array.isArray(value)) {
|
|
20
9
|
if (0 === value.length) {
|
|
@@ -54,9 +43,6 @@ function jsonify(value: any, indent: string): string {
|
|
|
54
43
|
}
|
|
55
44
|
|
|
56
45
|
|
|
57
|
-
// JSON.stringify, plus the U+2028/U+2029 escapes Go's encoding/json always
|
|
58
|
-
// applies even with HTML escaping off. JSON.stringify emits the separators
|
|
59
|
-
// literally (both forms are valid JSON), so escape them here for byte parity.
|
|
60
46
|
function jstr(value: any): string | undefined {
|
|
61
47
|
const out = JSON.stringify(value)
|
|
62
48
|
return undefined === out ? undefined :
|
package/src/producer/msg.ts
CHANGED
|
@@ -3,39 +3,6 @@
|
|
|
3
3
|
import type { Build, Producer, BuildContext, ProducerResult } from '../types'
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
// Message declarations live in `main.msg` and come in two shapes.
|
|
7
|
-
//
|
|
8
|
-
// The legacy shape nests the pattern pairs, so the pattern is the path down
|
|
9
|
-
// to the definition, and the definition sits at whatever depth that reaches:
|
|
10
|
-
//
|
|
11
|
-
// aim: web: { on: todo: { save: item: { '$': { file: './web_save_item' } } } }
|
|
12
|
-
//
|
|
13
|
-
// The declared shape is a LIST of definitions, each carrying its pattern as
|
|
14
|
-
// data - an ordered list of single-pair maps:
|
|
15
|
-
//
|
|
16
|
-
// main: msg: [
|
|
17
|
-
// { pat: [ {aim: todo}, {save: item} ] }
|
|
18
|
-
// { pat: [ {aim: web}, {on: todo}, {save: item} ], file: "./web_save_item" }
|
|
19
|
-
// ]
|
|
20
|
-
//
|
|
21
|
-
// A LIST, NOT A MAP KEYED BY MESSAGE NAME. The obvious flat shape - one entry
|
|
22
|
-
// per message, keyed by name - cannot express a gateway proxy. A proxy and the
|
|
23
|
-
// message it forwards to necessarily share their last pattern pair
|
|
24
|
-
// (aim:web,on:todo,save:item proxies aim:todo,save:item), and a key derived
|
|
25
|
-
// from that pair therefore collides. Keyed by name, the two above would both
|
|
26
|
-
// demand `save_item`, and aontu would merge them and fail trying to unify
|
|
27
|
-
// `todo` with `web`. A list has no key, so the question never arises.
|
|
28
|
-
//
|
|
29
|
-
// The action file still comes from the LAST pattern pair (save:item ->
|
|
30
|
-
// save_item), with `file` overriding it for a custom name - unchanged, and
|
|
31
|
-
// exactly what a proxy uses. That convention lives in the consumers
|
|
32
|
-
// (@voxgig/system's actpath, @voxgig/build's actfile), not here.
|
|
33
|
-
//
|
|
34
|
-
// The two shapes are told apart by main.msg being an array. Both may appear
|
|
35
|
-
// in one model only in the sense that a model picks one; a chain model that
|
|
36
|
-
// happens to contain a definition is a mistake this reports, because the
|
|
37
|
-
// nested walk would read the definition's metadata as pattern pairs and
|
|
38
|
-
// silently produce garbage patterns.
|
|
39
6
|
|
|
40
7
|
|
|
41
8
|
// Report a problem against the definition it belongs to.
|
|
@@ -55,10 +22,6 @@ function isMsgDef(val: any): boolean {
|
|
|
55
22
|
}
|
|
56
23
|
|
|
57
24
|
|
|
58
|
-
// Sort in UTF-8 byte order, matching Go's sort.Strings, so both
|
|
59
|
-
// implementations report the same problems in the same order. The default JS
|
|
60
|
-
// string sort compares UTF-16 code units, which disagrees for astral-plane
|
|
61
|
-
// names (see the model producer's jsonify, which sorts keys the same way).
|
|
62
25
|
function sortNames(names: string[]): string[] {
|
|
63
26
|
return names.sort((a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b)))
|
|
64
27
|
}
|
|
@@ -109,17 +72,6 @@ function checkMsgList(msg: any[]): string[] {
|
|
|
109
72
|
continue
|
|
110
73
|
}
|
|
111
74
|
|
|
112
|
-
// Reduce the pattern to its pairs, stopping at the first malformed one -
|
|
113
|
-
// the rest of the checks read the pairs, so there is nothing further to
|
|
114
|
-
// say about this message until its pattern is well-formed.
|
|
115
|
-
//
|
|
116
|
-
// Two renderings: `pairs` reads well in a message, and `canon` identifies
|
|
117
|
-
// the pattern. They cannot be the same string, because `key:value` joined
|
|
118
|
-
// by commas is ambiguous once a key or value contains a delimiter -
|
|
119
|
-
// [{a: "b,c:d"}] and [{a: b}, {c: d}] would both render `a:b,c:d` and the
|
|
120
|
-
// second would be rejected as a duplicate of the first. Quoting each part
|
|
121
|
-
// removes the ambiguity: a delimiter inside a part is escaped, so only
|
|
122
|
-
// genuinely equal patterns produce equal keys.
|
|
123
75
|
const pairs: string[] = []
|
|
124
76
|
const canon: string[] = []
|
|
125
77
|
let wellFormed = true
|
|
@@ -173,11 +125,6 @@ function checkMsgList(msg: any[]): string[] {
|
|
|
173
125
|
}
|
|
174
126
|
|
|
175
127
|
|
|
176
|
-
// The legacy chain. Nothing to validate in the chain itself - it has been
|
|
177
|
-
// valid by construction since before this producer existed - but a definition
|
|
178
|
-
// found among its nodes is reported rather than walked: the nested walk reads
|
|
179
|
-
// two levels at a time, so it would take the definition's metadata keys for
|
|
180
|
-
// pattern pairs and emit patterns nobody declared.
|
|
181
128
|
function checkMsgChain(msg: any): string[] {
|
|
182
129
|
const problems: string[] = []
|
|
183
130
|
|
|
@@ -193,16 +140,6 @@ function checkMsgChain(msg: any): string[] {
|
|
|
193
140
|
}
|
|
194
141
|
|
|
195
142
|
|
|
196
|
-
// Checks the message declarations before anything is written.
|
|
197
|
-
//
|
|
198
|
-
// This runs in BOTH phases, and must: a `pre` action can rewrite model source
|
|
199
|
-
// and request a reload, and the build re-resolves the model AFTER the pre
|
|
200
|
-
// phase has finished (see BuildImpl.run). A pre-only check would then have
|
|
201
|
-
// validated a model that no longer exists, and the model producer would write
|
|
202
|
-
// the regenerated one unchecked. Checking again in post closes that window -
|
|
203
|
-
// this producer is first in the pipeline, so it still runs ahead of the model
|
|
204
|
-
// producer, and a build whose model went bad during a reload fails with
|
|
205
|
-
// nothing written.
|
|
206
143
|
const msg_producer: Producer = async (build: Build, ctx: BuildContext) => {
|
|
207
144
|
const pr: ProducerResult = {
|
|
208
145
|
ok: true,
|
package/src/types.ts
CHANGED
|
@@ -131,9 +131,6 @@ interface ModelSpec {
|
|
|
131
131
|
dryrun?: boolean
|
|
132
132
|
buildargs?: any
|
|
133
133
|
fs?: any
|
|
134
|
-
// Resolve a .model-config/model-config.aon (auto-created when missing)
|
|
135
|
-
// that declares the build actions and their order. Defaults to true; set
|
|
136
|
-
// false to skip the config entirely and run the model on its own.
|
|
137
134
|
config?: boolean
|
|
138
135
|
watch?: {
|
|
139
136
|
mod?: boolean // file modification
|