@mikrojs/native 0.18.0 → 0.18.1
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/CMakeLists.txt +62 -1
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/runtime/result/native-result.node-shim.d.ts +3 -0
- package/dist/runtime/result/native-result.node-shim.d.ts.map +1 -0
- package/dist/runtime/result/native-result.node-shim.js +41 -0
- package/dist/runtime/result/native-result.node-shim.js.map +1 -0
- package/dist/runtime/result/types.d.ts +55 -0
- package/dist/runtime/result/types.d.ts.map +1 -0
- package/dist/runtime/result/types.js +2 -0
- package/dist/runtime/result/types.js.map +1 -0
- package/dist/runtime/schema/core.d.ts +115 -0
- package/dist/runtime/schema/core.d.ts.map +1 -0
- package/dist/runtime/schema/core.js +259 -0
- package/dist/runtime/schema/core.js.map +1 -0
- package/dist/runtime/schema/shared.d.ts +54 -0
- package/dist/runtime/schema/shared.d.ts.map +1 -0
- package/dist/runtime/schema/shared.js +489 -0
- package/dist/runtime/schema/shared.js.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/include/mikrojs/cbor_helpers.h +20 -0
- package/include/mikrojs/mem.h +11 -0
- package/include/mikrojs/mikrojs.h +2 -1
- package/include/mikrojs/ota_client.h +342 -0
- package/include/mikrojs/ota_config.h +100 -0
- package/include/mikrojs/ota_env.h +192 -0
- package/include/mikrojs/ota_js_hooks.h +71 -0
- package/include/mikrojs/ota_policy.h +131 -0
- package/include/mikrojs/ota_slots.h +47 -0
- package/include/mikrojs/sys_codec.h +61 -0
- package/package.json +7 -5
- package/prebuilds/darwin-arm64/mikrojs.napi.node +0 -0
- package/prebuilds/linux-arm64/mikrojs.napi.node +0 -0
- package/prebuilds/linux-x64/mikrojs.napi.node +0 -0
- package/runtime/internal.d.ts +22 -16
- package/runtime/kv/shared.ts +11 -5
- package/runtime/kv/types.ts +4 -4
- package/runtime/ota/client.ts +12 -51
- package/runtime/ota/config.ts +18 -0
- package/runtime/ota/ota.ts +28 -70
- package/runtime/ota/types.ts +220 -2
- package/runtime/schema/core.ts +539 -0
- package/runtime/schema/schema.ts +36 -314
- package/runtime/schema/shared.ts +494 -0
- package/runtime/schema/types.ts +84 -12
- package/scripts/bundle-runtime.js +33 -0
- package/scripts/gen-checkin-fixtures.js +323 -0
- package/src/builtins.cpp +7 -8
- package/src/fs.cpp +3 -0
- package/src/mem.cpp +38 -0
- package/src/mik_abort.cpp +8 -1
- package/src/mik_cbor.cpp +43 -5
- package/src/mik_inspect.cpp +128 -22
- package/src/mik_ota_client.cpp +1230 -0
- package/src/mik_ota_config.cpp +296 -0
- package/src/mik_ota_js_hooks.cpp +190 -0
- package/src/mik_ota_policy.cpp +419 -0
- package/src/mik_ota_slots.cpp +249 -0
- package/src/mik_repl.cpp +9 -3
- package/src/mik_result.cpp +3 -1
- package/src/mik_sys_codec.cpp +167 -0
- package/src/mikrojs.cpp +15 -0
- package/src/modules.cpp +32 -13
- package/runtime/ota/client-impl.ts +0 -590
- package/runtime/ota/policy.ts +0 -299
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/* Core schema machinery: types, constructors, the validator, and
|
|
2
|
+
* applyDefaults. Dependency-free so hosts (CLI, registries) can import it via
|
|
3
|
+
* shared.ts without resolving mikro/* builtins; mikro/schema re-exports it and
|
|
4
|
+
* adds the Result-returning parse(). */
|
|
5
|
+
function err(error) {
|
|
6
|
+
return { ok: false, error };
|
|
7
|
+
}
|
|
8
|
+
export const SchemaError = {
|
|
9
|
+
ValidationFailed: (message, path) => ({ name: 'ValidationFailed', message, path }),
|
|
10
|
+
};
|
|
11
|
+
/* Defaults below a wholesale unit never fill: applyDefaults replaces the unit
|
|
12
|
+
* whole, so only a unit-level default applies. Rejected where they are written
|
|
13
|
+
* rather than at the validation that later misses the field. The walk stops at
|
|
14
|
+
* a nested unit's own default, since that unit's constructor already cleared
|
|
15
|
+
* everything under it. */
|
|
16
|
+
function rejectInnerDefaults(node, path, unit, self) {
|
|
17
|
+
if (node.default !== undefined) {
|
|
18
|
+
throw new TypeError(`a default under ${unit} never applies; give ${self} itself a whole-value ` +
|
|
19
|
+
`default instead (found at ${path})`);
|
|
20
|
+
}
|
|
21
|
+
if (node.kind === 'object') {
|
|
22
|
+
const keys = Object.keys(node.shape);
|
|
23
|
+
for (let i = 0; i < keys.length; i++) {
|
|
24
|
+
rejectInnerDefaults(node.shape[keys[i]], `${path}.${keys[i]}`, unit, self);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else if (node.kind === 'optional') {
|
|
28
|
+
// optional() rejects an inner default itself, so this only reaches what it
|
|
29
|
+
// wraps without reporting the same node twice.
|
|
30
|
+
rejectInnerDefaults(node.inner, path, unit, self);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/* Copies the annotation onto the node and rejects a `default` the node itself
|
|
34
|
+
* would not accept, so a bad default fails where it is written. */
|
|
35
|
+
function annotate(node, options) {
|
|
36
|
+
if (options === undefined)
|
|
37
|
+
return node;
|
|
38
|
+
const out = node;
|
|
39
|
+
if (options.default !== undefined) {
|
|
40
|
+
out.default = options.default;
|
|
41
|
+
const result = validate(node, options.default, '');
|
|
42
|
+
if (result !== null) {
|
|
43
|
+
throw new TypeError(`schema default does not match the schema: ${result.error.message}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return node;
|
|
47
|
+
}
|
|
48
|
+
export function string(options) {
|
|
49
|
+
return annotate({ kind: 'string' }, options);
|
|
50
|
+
}
|
|
51
|
+
export function number(options) {
|
|
52
|
+
return annotate({ kind: 'number' }, options);
|
|
53
|
+
}
|
|
54
|
+
export function boolean(options) {
|
|
55
|
+
return annotate({ kind: 'boolean' }, options);
|
|
56
|
+
}
|
|
57
|
+
export function unknown() {
|
|
58
|
+
return { kind: 'unknown' };
|
|
59
|
+
}
|
|
60
|
+
export function literal(value, options) {
|
|
61
|
+
return annotate({ kind: 'literal', value }, options);
|
|
62
|
+
}
|
|
63
|
+
export function array(element, options) {
|
|
64
|
+
rejectInnerDefaults(element, '[]', 'an array', 'the array');
|
|
65
|
+
return annotate({ kind: 'array', element }, options);
|
|
66
|
+
}
|
|
67
|
+
export function object(shape, options) {
|
|
68
|
+
if (options?.default !== undefined) {
|
|
69
|
+
throw new TypeError("an object's defaults compose from its fields; declare defaults on the fields");
|
|
70
|
+
}
|
|
71
|
+
return { kind: 'object', shape };
|
|
72
|
+
}
|
|
73
|
+
export function tuple(elements, options) {
|
|
74
|
+
for (let i = 0; i < elements.length; i++) {
|
|
75
|
+
rejectInnerDefaults(elements[i], `[${i}]`, 'a tuple', 'the tuple');
|
|
76
|
+
}
|
|
77
|
+
return annotate({ kind: 'tuple', elements }, options);
|
|
78
|
+
}
|
|
79
|
+
export function optional(inner) {
|
|
80
|
+
if (inner.default !== undefined) {
|
|
81
|
+
throw new TypeError('optional() cannot wrap a schema with a default');
|
|
82
|
+
}
|
|
83
|
+
return { kind: 'optional', inner };
|
|
84
|
+
}
|
|
85
|
+
export function union(members, options) {
|
|
86
|
+
for (let i = 0; i < members.length; i++) {
|
|
87
|
+
rejectInnerDefaults(members[i], `[${i}]`, 'a union', 'the union');
|
|
88
|
+
}
|
|
89
|
+
return annotate({ kind: 'union', members }, options);
|
|
90
|
+
}
|
|
91
|
+
export function taggedUnion(key, branches, options) {
|
|
92
|
+
const tags = Object.keys(branches);
|
|
93
|
+
for (let i = 0; i < tags.length; i++) {
|
|
94
|
+
rejectInnerDefaults(branches[tags[i]], `.${tags[i]}`, 'a taggedUnion', 'the union');
|
|
95
|
+
}
|
|
96
|
+
return annotate({ kind: 'taggedUnion', key, branches }, options);
|
|
97
|
+
}
|
|
98
|
+
// ── Defaults ────────────────────────────────────────────────────────
|
|
99
|
+
/* Builds the effective value: schema defaults with `value` layered over them.
|
|
100
|
+
* Objects are structure and always materialize (recursing per field, unknown
|
|
101
|
+
* keys dropped); every other node is replaced wholesale by a present value, so
|
|
102
|
+
* defaults inside array elements or union branches are form hints, not fills.
|
|
103
|
+
* The result is unvalidated — a missing required field stays missing for
|
|
104
|
+
* parse() to report. */
|
|
105
|
+
export function applyDefaults(schema, value) {
|
|
106
|
+
switch (schema.kind) {
|
|
107
|
+
case 'object': {
|
|
108
|
+
// A present non-object stays as-is so validation rejects it; replacing
|
|
109
|
+
// it with {} here would make `{mqtt: 42}` validate clean and never
|
|
110
|
+
// record a configError.
|
|
111
|
+
if (value !== undefined &&
|
|
112
|
+
(typeof value !== 'object' || value === null || Array.isArray(value))) {
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
const src = value === undefined ? {} : value;
|
|
116
|
+
const out = {};
|
|
117
|
+
const keys = Object.keys(schema.shape);
|
|
118
|
+
for (let i = 0; i < keys.length; i++) {
|
|
119
|
+
const key = keys[i];
|
|
120
|
+
const field = schema.shape[key];
|
|
121
|
+
// hasOwn, not indexing: a shape key like "constructor" must read as
|
|
122
|
+
// absent, not as the inherited prototype member.
|
|
123
|
+
const raw = Object.hasOwn(src, key) ? src[key] : undefined;
|
|
124
|
+
if (field.kind === 'optional') {
|
|
125
|
+
if (raw !== undefined)
|
|
126
|
+
out[key] = raw;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
const child = applyDefaults(field, raw);
|
|
130
|
+
if (child !== undefined)
|
|
131
|
+
out[key] = child;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
case 'array':
|
|
137
|
+
if (value !== undefined)
|
|
138
|
+
return value;
|
|
139
|
+
return schema.default !== undefined ? schema.default : [];
|
|
140
|
+
case 'unknown':
|
|
141
|
+
case 'optional':
|
|
142
|
+
return value;
|
|
143
|
+
default:
|
|
144
|
+
return value !== undefined ? value : schema.default;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// ── Parse ───────────────────────────────────────────────────────────
|
|
148
|
+
function typeOf(value) {
|
|
149
|
+
if (value === null)
|
|
150
|
+
return 'null';
|
|
151
|
+
if (Array.isArray(value))
|
|
152
|
+
return 'array';
|
|
153
|
+
return typeof value;
|
|
154
|
+
}
|
|
155
|
+
export function validate(schema, value, path) {
|
|
156
|
+
switch (schema.kind) {
|
|
157
|
+
case 'string':
|
|
158
|
+
if (typeof value !== 'string')
|
|
159
|
+
return err(SchemaError.ValidationFailed(`expected string, got ${typeOf(value)}`, path));
|
|
160
|
+
return null;
|
|
161
|
+
case 'number':
|
|
162
|
+
if (typeof value !== 'number' || Number.isNaN(value))
|
|
163
|
+
return err(SchemaError.ValidationFailed(`expected number, got ${typeOf(value)}`, path));
|
|
164
|
+
return null;
|
|
165
|
+
case 'boolean':
|
|
166
|
+
if (typeof value !== 'boolean')
|
|
167
|
+
return err(SchemaError.ValidationFailed(`expected boolean, got ${typeOf(value)}`, path));
|
|
168
|
+
return null;
|
|
169
|
+
case 'unknown':
|
|
170
|
+
return null;
|
|
171
|
+
case 'literal':
|
|
172
|
+
if (value !== schema.value)
|
|
173
|
+
return err(SchemaError.ValidationFailed(`expected ${JSON.stringify(schema.value)}, got ${JSON.stringify(value)}`, path));
|
|
174
|
+
return null;
|
|
175
|
+
case 'array': {
|
|
176
|
+
if (!Array.isArray(value))
|
|
177
|
+
return err(SchemaError.ValidationFailed(`expected array, got ${typeOf(value)}`, path));
|
|
178
|
+
for (let i = 0; i < value.length; i++) {
|
|
179
|
+
const result = validate(schema.element, value[i], `${path}[${i}]`);
|
|
180
|
+
if (result !== null)
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
case 'object': {
|
|
186
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
187
|
+
return err(SchemaError.ValidationFailed(`expected object, got ${typeOf(value)}`, path));
|
|
188
|
+
const obj = value;
|
|
189
|
+
const keys = Object.keys(schema.shape);
|
|
190
|
+
for (let i = 0; i < keys.length; i++) {
|
|
191
|
+
const key = keys[i];
|
|
192
|
+
const fieldSchema = schema.shape[key];
|
|
193
|
+
const fieldPath = `${path}.${key}`;
|
|
194
|
+
// hasOwn, like the taggedUnion dispatch: an inherited "constructor"
|
|
195
|
+
// must not stand in for a field.
|
|
196
|
+
if (fieldSchema.kind === 'optional') {
|
|
197
|
+
if (Object.hasOwn(obj, key)) {
|
|
198
|
+
const result = validate(fieldSchema, obj[key], fieldPath);
|
|
199
|
+
if (result !== null)
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
if (!Object.hasOwn(obj, key))
|
|
205
|
+
return err(SchemaError.ValidationFailed(`missing required field`, fieldPath));
|
|
206
|
+
const result = validate(fieldSchema, obj[key], fieldPath);
|
|
207
|
+
if (result !== null)
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
case 'tuple': {
|
|
214
|
+
if (!Array.isArray(value))
|
|
215
|
+
return err(SchemaError.ValidationFailed(`expected array, got ${typeOf(value)}`, path));
|
|
216
|
+
if (value.length !== schema.elements.length)
|
|
217
|
+
return err(SchemaError.ValidationFailed(`expected ${schema.elements.length} elements, got ${value.length}`, path));
|
|
218
|
+
for (let i = 0; i < schema.elements.length; i++) {
|
|
219
|
+
const result = validate(schema.elements[i], value[i], `${path}[${i}]`);
|
|
220
|
+
if (result !== null)
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
case 'optional': {
|
|
226
|
+
if (value === undefined)
|
|
227
|
+
return null;
|
|
228
|
+
return validate(schema.inner, value, path);
|
|
229
|
+
}
|
|
230
|
+
case 'union': {
|
|
231
|
+
for (let i = 0; i < schema.members.length; i++) {
|
|
232
|
+
const result = validate(schema.members[i], value, path);
|
|
233
|
+
if (result === null)
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
return err(SchemaError.ValidationFailed(`value did not match any union member`, path));
|
|
237
|
+
}
|
|
238
|
+
case 'taggedUnion': {
|
|
239
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
240
|
+
return err(SchemaError.ValidationFailed(`expected object, got ${typeOf(value)}`, path));
|
|
241
|
+
const obj = value;
|
|
242
|
+
const tag = obj[schema.key];
|
|
243
|
+
if (tag === undefined)
|
|
244
|
+
return err(SchemaError.ValidationFailed(`missing discriminator field`, `${path}.${schema.key}`));
|
|
245
|
+
if (typeof tag !== 'string' && typeof tag !== 'number' && typeof tag !== 'boolean')
|
|
246
|
+
return err(SchemaError.ValidationFailed(`expected primitive discriminator, got ${typeOf(tag)}`, `${path}.${schema.key}`));
|
|
247
|
+
// hasOwn, not indexing: a tag like "constructor" must not resolve to
|
|
248
|
+
// an inherited property and validate against garbage.
|
|
249
|
+
const branch = Object.hasOwn(schema.branches, tag)
|
|
250
|
+
? schema.branches[tag]
|
|
251
|
+
: undefined;
|
|
252
|
+
if (branch === undefined)
|
|
253
|
+
return err(SchemaError.ValidationFailed(`unknown tag ${JSON.stringify(tag)}`, `${path}.${schema.key}`));
|
|
254
|
+
return validate(branch, value, path);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return err(SchemaError.ValidationFailed(`unknown schema kind: ${schema.kind}`, path));
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../runtime/schema/core.ts"],"names":[],"mappings":"AAAA;;;wCAGwC;AAExC,SAAS,GAAG,CAAI,KAAQ;IACtB,OAAO,EAAC,EAAE,EAAE,KAAc,EAAE,KAAK,EAAC,CAAA;AACpC,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,gBAAgB,EAAE,CAAC,OAAe,EAAE,IAAY,EAAE,EAAE,CAClD,CAAC,EAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,IAAI,EAAC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AAG,IAAI,IAAI,MAAM,CAAC,GAAG,EAAE,CACxB,CACF,CAAA;YACH,qEAAqE;YACrE,sDAAsD;YACtD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAa,CAAC;gBAC1D,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAa,CAAC;gBAChC,CAAC,CAAC,SAAS,CAAA;YACb,IAAI,MAAM,KAAK,SAAS;gBACtB,OAAO,GAAG,CACR,WAAW,CAAC,gBAAgB,CAC1B,eAAe,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EACpC,GAAG,IAAI,IAAI,MAAM,CAAC,GAAG,EAAE,CACxB,CACF,CAAA;YACH,OAAO,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QACtC,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC,WAAW,CAAC,gBAAgB,CAAC,wBAAyB,MAAc,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC,CAAA;AAChG,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type Schema, SchemaError } from './core.js';
|
|
2
|
+
export type SchemaCheck<T> = {
|
|
3
|
+
ok: true;
|
|
4
|
+
value: T;
|
|
5
|
+
} | {
|
|
6
|
+
ok: false;
|
|
7
|
+
error: SchemaError;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Validates an untrusted serialized schema AST as a config schema: well-formed
|
|
11
|
+
* nodes only, an object at the root, no `unknown()`, no `optional()` around an
|
|
12
|
+
* object or array (an overlay needs every absence to mean exactly one thing),
|
|
13
|
+
* defaults that match their own node, and nesting of at most 8 levels.
|
|
14
|
+
* The size cap is the caller's, since only the caller sees encoded bytes.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseConfigSchema(value: unknown): SchemaCheck<Schema>;
|
|
17
|
+
/**
|
|
18
|
+
* Derives the overlay to store or serve from operator-supplied values: drops
|
|
19
|
+
* keys the schema does not know, strips values structurally equal to the
|
|
20
|
+
* schema default, and prunes empty objects and arrays. Returns undefined when
|
|
21
|
+
* nothing deviates from the defaults. Wholesale nodes (arrays, tuples, unions)
|
|
22
|
+
* are compared and kept as units; nothing inside them is stripped.
|
|
23
|
+
*/
|
|
24
|
+
export declare function deriveOverlay(schema: Schema, values: unknown): unknown;
|
|
25
|
+
export declare function structuralEquals(a: unknown, b: unknown): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* The effective config for an overlay: defaults filled in, then validated.
|
|
28
|
+
* What a registry runs before serving and what `ota.config()` runs on read.
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseEffective(schema: Schema, overlay: unknown): SchemaCheck<unknown>;
|
|
31
|
+
/**
|
|
32
|
+
* The partial defaults a schema materializes with no overrides: every field a
|
|
33
|
+
* default covers, and nothing else. Unlike parseEffective it never fails on a
|
|
34
|
+
* required defaultless field, it omits it. This is what pack bakes into the
|
|
35
|
+
* manifest and what a device reads when it holds no served document.
|
|
36
|
+
*
|
|
37
|
+
* Plain objects compose, so a nested one is included only when defaults fill
|
|
38
|
+
* it completely: a half-filled object would not validate, and the read type
|
|
39
|
+
* makes that field optional anyway. Wholesale units (array, tuple, union,
|
|
40
|
+
* taggedUnion) need a whole-value default on the node itself, matching
|
|
41
|
+
* applyDefaults, where a default inside an element or branch is a form hint.
|
|
42
|
+
* Optional fields rest on absence, so they are omitted too.
|
|
43
|
+
*/
|
|
44
|
+
export declare function materializeDefaults(schema: Schema): Record<string, unknown>;
|
|
45
|
+
/**
|
|
46
|
+
* Human-readable warnings for what changed between two releases' config
|
|
47
|
+
* schemas, per the spec's change taxonomy (registry-spec.md, "Schema changes
|
|
48
|
+
* between releases"). Safe changes (new defaulted or optional fields, added
|
|
49
|
+
* union members, loosened requirements) produce nothing. "requires an
|
|
50
|
+
* operator" lines gate offers under rule 5 until someone supplies or fixes a
|
|
51
|
+
* value; "note" lines are compatible but worth telling the operator about.
|
|
52
|
+
*/
|
|
53
|
+
export declare function diffConfigSchemas(previous: Schema, next: Schema): string[];
|
|
54
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../runtime/schema/shared.ts"],"names":[],"mappings":"AAMA,OAAO,EAAmC,KAAK,MAAM,EAAE,WAAW,EAAW,MAAM,WAAW,CAAA;AAE9F,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAAC,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAC,GAAG;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAC,CAAA;AA4BnF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,CAOrE;AAuJD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAuCtE;AAkBD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAmBhE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAIrF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE3E;AAwED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAsG1E"}
|