@thi.ng/wasm-api 0.16.0 → 0.17.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/CHANGELOG.md +15 -1
- package/api.d.ts +9 -5
- package/codegen/utils.d.ts +8 -0
- package/codegen/utils.js +13 -0
- package/codegen/zig.js +10 -8
- package/codegen.js +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2022-10-
|
|
3
|
+
- **Last updated**: 2022-10-29T20:34:04Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,20 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [0.17.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@0.17.0) (2022-10-29)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- update default value format & handling ([c7752fb](https://github.com/thi-ng/umbrella/commit/c7752fb))
|
|
17
|
+
- update Field.default to support lang-specific alts
|
|
18
|
+
- add defaultValue() helper
|
|
19
|
+
- update zig codegen
|
|
20
|
+
|
|
21
|
+
#### 🩹 Bug fixes
|
|
22
|
+
|
|
23
|
+
- fix idempotence checks for self-referential types ([2c3f670](https://github.com/thi-ng/umbrella/commit/2c3f670))
|
|
24
|
+
- update prepareType()
|
|
25
|
+
|
|
12
26
|
## [0.16.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@0.16.0) (2022-10-28)
|
|
13
27
|
|
|
14
28
|
#### 🚀 Features
|
package/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BigType, FloatType, Fn, Fn2, IDeref, ILength, IObjectOf } from "@thi.ng/api";
|
|
1
|
+
import type { BigType, FloatType, Fn, Fn2, IDeref, ILength, IObjectOf, NumOrString } from "@thi.ng/api";
|
|
2
2
|
import type { Pow2 } from "@thi.ng/binary";
|
|
3
3
|
import type { WasmBridge } from "./bridge.js";
|
|
4
4
|
export declare const PKG_NAME = "@thi.ng/wasm-api";
|
|
@@ -224,7 +224,7 @@ export declare type WasmPrim32 = Exclude<WasmPrim, BigType>;
|
|
|
224
224
|
export declare type ReadonlyWasmString = IDeref<string> & ILength & {
|
|
225
225
|
readonly addr: number;
|
|
226
226
|
};
|
|
227
|
-
export declare type TypeColl =
|
|
227
|
+
export declare type TypeColl = IObjectOf<TopLevelType>;
|
|
228
228
|
export interface TypeInfo {
|
|
229
229
|
/**
|
|
230
230
|
* Auto-computed size (in bytes)
|
|
@@ -370,10 +370,14 @@ export interface Field extends TypeInfo {
|
|
|
370
370
|
*/
|
|
371
371
|
len?: number;
|
|
372
372
|
/**
|
|
373
|
-
* Currently only supported for {@link ZIG}
|
|
374
|
-
*
|
|
373
|
+
* Currently only supported for {@link ZIG}, otherwise ignored!
|
|
374
|
+
*
|
|
375
|
+
* @remarks
|
|
376
|
+
* The object form allows for different default values per language (in
|
|
377
|
+
* theory). So if given as object, the keys refer to the lang ID and the
|
|
378
|
+
* values as the defaults for those languages.
|
|
375
379
|
*/
|
|
376
|
-
default?:
|
|
380
|
+
default?: NumOrString | IObjectOf<NumOrString>;
|
|
377
381
|
/**
|
|
378
382
|
* If defined and > 0, the field will be considered for padding purposes
|
|
379
383
|
* only and the value provided is the number of bytes used. All other config
|
package/codegen/utils.d.ts
CHANGED
|
@@ -59,6 +59,14 @@ export declare const stringFields: (fields: Field[]) => Field[];
|
|
|
59
59
|
* @internal
|
|
60
60
|
*/
|
|
61
61
|
export declare const enumName: (opts: CodeGenOpts, name: string) => string;
|
|
62
|
+
/**
|
|
63
|
+
* Returns given field's default value (or undefined). The `lang` ID is required
|
|
64
|
+
* to obtain the language specific value if the default is given as object.
|
|
65
|
+
*
|
|
66
|
+
* @param f
|
|
67
|
+
* @param lang
|
|
68
|
+
*/
|
|
69
|
+
export declare const defaultValue: (f: Field, lang: string) => import("@thi.ng/api").NumOrString | undefined;
|
|
62
70
|
/**
|
|
63
71
|
* Takes an array of strings or splits given string into lines, word wraps and
|
|
64
72
|
* then prefixes each line with given `width` and `prefix`. Returns array of new
|
package/codegen/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isArray } from "@thi.ng/checks/is-array";
|
|
2
|
+
import { isPlainObject } from "@thi.ng/checks/is-plain-object";
|
|
2
3
|
import { isString } from "@thi.ng/checks/is-string";
|
|
3
4
|
import { split } from "@thi.ng/strings/split";
|
|
4
5
|
import { wordWrapLine, wordWrapLines } from "@thi.ng/strings/word-wrap";
|
|
@@ -61,6 +62,18 @@ export const stringFields = (fields) => fields.filter((f) => isWasmString(f.type
|
|
|
61
62
|
* @internal
|
|
62
63
|
*/
|
|
63
64
|
export const enumName = (opts, name) => opts.uppercaseEnums ? name.toUpperCase() : name;
|
|
65
|
+
/**
|
|
66
|
+
* Returns given field's default value (or undefined). The `lang` ID is required
|
|
67
|
+
* to obtain the language specific value if the default is given as object.
|
|
68
|
+
*
|
|
69
|
+
* @param f
|
|
70
|
+
* @param lang
|
|
71
|
+
*/
|
|
72
|
+
export const defaultValue = (f, lang) => f.default !== undefined
|
|
73
|
+
? isPlainObject(f.default)
|
|
74
|
+
? f.default[lang]
|
|
75
|
+
: f.default
|
|
76
|
+
: undefined;
|
|
64
77
|
/**
|
|
65
78
|
* Takes an array of strings or splits given string into lines, word wraps and
|
|
66
79
|
* then prefixes each line with given `width` and `prefix`. Returns array of new
|
package/codegen/zig.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isNumber } from "@thi.ng/checks
|
|
1
|
+
import { isNumber } from "@thi.ng/checks";
|
|
2
2
|
import { isString } from "@thi.ng/checks/is-string";
|
|
3
3
|
import { unsupported } from "@thi.ng/errors/unsupported";
|
|
4
|
-
import { ensureLines, enumName, isPadding, isStringSlice, isWasmString, prefixLines, withIndentation, } from "./utils.js";
|
|
4
|
+
import { defaultValue, ensureLines, enumName, isPadding, isStringSlice, isWasmString, prefixLines, withIndentation, } from "./utils.js";
|
|
5
5
|
/**
|
|
6
6
|
* Zig code generator. Call with options and then pass to {@link generateTypes}
|
|
7
7
|
* (see its docs for further usage).
|
|
@@ -109,7 +109,7 @@ export const fieldType = (parent, f, opts) => {
|
|
|
109
109
|
? "[*:0]const u8"
|
|
110
110
|
: "[*:0]u8"
|
|
111
111
|
: f.type;
|
|
112
|
-
let defaultVal = "";
|
|
112
|
+
let defaultVal = defaultValue(f, "zig");
|
|
113
113
|
switch (f.tag) {
|
|
114
114
|
case "array":
|
|
115
115
|
type =
|
|
@@ -128,14 +128,16 @@ export const fieldType = (parent, f, opts) => {
|
|
|
128
128
|
break;
|
|
129
129
|
case "scalar":
|
|
130
130
|
default:
|
|
131
|
-
if (
|
|
132
|
-
if (!(isString(
|
|
133
|
-
unsupported(`wrong default value for ${parent.name}.${f.name} (${
|
|
131
|
+
if (defaultVal != undefined) {
|
|
132
|
+
if (!(isString(defaultVal) || isNumber(defaultVal))) {
|
|
133
|
+
unsupported(`wrong default value for ${parent.name}.${f.name} (${defaultVal})`);
|
|
134
134
|
}
|
|
135
|
-
defaultVal = ` = ${JSON.stringify(f.default)}`;
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
|
-
return {
|
|
137
|
+
return {
|
|
138
|
+
type,
|
|
139
|
+
defaultVal: defaultVal != undefined ? ` = ${defaultVal}` : "",
|
|
140
|
+
};
|
|
139
141
|
};
|
|
140
142
|
const __packedPadding = (id, n, res) => {
|
|
141
143
|
let i = 0;
|
package/codegen.js
CHANGED
|
@@ -113,13 +113,13 @@ const alignOf = defmulti((x) => x.type, {}, {
|
|
|
113
113
|
});
|
|
114
114
|
const prepareType = defmulti((x) => x.type, {}, {
|
|
115
115
|
[DEFAULT]: (x, types, alignImpl, opts) => {
|
|
116
|
-
if (x.__align
|
|
116
|
+
if (x.__align)
|
|
117
117
|
return;
|
|
118
118
|
alignOf(x, types, alignImpl, opts);
|
|
119
119
|
sizeOf(x, types, alignImpl, opts);
|
|
120
120
|
},
|
|
121
121
|
struct: (x, types, align, opts) => {
|
|
122
|
-
if (x.__align
|
|
122
|
+
if (x.__align)
|
|
123
123
|
return;
|
|
124
124
|
const struct = x;
|
|
125
125
|
alignOf(struct, types, align, opts);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/wasm-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Generic, modular, extensible API bridge, polyglot glue code and bindings code generators for hybrid JS & WebAssembly projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -141,5 +141,5 @@
|
|
|
141
141
|
"status": "alpha",
|
|
142
142
|
"year": 2022
|
|
143
143
|
},
|
|
144
|
-
"gitHead": "
|
|
144
|
+
"gitHead": "0402675247b1c312e4dd3d9bc6c01af5cc837c5d\n"
|
|
145
145
|
}
|