@mikrojs/native 0.18.2 → 0.19.0-pr-352.20260829215534
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 +25 -2
- package/include/mikrojs/mem.h +4 -0
- package/include/mikrojs/ota_client.h +3 -3
- package/include/mikrojs/platform.h +8 -0
- package/include/mikrojs/private.h +28 -0
- package/package.json +4 -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/http/helpers.ts +5 -0
- package/runtime/internal.d.ts +41 -2
- package/runtime/ota/client.ts +4 -0
- package/runtime/ota/ota.ts +4 -0
- package/runtime/ota/types.ts +75 -0
- package/runtime/schema/schema.ts +25 -3
- package/runtime/schema/types.ts +193 -15
- package/runtime/sys/types.ts +11 -1
- package/runtime/test/test.ts +6 -2
- package/runtime/wifi/types.ts +3 -0
- package/scripts/gen-schema-fixtures.js +317 -0
- package/src/mem.cpp +83 -37
- package/src/mik_app_config.cpp +9 -1
- package/src/mik_http_client.cpp +1357 -0
- package/src/mik_ota_client.cpp +3 -3
- package/src/mik_repl.cpp +44 -5
- package/src/mik_schema.cpp +892 -0
- package/src/mik_sys.cpp +9 -1
- package/src/mik_wifi_client.cpp +742 -0
- package/src/mikrojs.cpp +34 -8
- package/src/modules.cpp +66 -0
- package/dist/runtime/schema/core.d.ts +0 -115
- package/dist/runtime/schema/core.d.ts.map +0 -1
- package/dist/runtime/schema/core.js +0 -259
- package/dist/runtime/schema/core.js.map +0 -1
- package/dist/runtime/schema/shared.d.ts +0 -54
- package/dist/runtime/schema/shared.d.ts.map +0 -1
- package/dist/runtime/schema/shared.js +0 -489
- package/dist/runtime/schema/shared.js.map +0 -1
- package/runtime/http/native.ts +0 -160
- package/runtime/http/request.ts +0 -25
- package/runtime/schema/core.ts +0 -539
- package/runtime/schema/shared.ts +0 -494
- package/runtime/wifi/wifi.ts +0 -191
package/src/mikrojs.cpp
CHANGED
|
@@ -312,6 +312,7 @@ MIKRuntime* MIK_NewRuntimeInternal(MIKRunOptions* options) {
|
|
|
312
312
|
* distinguish "unset" from "set to some object". */
|
|
313
313
|
mik_rt->result_proto = JS_UNDEFINED;
|
|
314
314
|
mik_rt->result_ok_void_singleton = JS_UNDEFINED;
|
|
315
|
+
mik_rt->http_body_consumed_ctor = JS_UNDEFINED;
|
|
315
316
|
|
|
316
317
|
/* Default fs read cap: 64 KiB. Large enough for typical config/JSON
|
|
317
318
|
* payloads on MCU; small enough that a runaway readFile() can't
|
|
@@ -361,7 +362,13 @@ MIKRuntime* MIK_NewRuntimeInternal(MIKRunOptions* options) {
|
|
|
361
362
|
mik__udp_init(ctx);
|
|
362
363
|
mik__observable_init(ctx);
|
|
363
364
|
|
|
364
|
-
/* Native mikrojs modules (replace bytecode builtins)
|
|
365
|
+
/* Native mikrojs modules (replace bytecode builtins). The http client
|
|
366
|
+
* modules are NOT registered here: they load lazily through the C-module
|
|
367
|
+
* table in modules.cpp so virtual modules keep precedence. Schema takes
|
|
368
|
+
* the other lazy route, putting a descriptor on the native: registry,
|
|
369
|
+
* because mikro/schema keeps a small facade for its Result-returning
|
|
370
|
+
* parse(); both are resolved after the virtual-module check. */
|
|
371
|
+
mik__schema_register();
|
|
365
372
|
mik__inspect_register(ctx);
|
|
366
373
|
mik__pub_fs_register(ctx);
|
|
367
374
|
|
|
@@ -432,6 +439,8 @@ void MIK_FreeRuntime(MIKRuntime* mik_rt) {
|
|
|
432
439
|
mik_rt->env_obj = JS_UNDEFINED;
|
|
433
440
|
JS_FreeValue(mik_rt->ctx, mik_rt->result_ok_void_singleton);
|
|
434
441
|
mik_rt->result_ok_void_singleton = JS_UNDEFINED;
|
|
442
|
+
JS_FreeValue(mik_rt->ctx, mik_rt->http_body_consumed_ctor);
|
|
443
|
+
mik_rt->http_body_consumed_ctor = JS_UNDEFINED;
|
|
435
444
|
JS_FreeValue(mik_rt->ctx, mik_rt->result_proto);
|
|
436
445
|
mik_rt->result_proto = JS_UNDEFINED;
|
|
437
446
|
JS_FreeContext(mik_rt->ctx);
|
|
@@ -911,15 +920,32 @@ static void mik__check_pre_eval_headroom(JSContext* ctx, const char* filename) {
|
|
|
911
920
|
if (mem.malloc_limit <= 0) return; /* No limit configured — nothing to warn about. */
|
|
912
921
|
|
|
913
922
|
long headroom = (long)mem.malloc_limit - (long)mem.malloc_size;
|
|
923
|
+
/* The malloc limit is fixed at runtime creation, but the physical heap
|
|
924
|
+
* moves underneath it — the real budget is whichever ceiling is nearer.
|
|
925
|
+
* 0 means the platform can't report system memory (desktop builds). */
|
|
926
|
+
const MIKPlatform* platform = MIK_GetPlatform();
|
|
927
|
+
size_t sys_free = platform->get_free_system_mem();
|
|
928
|
+
bool sys_bound = sys_free > 0 && (long)sys_free < headroom;
|
|
929
|
+
if (sys_bound) {
|
|
930
|
+
headroom = (long)sys_free;
|
|
931
|
+
}
|
|
914
932
|
if (headroom >= MIK__PRE_EVAL_HEADROOM_WARN) return;
|
|
915
933
|
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
934
|
+
if (sys_bound) {
|
|
935
|
+
platform->log(MIK_LOG_WARN, "mikrojs",
|
|
936
|
+
"Low system heap before evaluating '%s': %ld bytes free "
|
|
937
|
+
"(QuickJS %ld / %ld used has room, but native subsystems have "
|
|
938
|
+
"overrun the reserve). Module evaluation may fail with OOM. Raise "
|
|
939
|
+
"`memReserved` in mikro.config.ts or free native resources.",
|
|
940
|
+
filename, headroom, (long)mem.malloc_size, (long)mem.malloc_limit);
|
|
941
|
+
} else {
|
|
942
|
+
platform->log(MIK_LOG_WARN, "mikrojs",
|
|
943
|
+
"Low QuickJS heap headroom before evaluating '%s': %ld bytes left "
|
|
944
|
+
"(%ld / %ld used). Module evaluation may fail with OOM. Lower "
|
|
945
|
+
"`memReserved` in mikro.config.ts or split the module graph with "
|
|
946
|
+
"dynamic imports.",
|
|
947
|
+
filename, headroom, (long)mem.malloc_size, (long)mem.malloc_limit);
|
|
948
|
+
}
|
|
923
949
|
|
|
924
950
|
/* Signal the host so it can take application-level action (flash LED,
|
|
925
951
|
* log metric, trigger reset, forward to telemetry). Operates on C state
|
package/src/modules.cpp
CHANGED
|
@@ -240,6 +240,21 @@ static JSModuleDef* mik_module_loader_inner(JSContext* ctx, const char* module_n
|
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
if (strncmp(mikro_prefix, module_name, strlen(mikro_prefix)) == 0) {
|
|
243
|
+
/* C-backed mikro-prefixed modules (ported from bytecode builtins). Resolved
|
|
244
|
+
* here — after the virtual-module check, before bytecode builtins —
|
|
245
|
+
* so MIK_RegisterVirtualModule keeps documented precedence and
|
|
246
|
+
* runtimes that never import them pay nothing. */
|
|
247
|
+
static const struct {
|
|
248
|
+
const char* name;
|
|
249
|
+
JSModuleDef* (*load)(JSContext* ctx);
|
|
250
|
+
} c_modules[] = {
|
|
251
|
+
{"mikro/http/helpers", mik__http_helpers_load},
|
|
252
|
+
{"mikro/http/request", mik__http_request_load},
|
|
253
|
+
{"mikro/wifi", mik__wifi_client_load},
|
|
254
|
+
};
|
|
255
|
+
for (const auto& cm : c_modules) {
|
|
256
|
+
if (strcmp(cm.name, module_name) == 0) return cm.load(ctx);
|
|
257
|
+
}
|
|
243
258
|
JSModuleDef* builtin_m = mik__load_builtin(ctx, module_name);
|
|
244
259
|
if (builtin_m) return builtin_m;
|
|
245
260
|
/* mik__load_builtin returns NULL either because the module isn't in
|
|
@@ -960,3 +975,54 @@ bool mik__is_unloadable_namespace(JSContext* ctx, JSValueConst ns) {
|
|
|
960
975
|
JS_FreeCString(ctx, name);
|
|
961
976
|
return ok;
|
|
962
977
|
}
|
|
978
|
+
|
|
979
|
+
/* Load `specifier` through the module loader on behalf of `importer` and
|
|
980
|
+
* return its namespace. Goes through the loader (not the C-module table
|
|
981
|
+
* directly) so virtual-module overrides keep documented precedence.
|
|
982
|
+
*
|
|
983
|
+
* A PENDING evaluation promise is normal even for fully synchronous modules:
|
|
984
|
+
* quickjs-ng settles it through the job queue when this runs inside an outer
|
|
985
|
+
* module graph. Two invariants, picked by `require_evaluated`:
|
|
986
|
+
* - false: the caller only stores the namespace or reads hoisted function
|
|
987
|
+
* exports, which are safe from instantiation onward.
|
|
988
|
+
* - true: the caller immediately reads or invokes const/class exports, so
|
|
989
|
+
* the module body must have finished running (status EVALUATED); a module
|
|
990
|
+
* parked in top-level await fails with a clear error instead of TDZ. */
|
|
991
|
+
JSValue mik__load_module_ns(JSContext* ctx, const char* importer, const char* specifier,
|
|
992
|
+
bool require_evaluated) {
|
|
993
|
+
JSAtom name = JS_NewAtom(ctx, specifier);
|
|
994
|
+
JSModuleDef* m = JS_FindLoadedModule(ctx, name);
|
|
995
|
+
if (!m) {
|
|
996
|
+
JSValue p = JS_LoadModule(ctx, importer, specifier);
|
|
997
|
+
if (JS_IsException(p)) {
|
|
998
|
+
/* Propagate the loader's real error (e.g. a syntax error in a
|
|
999
|
+
* virtual stub), not a generic not-available message. */
|
|
1000
|
+
JS_FreeAtom(ctx, name);
|
|
1001
|
+
return p;
|
|
1002
|
+
}
|
|
1003
|
+
if (JS_PromiseState(ctx, p) == JS_PROMISE_REJECTED) {
|
|
1004
|
+
JSValue reason = JS_PromiseResult(ctx, p);
|
|
1005
|
+
JS_PromiseMarkAsHandled(ctx, p);
|
|
1006
|
+
JS_FreeValue(ctx, p);
|
|
1007
|
+
JS_FreeAtom(ctx, name);
|
|
1008
|
+
return JS_Throw(ctx, reason);
|
|
1009
|
+
}
|
|
1010
|
+
/* A PENDING promise (top-level-await stub) may still reject later;
|
|
1011
|
+
* mark it handled so that surfaces as a load error, not as an
|
|
1012
|
+
* unhandled-rejection report. Harmless for the fulfilled case. */
|
|
1013
|
+
JS_PromiseMarkAsHandled(ctx, p);
|
|
1014
|
+
JS_FreeValue(ctx, p);
|
|
1015
|
+
m = JS_FindLoadedModule(ctx, name);
|
|
1016
|
+
}
|
|
1017
|
+
JS_FreeAtom(ctx, name);
|
|
1018
|
+
if (!m) {
|
|
1019
|
+
return JS_ThrowReferenceError(ctx, "Native module '%s' is not available", specifier);
|
|
1020
|
+
}
|
|
1021
|
+
/* 5 == EVALUATED; quickjs.h documents the numbering but exports no enum. */
|
|
1022
|
+
if (require_evaluated && JS_GetModuleStatus(ctx, m) != 5) {
|
|
1023
|
+
return JS_ThrowReferenceError(
|
|
1024
|
+
ctx, "Module '%s' has not finished evaluating (top-level await is not supported here)",
|
|
1025
|
+
specifier);
|
|
1026
|
+
}
|
|
1027
|
+
return JS_GetModuleNamespace(ctx, m);
|
|
1028
|
+
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
declare function err<E>(error: E): {
|
|
2
|
-
ok: false;
|
|
3
|
-
error: E;
|
|
4
|
-
};
|
|
5
|
-
export declare const SchemaError: {
|
|
6
|
-
ValidationFailed: (message: string, path: string) => {
|
|
7
|
-
readonly name: "ValidationFailed";
|
|
8
|
-
readonly message: string;
|
|
9
|
-
readonly path: string;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
export type SchemaError = ReturnType<typeof SchemaError.ValidationFailed>;
|
|
13
|
-
type Primitive = string | number | boolean;
|
|
14
|
-
export interface StringSchema {
|
|
15
|
-
readonly kind: 'string';
|
|
16
|
-
readonly default?: string;
|
|
17
|
-
}
|
|
18
|
-
export interface NumberSchema {
|
|
19
|
-
readonly kind: 'number';
|
|
20
|
-
readonly default?: number;
|
|
21
|
-
}
|
|
22
|
-
export interface BooleanSchema {
|
|
23
|
-
readonly kind: 'boolean';
|
|
24
|
-
readonly default?: boolean;
|
|
25
|
-
}
|
|
26
|
-
export interface UnknownSchema {
|
|
27
|
-
readonly kind: 'unknown';
|
|
28
|
-
}
|
|
29
|
-
export interface LiteralSchema<T extends Primitive = Primitive> {
|
|
30
|
-
readonly kind: 'literal';
|
|
31
|
-
readonly value: T;
|
|
32
|
-
readonly default?: T;
|
|
33
|
-
}
|
|
34
|
-
export interface ArraySchema<S extends Schema = Schema> {
|
|
35
|
-
readonly kind: 'array';
|
|
36
|
-
readonly element: S;
|
|
37
|
-
readonly default?: unknown;
|
|
38
|
-
}
|
|
39
|
-
export interface ObjectSchema<Shape extends Record<string, Schema> = Record<string, Schema>> {
|
|
40
|
-
readonly kind: 'object';
|
|
41
|
-
readonly shape: Shape;
|
|
42
|
-
}
|
|
43
|
-
export interface OptionalSchema<S extends Schema = Schema> {
|
|
44
|
-
readonly kind: 'optional';
|
|
45
|
-
readonly inner: S;
|
|
46
|
-
}
|
|
47
|
-
export interface TupleSchema<Elements extends readonly Schema[] = readonly Schema[]> {
|
|
48
|
-
readonly kind: 'tuple';
|
|
49
|
-
readonly elements: Elements;
|
|
50
|
-
readonly default?: unknown;
|
|
51
|
-
}
|
|
52
|
-
export interface UnionSchema<Members extends readonly Schema[] = readonly Schema[]> {
|
|
53
|
-
readonly kind: 'union';
|
|
54
|
-
readonly members: Members;
|
|
55
|
-
readonly default?: unknown;
|
|
56
|
-
}
|
|
57
|
-
export interface TaggedUnionSchema<Key extends string = string, Branches extends Record<string, ObjectSchema> = Record<string, ObjectSchema>> {
|
|
58
|
-
readonly kind: 'taggedUnion';
|
|
59
|
-
readonly key: Key;
|
|
60
|
-
readonly branches: Branches;
|
|
61
|
-
readonly default?: unknown;
|
|
62
|
-
}
|
|
63
|
-
export type Schema = StringSchema | NumberSchema | BooleanSchema | UnknownSchema | LiteralSchema | ArraySchema | ObjectSchema | OptionalSchema | TupleSchema | UnionSchema | TaggedUnionSchema;
|
|
64
|
-
type Simplify<T> = {
|
|
65
|
-
[K in keyof T]: T[K];
|
|
66
|
-
} & {};
|
|
67
|
-
export type Infer<S> = S extends StringSchema ? string : S extends NumberSchema ? number : S extends BooleanSchema ? boolean : S extends UnknownSchema ? unknown : S extends LiteralSchema<infer T> ? T : S extends ArraySchema<infer E> ? ArraySchema extends S ? [] : Infer<E>[] : S extends ObjectSchema<infer Shape> ? ObjectSchema extends S ? object : Simplify<InferObject<Shape>> : S extends TupleSchema<infer Elements> ? InferTuple<Elements> : S extends OptionalSchema<infer Inner> ? OptionalSchema extends S ? OptionalSchema : Infer<Inner> | undefined : S extends UnionSchema<infer Members> ? InferUnion<Members> : S extends TaggedUnionSchema<infer Key, infer Branches> ? InferTaggedUnion<Key, Branches> : never;
|
|
68
|
-
type InferObject<Shape> = {
|
|
69
|
-
[K in keyof Shape as Shape[K] extends OptionalSchema ? never : K]: Infer<Shape[K]>;
|
|
70
|
-
} & {
|
|
71
|
-
[K in keyof Shape as Shape[K] extends OptionalSchema ? K : never]?: Infer<Shape[K]>;
|
|
72
|
-
};
|
|
73
|
-
type InferTuple<Elements> = Elements extends readonly [infer Head, ...infer Tail] ? [Infer<Head>, ...InferTuple<Tail>] : [];
|
|
74
|
-
type InferUnion<Members> = Members extends readonly [infer Head, ...infer Tail] ? Infer<Head> | InferUnion<Tail> : never;
|
|
75
|
-
type InferTaggedUnion<Key extends string, Branches> = {
|
|
76
|
-
[Tag in keyof Branches & string]: {
|
|
77
|
-
[K in Key]: Tag;
|
|
78
|
-
} & Infer<Branches[Tag]>;
|
|
79
|
-
}[keyof Branches & string];
|
|
80
|
-
export type InferRead<S> = S extends ObjectSchema<infer Shape> ? ObjectSchema extends S ? object : Simplify<InferReadObject<Shape>> : Infer<S>;
|
|
81
|
-
type Filled<S> = S extends {
|
|
82
|
-
default: unknown;
|
|
83
|
-
} ? true : S extends OptionalSchema ? false : S extends ObjectSchema<infer Shape> ? ObjectSchema extends S ? false : AllFilled<Shape> : false;
|
|
84
|
-
type AllFilled<Shape> = false extends {
|
|
85
|
-
[K in keyof Shape]: Shape[K] extends OptionalSchema ? true : Filled<Shape[K]>;
|
|
86
|
-
}[keyof Shape] ? false : true;
|
|
87
|
-
type InferReadObject<Shape> = {
|
|
88
|
-
[K in keyof Shape as Filled<Shape[K]> extends true ? K : never]: InferRead<Shape[K]>;
|
|
89
|
-
} & {
|
|
90
|
-
[K in keyof Shape as Filled<Shape[K]> extends true ? never : K]?: InferRead<Shape[K]>;
|
|
91
|
-
};
|
|
92
|
-
export interface ScalarOptions<T> {
|
|
93
|
-
readonly default?: T;
|
|
94
|
-
}
|
|
95
|
-
export interface DefaultOption<T> {
|
|
96
|
-
readonly default?: T;
|
|
97
|
-
}
|
|
98
|
-
type Defaulted<S, D> = [D] extends [undefined] ? S : S & {
|
|
99
|
-
readonly default: unknown;
|
|
100
|
-
};
|
|
101
|
-
export declare function string<D extends string | undefined = undefined>(options?: ScalarOptions<D>): Defaulted<StringSchema, D>;
|
|
102
|
-
export declare function number<D extends number | undefined = undefined>(options?: ScalarOptions<D>): Defaulted<NumberSchema, D>;
|
|
103
|
-
export declare function boolean<D extends boolean | undefined = undefined>(options?: ScalarOptions<D>): Defaulted<BooleanSchema, D>;
|
|
104
|
-
export declare function unknown(): UnknownSchema;
|
|
105
|
-
export declare function literal<T extends Primitive, D extends T | undefined = undefined>(value: T, options?: ScalarOptions<D>): Defaulted<LiteralSchema<T>, D>;
|
|
106
|
-
export declare function array<S extends Schema, D extends NoInfer<Infer<S>>[] | undefined = undefined>(element: S, options?: DefaultOption<D>): Defaulted<ArraySchema<S>, D>;
|
|
107
|
-
export declare function object<Shape extends Record<string, Schema>>(shape: Shape, options?: DefaultOption<never>): ObjectSchema<Shape>;
|
|
108
|
-
export declare function tuple<Elements extends readonly Schema[], D extends NoInfer<Infer<TupleSchema<Elements>>> | undefined = undefined>(elements: [...Elements], options?: DefaultOption<D>): Defaulted<TupleSchema<Elements>, D>;
|
|
109
|
-
export declare function optional<S extends Schema>(inner: S): OptionalSchema<S>;
|
|
110
|
-
export declare function union<Members extends readonly Schema[], D extends NoInfer<Infer<UnionSchema<Members>>> | undefined = undefined>(members: [...Members], options?: DefaultOption<D>): Defaulted<UnionSchema<Members>, D>;
|
|
111
|
-
export declare function taggedUnion<Key extends string, Branches extends Record<string, ObjectSchema>, D extends NoInfer<Infer<TaggedUnionSchema<Key, Branches>>> | undefined = undefined>(key: Key, branches: Branches, options?: DefaultOption<D>): Defaulted<TaggedUnionSchema<Key, Branches>, D>;
|
|
112
|
-
export declare function applyDefaults(schema: Schema, value: unknown): unknown;
|
|
113
|
-
export declare function validate(schema: Schema, value: unknown, path: string): ReturnType<typeof err<SchemaError>> | null;
|
|
114
|
-
export {};
|
|
115
|
-
//# sourceMappingURL=core.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../runtime/schema/core.ts"],"names":[],"mappings":"AAKA,iBAAS,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;;;EAEvB;AAED,eAAO,MAAM,WAAW;gCACM,MAAM,QAAQ,MAAM;;;;;CAEjD,CAAA;AACD,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,gBAAgB,CAAC,CAAA;AAIzE,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AAO1C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CACzB;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAC5D,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAA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AiB,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAShD;AAUD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAuCrE;AAUD,wBAAgB,QAAQ,CACtB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,GACX,UAAU,CAAC,OAAO,GAAG,CAAC,WAAW,CAAC,CAAC,GAAG,IAAI,CAgI5C"}
|
|
@@ -1,259 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,CAAU;CACvD,CAAA;AAkMD;;;;0BAI0B;AAC1B,SAAS,mBAAmB,CAAC,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,IAAY;IACjF,IAAK,IAA4B,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACxD,MAAM,IAAI,SAAS,CACjB,mBAAmB,IAAI,wBAAwB,IAAI,wBAAwB;YACzE,6BAA6B,IAAI,GAAG,CACvC,CAAA;IACH,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC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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"}
|
|
@@ -1,54 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|