@voxgig/model 10.0.1 → 10.1.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 +4 -4
- package/dist/model.js +29 -1
- package/dist/model.js.map +1 -1
- package/dist/producer/msg.d.ts +4 -0
- package/dist/producer/msg.js +170 -0
- package/dist/producer/msg.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -4
- package/src/build.ts +254 -0
- package/src/config.ts +49 -0
- package/src/init.ts +65 -0
- package/src/model.ts +330 -0
- package/src/producer/local.ts +116 -0
- package/src/producer/model.ts +122 -0
- package/src/producer/msg.ts +207 -0
- package/src/tsconfig.json +19 -0
- package/src/types.ts +162 -0
- package/src/watch.ts +335 -0
package/bin/voxgig-model
CHANGED
|
@@ -167,7 +167,7 @@ function doInit(dir) {
|
|
|
167
167
|
const res = initModel(dir, Fs)
|
|
168
168
|
res.created.forEach(p => KONSOLE.log('created: ' + p))
|
|
169
169
|
res.skipped.forEach(p => KONSOLE.log('exists: ' + p))
|
|
170
|
-
KONSOLE.log('Next: voxgig-model ' + Path.join(dir, 'model', 'model.
|
|
170
|
+
KONSOLE.log('Next: voxgig-model ' + Path.join(dir, 'model', 'model.aon'))
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
|
|
@@ -267,11 +267,11 @@ Examples:
|
|
|
267
267
|
|
|
268
268
|
# Scaffold a new model in ./model, then build it
|
|
269
269
|
> voxgig-model init
|
|
270
|
-
> voxgig-model model/model.
|
|
270
|
+
> voxgig-model model/model.aon
|
|
271
271
|
|
|
272
272
|
# Basic usage
|
|
273
|
-
> voxgig-model model/model.
|
|
274
|
-
# Builds a model defined in the file model/model.
|
|
273
|
+
> voxgig-model model/model.aon
|
|
274
|
+
# Builds a model defined in the file model/model.aon
|
|
275
275
|
|
|
276
276
|
See also: https://voxgig.com/model
|
|
277
277
|
`
|
package/dist/model.js
CHANGED
|
@@ -42,6 +42,7 @@ const config_1 = require("./config");
|
|
|
42
42
|
const watch_1 = require("./watch");
|
|
43
43
|
const model_1 = require("./producer/model");
|
|
44
44
|
const local_1 = require("./producer/local");
|
|
45
|
+
const msg_1 = require("./producer/msg");
|
|
45
46
|
const init_1 = require("./init");
|
|
46
47
|
Object.defineProperty(exports, "initModel", { enumerable: true, get: function () { return init_1.initModel; } });
|
|
47
48
|
class Model {
|
|
@@ -114,6 +115,12 @@ class Model {
|
|
|
114
115
|
buildargs: mspec.buildargs,
|
|
115
116
|
use: self.config ? { config: self.config } : {},
|
|
116
117
|
res: [
|
|
118
|
+
// Validates message declarations (pre phase), so an inconsistent
|
|
119
|
+
// main.msg fails the build before any output is written.
|
|
120
|
+
{
|
|
121
|
+
path: '/',
|
|
122
|
+
build: msg_1.msg_producer
|
|
123
|
+
},
|
|
117
124
|
{
|
|
118
125
|
path: '/',
|
|
119
126
|
build: model_1.model_producer
|
|
@@ -176,7 +183,28 @@ function makeConfig(mspec, log, fs, trigger_model_build) {
|
|
|
176
183
|
// silently discarding whatever the project had declared there.
|
|
177
184
|
const legacycpath = cbase + '/model-config.aontu';
|
|
178
185
|
if (!fs.existsSync(cpath) && fs.existsSync(legacycpath)) {
|
|
179
|
-
|
|
186
|
+
// NOT A VERBATIM COPY. This package's OWN config moved to .aon in v10, so
|
|
187
|
+
// a legacy config's import of it names a file that no longer ships and the
|
|
188
|
+
// migrated config fails to resolve - `aontu/multisource_not_found:
|
|
189
|
+
// @voxgig/model/model/.model-config/model-config.aontu` - on the first
|
|
190
|
+
// build after upgrading. Renaming the file without retargeting that import
|
|
191
|
+
// just moves the breakage.
|
|
192
|
+
//
|
|
193
|
+
// Only THIS package's import is retargeted, and only where it is an
|
|
194
|
+
// IMPORT. Two things are deliberately left alone:
|
|
195
|
+
//
|
|
196
|
+
// - a project's own `.aontu` imports, which still name real files on
|
|
197
|
+
// its disk that nothing here renamed;
|
|
198
|
+
// - this same pathname held as ordinary string DATA (a note, a
|
|
199
|
+
// compatibility path in action metadata).
|
|
200
|
+
//
|
|
201
|
+
// Hence the match is anchored to aontu's `@"..."` import syntax, closing
|
|
202
|
+
// quote included, rather than to the bare pathname. Both are declarations
|
|
203
|
+
// the migration exists to preserve, and silently editing one during a
|
|
204
|
+
// one-time migration is precisely the failure this whole block guards
|
|
205
|
+
// against.
|
|
206
|
+
const legacy = fs.readFileSync(legacycpath, 'utf8');
|
|
207
|
+
fs.writeFileSync(cpath, legacy.replace(/@(\s*)"(@voxgig\/model\/[^"]*model-config)\.aontu"/g, '@$1"$2.aon"'));
|
|
180
208
|
try {
|
|
181
209
|
fs.unlinkSync(legacycpath);
|
|
182
210
|
}
|
package/dist/model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGpD,MAAY,MAAM,oCAAe;AAEjC,iCAAsC;AAEtC,uCAAyC;AAezC,qCAAiC;AACjC,mCAA+B;AAE/B,4CAAiD;AACjD,4CAAiD;
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGpD,MAAY,MAAM,oCAAe;AAEjC,iCAAsC;AAEtC,uCAAyC;AAezC,qCAAiC;AACjC,mCAA+B;AAE/B,4CAAiD;AACjD,4CAAiD;AACjD,wCAA6C;AAE7C,iCAAkC;0FAAzB,gBAAS;AAGlB,MAAM,KAAK;IAUT,YAAY,KAAgB;QAL5B,kBAAa,GAAG,KAAK,CAAA;QAMnB,MAAM,IAAI,GAAG,IAAI,CAAA;QAEjB,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,IAAI,MAAM,CAAC,EAAE,CAAA;QAErC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YACjB,YA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ChD,CAAC;QACH,CAAC;QACD,CAAC;QAAC,GAAW,CAAC,QAAQ,GAAG,QAAQ,CAAA;IACnC,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright © 2026 Voxgig Ltd, MIT License. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.msg_producer = void 0;
|
|
5
|
+
exports.checkMsg = checkMsg;
|
|
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 flat - one entry per message, keyed by the message
|
|
14
|
+
// name, with the pattern as data and the definition at a known depth:
|
|
15
|
+
//
|
|
16
|
+
// save_item: { pat: [ {aim: web}, {save: item} ], doc: "Save a todo item" }
|
|
17
|
+
//
|
|
18
|
+
// The two are told apart by `pat`: a definition is a map holding a `pat`
|
|
19
|
+
// LIST, and a legacy chain node never holds one, because every value in a
|
|
20
|
+
// chain node is a map - either the next pattern level or the '$' leaf. So the
|
|
21
|
+
// discriminator holds even for a legacy pattern pair that happens to be
|
|
22
|
+
// spelled `pat:`. Anything without a `pat` list is left alone entirely, which
|
|
23
|
+
// is what lets the two shapes coexist while models migrate message by
|
|
24
|
+
// message.
|
|
25
|
+
//
|
|
26
|
+
// Only the declared shape is checked here. The checks are the two things the
|
|
27
|
+
// flat shape makes checkable and the nested one did not:
|
|
28
|
+
//
|
|
29
|
+
// 1. the entry key agrees with the last pattern pair - the key names the
|
|
30
|
+
// action file, a convention the legacy shape got implicitly from the
|
|
31
|
+
// chain's leaf, and which becomes a real consistency check once the key
|
|
32
|
+
// is written out by hand;
|
|
33
|
+
// 2. no two messages declare the same pattern - previously impossible to
|
|
34
|
+
// state twice, because the pattern WAS the path.
|
|
35
|
+
// Report a problem against the message it belongs to.
|
|
36
|
+
function msgerr(name, why) {
|
|
37
|
+
return 'model msg "' + name + '": ' + why;
|
|
38
|
+
}
|
|
39
|
+
function isObj(val) {
|
|
40
|
+
return null != val && 'object' === typeof val && !Array.isArray(val);
|
|
41
|
+
}
|
|
42
|
+
// A message definition declares its pattern as a list; a chain node never does.
|
|
43
|
+
function isMsgDef(val) {
|
|
44
|
+
return isObj(val) && Array.isArray(val.pat);
|
|
45
|
+
}
|
|
46
|
+
// Sort in UTF-8 byte order, matching Go's sort.Strings, so both
|
|
47
|
+
// implementations report the same problems in the same order. The default JS
|
|
48
|
+
// string sort compares UTF-16 code units, which disagrees for astral-plane
|
|
49
|
+
// names (see the model producer's jsonify, which sorts keys the same way).
|
|
50
|
+
function sortNames(names) {
|
|
51
|
+
return names.sort((a, b) => Buffer.compare(Buffer.from(a), Buffer.from(b)));
|
|
52
|
+
}
|
|
53
|
+
// Validate the declared-shape message entries in main.msg, returning one
|
|
54
|
+
// message per problem found (empty when the model is valid, which includes a
|
|
55
|
+
// model with no messages at all, or only legacy chains).
|
|
56
|
+
function checkMsg(model) {
|
|
57
|
+
const problems = [];
|
|
58
|
+
const msg = model?.main?.msg;
|
|
59
|
+
if (!isObj(msg)) {
|
|
60
|
+
return problems;
|
|
61
|
+
}
|
|
62
|
+
// Canonical pattern -> the message that claimed it first.
|
|
63
|
+
const seen = {};
|
|
64
|
+
for (const name of sortNames(Object.keys(msg))) {
|
|
65
|
+
const def = msg[name];
|
|
66
|
+
// Legacy chain node (or not a map at all): not this check's business.
|
|
67
|
+
if (!isMsgDef(def)) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const pat = def.pat;
|
|
71
|
+
if (0 === pat.length) {
|
|
72
|
+
problems.push(msgerr(name, 'pat declares no pattern pairs'));
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
// Reduce the pattern to its pairs, stopping at the first malformed one -
|
|
76
|
+
// the rest of the checks read the pairs, so there is nothing further to
|
|
77
|
+
// say about this message until its pattern is well-formed.
|
|
78
|
+
//
|
|
79
|
+
// Two renderings: `pairs` reads well in a message, and `canon` identifies
|
|
80
|
+
// the pattern. They cannot be the same string, because `key:value` joined
|
|
81
|
+
// by commas is ambiguous once a key or value contains a delimiter -
|
|
82
|
+
// [{a: "b,c:d"}] and [{a: b}, {c: d}] would both render `a:b,c:d` and the
|
|
83
|
+
// second would be rejected as a duplicate of the first. Quoting each part
|
|
84
|
+
// removes the ambiguity: a delimiter inside a part is escaped, so only
|
|
85
|
+
// genuinely equal patterns produce equal keys.
|
|
86
|
+
const pairs = [];
|
|
87
|
+
const canon = [];
|
|
88
|
+
let last;
|
|
89
|
+
for (let pI = 0; pI < pat.length; pI++) {
|
|
90
|
+
const pair = pat[pI];
|
|
91
|
+
const keys = isObj(pair) ? Object.keys(pair) : [];
|
|
92
|
+
if (1 !== keys.length) {
|
|
93
|
+
problems.push(msgerr(name, 'pat pair ' + pI +
|
|
94
|
+
' is not a single key:value pair'));
|
|
95
|
+
last = undefined;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
const key = keys[0];
|
|
99
|
+
const val = pair[key];
|
|
100
|
+
if ('string' !== typeof val) {
|
|
101
|
+
problems.push(msgerr(name, 'pat pair ' + pI + ' (' + key +
|
|
102
|
+
') value is not a string'));
|
|
103
|
+
last = undefined;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
pairs.push(key + ':' + val);
|
|
107
|
+
canon.push(JSON.stringify(key) + ':' + JSON.stringify(val));
|
|
108
|
+
last = [key, val];
|
|
109
|
+
}
|
|
110
|
+
if (null == last) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
// The entry key names the action file, so it must agree with the last
|
|
114
|
+
// pattern pair.
|
|
115
|
+
const expected = last[0] + '_' + last[1];
|
|
116
|
+
if (name !== expected) {
|
|
117
|
+
problems.push(msgerr(name, 'key does not match last pat pair ' +
|
|
118
|
+
last[0] + ':' + last[1] + ' (expected "' + expected + '")'));
|
|
119
|
+
}
|
|
120
|
+
const canonKey = canon.join(',');
|
|
121
|
+
if (null == seen[canonKey]) {
|
|
122
|
+
seen[canonKey] = name;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
problems.push(msgerr(name, 'pat [' + pairs.join(',') +
|
|
126
|
+
'] is already declared by "' + seen[canonKey] + '"'));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return problems;
|
|
130
|
+
}
|
|
131
|
+
// Checks the message declarations before anything is written.
|
|
132
|
+
//
|
|
133
|
+
// This runs in BOTH phases, and must: a `pre` action can rewrite model source
|
|
134
|
+
// and request a reload, and the build re-resolves the model AFTER the pre
|
|
135
|
+
// phase has finished (see BuildImpl.run). A pre-only check would then have
|
|
136
|
+
// validated a model that no longer exists, and the model producer would write
|
|
137
|
+
// the regenerated one unchecked. Checking again in post closes that window -
|
|
138
|
+
// this producer is first in the pipeline, so it still runs ahead of the model
|
|
139
|
+
// producer, and a build whose model went bad during a reload fails with
|
|
140
|
+
// nothing written.
|
|
141
|
+
const msg_producer = async (build, ctx) => {
|
|
142
|
+
const pr = {
|
|
143
|
+
ok: true,
|
|
144
|
+
name: 'msg',
|
|
145
|
+
reload: false,
|
|
146
|
+
step: ctx.step,
|
|
147
|
+
active: true,
|
|
148
|
+
errs: [],
|
|
149
|
+
runlog: []
|
|
150
|
+
};
|
|
151
|
+
const problems = checkMsg(build.model);
|
|
152
|
+
if (0 < problems.length) {
|
|
153
|
+
pr.ok = false;
|
|
154
|
+
pr.errs = problems.map((problem) => new Error(problem));
|
|
155
|
+
// Add them to the build too. BuildImpl.run collects the errors a producer
|
|
156
|
+
// THROWS, but not the ones it returns, so a returned error would
|
|
157
|
+
// otherwise be missing from the BuildResult. (The Go port needs no such
|
|
158
|
+
// push: its runProducer merges a failed producer's Errs itself. Both
|
|
159
|
+
// implementations end up with the same errors on the build.)
|
|
160
|
+
build.errs.push(...pr.errs);
|
|
161
|
+
build.log.error({
|
|
162
|
+
point: 'msg-invalid',
|
|
163
|
+
count: problems.length,
|
|
164
|
+
note: problems.join('; ')
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return pr;
|
|
168
|
+
};
|
|
169
|
+
exports.msg_producer = msg_producer;
|
|
170
|
+
//# sourceMappingURL=msg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msg.js","sourceRoot":"","sources":["../../src/producer/msg.ts"],"names":[],"mappings":";AAAA,+CAA+C;;;QA6M7C,QAAQ;AAxMV,kEAAkE;AAClE,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,EAAE;AACF,iFAAiF;AACjF,EAAE;AACF,2EAA2E;AAC3E,sEAAsE;AACtE,EAAE;AACF,8EAA8E;AAC9E,EAAE;AACF,yEAAyE;AACzE,0EAA0E;AAC1E,8EAA8E;AAC9E,wEAAwE;AACxE,8EAA8E;AAC9E,sEAAsE;AACtE,WAAW;AACX,EAAE;AACF,6EAA6E;AAC7E,yDAAyD;AACzD,EAAE;AACF,2EAA2E;AAC3E,0EAA0E;AAC1E,6EAA6E;AAC7E,+BAA+B;AAC/B,2EAA2E;AAC3E,sDAAsD;AAGtD,sDAAsD;AACtD,SAAS,MAAM,CAAC,IAAY,EAAE,GAAW;IACvC,OAAO,aAAa,GAAG,IAAI,GAAG,KAAK,GAAG,GAAG,CAAA;AAC3C,CAAC;AAGD,SAAS,KAAK,CAAC,GAAQ;IACrB,OAAO,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;AACtE,CAAC;AAGD,gFAAgF;AAChF,SAAS,QAAQ,CAAC,GAAQ;IACxB,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG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