@openedges/pkl-napi 0.32.0-rc.3 → 0.32.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/NOTICE +4 -4
- package/README.md +13 -9
- package/THIRD-PARTY-NOTICES.md +24 -8
- package/dist/index.cjs +586 -273
- package/dist/index.d.cts +547 -0
- package/dist/index.d.mts +575 -0
- package/dist/index.d.ts +38 -25
- package/dist/index.mjs +0 -5
- package/dist/testing.cjs +114 -0
- package/dist/testing.d.cts +29 -0
- package/dist/testing.d.mts +38 -0
- package/dist/testing.d.ts +29 -0
- package/dist/testing.mjs +14 -0
- package/native/pkl_napi.darwin-arm64.node +0 -0
- package/native/pkl_napi.darwin-x64.node +0 -0
- package/native/pkl_napi.linux-arm64-gnu.node +0 -0
- package/native/pkl_napi.linux-arm64-musl.node +0 -0
- package/native/pkl_napi.linux-x64-gnu.node +0 -0
- package/native/pkl_napi.linux-x64-musl.node +0 -0
- package/native/pkl_napi.win32-x64.node +0 -0
- package/package.json +20 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const PKL_VERSION: "0.32.
|
|
1
|
+
export const PKL_VERSION: "0.32.1";
|
|
2
2
|
|
|
3
3
|
export interface PklCapabilities {
|
|
4
4
|
vfs: boolean;
|
|
@@ -37,6 +37,7 @@ export type PklErrorKind =
|
|
|
37
37
|
| "capability-unavailable";
|
|
38
38
|
|
|
39
39
|
export class PklError extends Error {
|
|
40
|
+
readonly name: "PklError";
|
|
40
41
|
readonly kind: PklErrorKind;
|
|
41
42
|
readonly code: PklErrorKind;
|
|
42
43
|
readonly capability?: keyof PklCapabilities;
|
|
@@ -86,9 +87,16 @@ export class PklObject {
|
|
|
86
87
|
className: string,
|
|
87
88
|
moduleUri: string,
|
|
88
89
|
properties?: Record<string, PklValue>,
|
|
89
|
-
entries?: Map<PklValue, PklValue>,
|
|
90
|
-
elements?: PklValue
|
|
90
|
+
entries?: Map<PklValue, PklValue> | Iterable<[PklValue, PklValue]>,
|
|
91
|
+
elements?: Iterable<PklValue>,
|
|
91
92
|
);
|
|
93
|
+
toJSON(): {
|
|
94
|
+
className: string;
|
|
95
|
+
moduleUri: string;
|
|
96
|
+
properties: Record<string, PklValue>;
|
|
97
|
+
entries: [PklValue, PklValue][];
|
|
98
|
+
elements: PklValue[];
|
|
99
|
+
};
|
|
92
100
|
}
|
|
93
101
|
|
|
94
102
|
export class PklClass {
|
|
@@ -162,8 +170,11 @@ export interface ModuleReader {
|
|
|
162
170
|
isLocal?: boolean;
|
|
163
171
|
isGlobbable?: boolean;
|
|
164
172
|
hasHierarchicalUris?: boolean;
|
|
173
|
+
hasFragmentPaths?: boolean;
|
|
165
174
|
isCached?: boolean;
|
|
166
|
-
read(
|
|
175
|
+
read(
|
|
176
|
+
uri: string,
|
|
177
|
+
): string | Uint8Array | null | undefined | Promise<string | Uint8Array | null | undefined>;
|
|
167
178
|
listElements?(uri: string): PathElement[] | Promise<PathElement[]>;
|
|
168
179
|
hasElement?(uri: string): boolean | Promise<boolean>;
|
|
169
180
|
}
|
|
@@ -244,6 +255,7 @@ export interface TestOptions extends CallOptions {
|
|
|
244
255
|
overwrite?: boolean;
|
|
245
256
|
reporter?: "spec" | "minimal" | "junit";
|
|
246
257
|
}
|
|
258
|
+
export type EvaluateTestOptions = TestOptions;
|
|
247
259
|
|
|
248
260
|
export interface SourceLocation {
|
|
249
261
|
startLine: number;
|
|
@@ -294,6 +306,7 @@ export interface PClassProperty {
|
|
|
294
306
|
annotations: PklObject[];
|
|
295
307
|
type: PType;
|
|
296
308
|
}
|
|
309
|
+
export type PPropertySchema = PClassProperty;
|
|
297
310
|
|
|
298
311
|
export interface PClassMethod {
|
|
299
312
|
name: string;
|
|
@@ -307,8 +320,10 @@ export interface PClassMethod {
|
|
|
307
320
|
parameters: Record<string, PType>;
|
|
308
321
|
returnType: PType;
|
|
309
322
|
}
|
|
323
|
+
export type PMethodSchema = PClassMethod;
|
|
310
324
|
|
|
311
325
|
export interface PClassSchema extends PClassInfo {
|
|
326
|
+
info: PClassInfo;
|
|
312
327
|
docComment: string | null;
|
|
313
328
|
sourceLocation: SourceLocation;
|
|
314
329
|
modifiers: string[];
|
|
@@ -323,6 +338,7 @@ export interface PClassSchema extends PClassInfo {
|
|
|
323
338
|
}
|
|
324
339
|
|
|
325
340
|
export interface TypeAliasSchema extends TypeAliasInfo {
|
|
341
|
+
info: TypeAliasInfo;
|
|
326
342
|
docComment: string | null;
|
|
327
343
|
sourceLocation: SourceLocation;
|
|
328
344
|
modifiers: string[];
|
|
@@ -330,6 +346,7 @@ export interface TypeAliasSchema extends TypeAliasInfo {
|
|
|
330
346
|
typeParameters: TypeParameter[];
|
|
331
347
|
aliasedType: PType;
|
|
332
348
|
}
|
|
349
|
+
export type PTypeAliasSchema = TypeAliasSchema;
|
|
333
350
|
|
|
334
351
|
export interface ModuleSchema {
|
|
335
352
|
moduleUri: string;
|
|
@@ -447,6 +464,7 @@ export class Project {
|
|
|
447
464
|
}
|
|
448
465
|
|
|
449
466
|
export class Evaluator {
|
|
467
|
+
private constructor();
|
|
450
468
|
readonly isClosed: boolean;
|
|
451
469
|
evaluateOutputText(source: ModuleSource, options?: CallOptions): Promise<string>;
|
|
452
470
|
evaluateOutputTextSync(source: ModuleSource, options?: CallOptions): string;
|
|
@@ -486,17 +504,29 @@ export function createEvaluator(options?: EvaluatorOptions): Promise<Evaluator>;
|
|
|
486
504
|
export function createEvaluatorSync(options?: EvaluatorOptions): Evaluator;
|
|
487
505
|
|
|
488
506
|
export interface ReplResponse {
|
|
489
|
-
kind:
|
|
507
|
+
kind:
|
|
508
|
+
| "evalSuccess"
|
|
509
|
+
| "evalError"
|
|
510
|
+
| "incompleteInput"
|
|
511
|
+
| "invalidRequest"
|
|
512
|
+
| "internalError"
|
|
513
|
+
| "completion";
|
|
490
514
|
result?: string;
|
|
491
515
|
message?: string;
|
|
516
|
+
members?: string[];
|
|
492
517
|
}
|
|
493
518
|
|
|
494
519
|
export class ReplSession {
|
|
520
|
+
private constructor();
|
|
495
521
|
readonly isClosed: boolean;
|
|
496
|
-
eval(
|
|
522
|
+
eval(
|
|
523
|
+
input: string,
|
|
524
|
+
options?: { force?: boolean; evalDefinitions?: boolean; id?: string },
|
|
525
|
+
): Promise<ReplResponse[]>;
|
|
497
526
|
load(uriOrSource: string | ModuleSource, options?: { id?: string }): Promise<ReplResponse[]>;
|
|
498
527
|
reset(options?: { id?: string }): Promise<void>;
|
|
499
528
|
complete(prefix: string, options?: { id?: string }): Promise<string[]>;
|
|
529
|
+
cancel(): void;
|
|
500
530
|
close(): Promise<void>;
|
|
501
531
|
}
|
|
502
532
|
|
|
@@ -512,23 +542,6 @@ export function analyzeImportGraph(
|
|
|
512
542
|
options?: EvaluatorOptions,
|
|
513
543
|
): Promise<ImportGraph>;
|
|
514
544
|
|
|
515
|
-
export function format(source: string, options?: { grammarVersion?: 1 | 2 }): string;
|
|
516
|
-
export function decodePklBinary(bytes: Uint8Array): PklValue;
|
|
545
|
+
export function format(source: string, options?: { grammarVersion?: 1 | 2 | null }): string;
|
|
546
|
+
export function decodePklBinary(bytes: Uint8Array, options?: { strict?: boolean }): PklValue;
|
|
517
547
|
export function monotonicClockMs(): bigint;
|
|
518
|
-
|
|
519
|
-
export function roundtripValue<T extends PklValue>(val: T): PklValue;
|
|
520
|
-
export function roundtripInteger(val: bigint): bigint;
|
|
521
|
-
export function roundtripBytes(val: Uint8Array): Uint8Array;
|
|
522
|
-
export function roundtripString(val: string): string;
|
|
523
|
-
|
|
524
|
-
export interface ConversionBenchmarkResult {
|
|
525
|
-
iterations: number;
|
|
526
|
-
elapsedMs: number;
|
|
527
|
-
nativeElapsedMs: number;
|
|
528
|
-
perIterationUs: number;
|
|
529
|
-
nativePerIterationUs: number;
|
|
530
|
-
lastValue: PklValue;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
export function measureConversion(iterations?: number): ConversionBenchmarkResult;
|
|
534
|
-
export function measureConversion(value: PklValue, iterations?: number): ConversionBenchmarkResult;
|
package/dist/index.mjs
CHANGED
package/dist/testing.cjs
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const pkg = require("./index.cjs");
|
|
4
|
+
|
|
5
|
+
const TESTING_INTERNALS = Symbol.for("@openedges/pkl-napi/testing-internals");
|
|
6
|
+
const internals = pkg[TESTING_INTERNALS];
|
|
7
|
+
if (!internals) {
|
|
8
|
+
throw new Error("Missing @openedges/pkl-napi testing internals");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const { native, unwrapOutcome, dehydrateValue, hydrateValue } = internals;
|
|
12
|
+
const { PklError, PklObject, PklDuration, PklDataSize, PklPair } = pkg;
|
|
13
|
+
|
|
14
|
+
const MIN_I64 = -(1n << 63n);
|
|
15
|
+
const MAX_I64 = (1n << 63n) - 1n;
|
|
16
|
+
|
|
17
|
+
function roundtripValue(val) {
|
|
18
|
+
const dehydrated = dehydrateValue(val);
|
|
19
|
+
const raw = unwrapOutcome(native.productRoundtripValue(dehydrated));
|
|
20
|
+
return hydrateValue(raw);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function roundtripInteger(val) {
|
|
24
|
+
if (typeof val !== "bigint") {
|
|
25
|
+
throw new PklError("roundtripInteger expects a BigInt.", "invalid-argument");
|
|
26
|
+
}
|
|
27
|
+
return unwrapOutcome(native.productRoundtripInteger(val));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function roundtripBytes(val) {
|
|
31
|
+
if (!(val instanceof Uint8Array)) {
|
|
32
|
+
throw new PklError("roundtripBytes expects a Uint8Array.", "invalid-argument");
|
|
33
|
+
}
|
|
34
|
+
return native.roundtripBytes(new Uint8Array(val.buffer, val.byteOffset, val.byteLength));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function roundtripString(val) {
|
|
38
|
+
if (typeof val !== "string") {
|
|
39
|
+
throw new PklError("roundtripString expects a string.", "invalid-argument");
|
|
40
|
+
}
|
|
41
|
+
return native.roundtripString(val);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function defaultBenchmarkPayload() {
|
|
45
|
+
return new PklObject(
|
|
46
|
+
"Bench#Payload",
|
|
47
|
+
"repl:bench",
|
|
48
|
+
{
|
|
49
|
+
intMin: MIN_I64,
|
|
50
|
+
intMax: MAX_I64,
|
|
51
|
+
floatVal: 3.141592653589793,
|
|
52
|
+
text: "hello-pkl-🚀-utf16",
|
|
53
|
+
bytes: new Uint8Array([0, 1, 2, 127, 128, 255]),
|
|
54
|
+
duration: new PklDuration(5, "s"),
|
|
55
|
+
dataSize: new PklDataSize(16, "mib"),
|
|
56
|
+
pair: new PklPair("left", 42n),
|
|
57
|
+
list: [1n, 2n, 3n, true, null],
|
|
58
|
+
set: new Set(["a", "b", "c"]),
|
|
59
|
+
map: new Map([
|
|
60
|
+
["k1", 100n],
|
|
61
|
+
["k2", "v2"],
|
|
62
|
+
]),
|
|
63
|
+
},
|
|
64
|
+
new Map(),
|
|
65
|
+
[],
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function measureConversion(valOrIterations = 1000, maybeSecond = undefined) {
|
|
70
|
+
let value;
|
|
71
|
+
let iterations;
|
|
72
|
+
if (
|
|
73
|
+
typeof valOrIterations === "number" &&
|
|
74
|
+
(maybeSecond === undefined || Number.isInteger(valOrIterations))
|
|
75
|
+
) {
|
|
76
|
+
iterations = valOrIterations;
|
|
77
|
+
value = maybeSecond !== undefined ? maybeSecond : defaultBenchmarkPayload();
|
|
78
|
+
} else {
|
|
79
|
+
value = valOrIterations;
|
|
80
|
+
iterations = maybeSecond === undefined ? 1000 : maybeSecond;
|
|
81
|
+
}
|
|
82
|
+
if (!Number.isInteger(iterations) || iterations < 1 || iterations > 1_000_000) {
|
|
83
|
+
throw new PklError(
|
|
84
|
+
`iterations must be an integer between 1 and 1000000, got ${iterations}.`,
|
|
85
|
+
"invalid-argument",
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const dehydrated = dehydrateValue(value);
|
|
89
|
+
const startNs = process.hrtime.bigint();
|
|
90
|
+
const nativeStats = unwrapOutcome(native.productMeasureConversion(dehydrated, iterations));
|
|
91
|
+
const hydrated = hydrateValue(nativeStats.lastValue);
|
|
92
|
+
const totalElapsedMs = Number(process.hrtime.bigint() - startNs) / 1e6;
|
|
93
|
+
const perIterationUs = (totalElapsedMs * 1000) / nativeStats.iterations;
|
|
94
|
+
return {
|
|
95
|
+
iterations: nativeStats.iterations,
|
|
96
|
+
totalMs: totalElapsedMs,
|
|
97
|
+
elapsedMs: totalElapsedMs,
|
|
98
|
+
nativeElapsedMs: nativeStats.elapsedMs,
|
|
99
|
+
avgUs: perIterationUs,
|
|
100
|
+
perIterationUs,
|
|
101
|
+
nativePerIterationUs: nativeStats.perIterationUs,
|
|
102
|
+
opsPerSec: totalElapsedMs > 0 ? (nativeStats.iterations * 1000) / totalElapsedMs : Infinity,
|
|
103
|
+
sample: hydrated,
|
|
104
|
+
lastValue: hydrated,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
module.exports = {
|
|
109
|
+
roundtripValue,
|
|
110
|
+
roundtripInteger,
|
|
111
|
+
roundtripBytes,
|
|
112
|
+
roundtripString,
|
|
113
|
+
measureConversion,
|
|
114
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PklValue } from "./index.cjs";
|
|
2
|
+
|
|
3
|
+
export function roundtripValue<T extends PklValue>(val: T): PklValue;
|
|
4
|
+
export function roundtripInteger(val: bigint): bigint;
|
|
5
|
+
export function roundtripBytes(val: Uint8Array): Uint8Array;
|
|
6
|
+
export function roundtripString(val: string): string;
|
|
7
|
+
|
|
8
|
+
export interface ConversionBenchmarkResult {
|
|
9
|
+
iterations: number;
|
|
10
|
+
totalMs: number;
|
|
11
|
+
elapsedMs: number;
|
|
12
|
+
nativeElapsedMs: number;
|
|
13
|
+
avgUs: number;
|
|
14
|
+
perIterationUs: number;
|
|
15
|
+
nativePerIterationUs: number;
|
|
16
|
+
opsPerSec: number;
|
|
17
|
+
sample: PklValue;
|
|
18
|
+
lastValue: PklValue;
|
|
19
|
+
}
|
|
20
|
+
export type ConversionTelemetry = ConversionBenchmarkResult;
|
|
21
|
+
|
|
22
|
+
export function measureConversion(
|
|
23
|
+
iterations?: number,
|
|
24
|
+
sampleValue?: PklValue,
|
|
25
|
+
): ConversionBenchmarkResult;
|
|
26
|
+
export function measureConversion(
|
|
27
|
+
value: PklValue,
|
|
28
|
+
iterations?: number,
|
|
29
|
+
): ConversionBenchmarkResult;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { PklValue } from "./index.mjs";
|
|
2
|
+
|
|
3
|
+
export function roundtripValue<T extends PklValue>(val: T): PklValue;
|
|
4
|
+
export function roundtripInteger(val: bigint): bigint;
|
|
5
|
+
export function roundtripBytes(val: Uint8Array): Uint8Array;
|
|
6
|
+
export function roundtripString(val: string): string;
|
|
7
|
+
|
|
8
|
+
export interface ConversionBenchmarkResult {
|
|
9
|
+
iterations: number;
|
|
10
|
+
totalMs: number;
|
|
11
|
+
elapsedMs: number;
|
|
12
|
+
nativeElapsedMs: number;
|
|
13
|
+
avgUs: number;
|
|
14
|
+
perIterationUs: number;
|
|
15
|
+
nativePerIterationUs: number;
|
|
16
|
+
opsPerSec: number;
|
|
17
|
+
sample: PklValue;
|
|
18
|
+
lastValue: PklValue;
|
|
19
|
+
}
|
|
20
|
+
export type ConversionTelemetry = ConversionBenchmarkResult;
|
|
21
|
+
|
|
22
|
+
export function measureConversion(
|
|
23
|
+
iterations?: number,
|
|
24
|
+
sampleValue?: PklValue,
|
|
25
|
+
): ConversionBenchmarkResult;
|
|
26
|
+
export function measureConversion(
|
|
27
|
+
value: PklValue,
|
|
28
|
+
iterations?: number,
|
|
29
|
+
): ConversionBenchmarkResult;
|
|
30
|
+
|
|
31
|
+
declare const _testingDefault: {
|
|
32
|
+
roundtripValue: typeof roundtripValue;
|
|
33
|
+
roundtripInteger: typeof roundtripInteger;
|
|
34
|
+
roundtripBytes: typeof roundtripBytes;
|
|
35
|
+
roundtripString: typeof roundtripString;
|
|
36
|
+
measureConversion: typeof measureConversion;
|
|
37
|
+
};
|
|
38
|
+
export default _testingDefault;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PklValue } from "./index";
|
|
2
|
+
|
|
3
|
+
export function roundtripValue<T extends PklValue>(val: T): PklValue;
|
|
4
|
+
export function roundtripInteger(val: bigint): bigint;
|
|
5
|
+
export function roundtripBytes(val: Uint8Array): Uint8Array;
|
|
6
|
+
export function roundtripString(val: string): string;
|
|
7
|
+
|
|
8
|
+
export interface ConversionBenchmarkResult {
|
|
9
|
+
iterations: number;
|
|
10
|
+
totalMs: number;
|
|
11
|
+
elapsedMs: number;
|
|
12
|
+
nativeElapsedMs: number;
|
|
13
|
+
avgUs: number;
|
|
14
|
+
perIterationUs: number;
|
|
15
|
+
nativePerIterationUs: number;
|
|
16
|
+
opsPerSec: number;
|
|
17
|
+
sample: PklValue;
|
|
18
|
+
lastValue: PklValue;
|
|
19
|
+
}
|
|
20
|
+
export type ConversionTelemetry = ConversionBenchmarkResult;
|
|
21
|
+
|
|
22
|
+
export function measureConversion(
|
|
23
|
+
iterations?: number,
|
|
24
|
+
sampleValue?: PklValue,
|
|
25
|
+
): ConversionBenchmarkResult;
|
|
26
|
+
export function measureConversion(
|
|
27
|
+
value: PklValue,
|
|
28
|
+
iterations?: number,
|
|
29
|
+
): ConversionBenchmarkResult;
|
package/dist/testing.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
const testing = require("./testing.cjs");
|
|
5
|
+
|
|
6
|
+
export const {
|
|
7
|
+
roundtripValue,
|
|
8
|
+
roundtripInteger,
|
|
9
|
+
roundtripBytes,
|
|
10
|
+
roundtripString,
|
|
11
|
+
measureConversion,
|
|
12
|
+
} = testing;
|
|
13
|
+
|
|
14
|
+
export default testing;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openedges/pkl-napi",
|
|
3
|
-
"version": "0.32.
|
|
4
|
-
"description": "Node.js N-API bindings for the shared pure-Rust Apple Pkl 0.32.
|
|
3
|
+
"version": "0.32.1",
|
|
4
|
+
"description": "Node.js N-API bindings for the shared pure-Rust Apple Pkl 0.32.1 engine",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -17,9 +17,24 @@
|
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./dist/index.d.mts",
|
|
22
|
+
"default": "./dist/index.mjs"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./dist/index.d.cts",
|
|
26
|
+
"default": "./dist/index.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"./testing": {
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/testing.d.mts",
|
|
32
|
+
"default": "./dist/testing.mjs"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/testing.d.cts",
|
|
36
|
+
"default": "./dist/testing.cjs"
|
|
37
|
+
}
|
|
23
38
|
}
|
|
24
39
|
},
|
|
25
40
|
"files": [
|