fastdb4ts 0.0.2 → 0.2.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/README.md +69 -19
- package/dist/LICENSE +21 -0
- package/dist/THIRD_PARTY_NOTICES.txt +1958 -0
- package/dist/column.d.ts +1 -0
- package/dist/column.js +35 -1
- package/dist/database-buffer.d.ts +20 -0
- package/dist/database-buffer.js +101 -0
- package/dist/feature.d.ts +1 -1
- package/dist/feature.js +47 -5
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/orm.d.ts +4 -2
- package/dist/orm.js +128 -33
- package/dist/payload/abi.d.ts +27 -0
- package/dist/payload/abi.js +160 -0
- package/dist/payload/builder.d.ts +98 -0
- package/dist/payload/builder.js +364 -0
- package/dist/payload/codegen.d.ts +43 -0
- package/dist/payload/codegen.js +182 -0
- package/dist/payload/error.d.ts +9 -0
- package/dist/payload/error.js +53 -0
- package/dist/payload/index.d.ts +9 -0
- package/dist/payload/index.js +9 -0
- package/dist/payload/runtime.d.ts +195 -0
- package/dist/payload/runtime.js +756 -0
- package/dist/payload/spec.d.ts +44 -0
- package/dist/payload/spec.js +220 -0
- package/dist/schema.js +1 -0
- package/dist/serializer.d.ts +2 -1
- package/dist/serializer.js +5 -4
- package/dist/table.js +3 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.js +31 -0
- package/dist/wasm/fastdb4ts.js +1 -1
- package/dist/wasm/fastdb4ts.wasm +0 -0
- package/dist/wasm-loader.d.ts +146 -1
- package/package.json +6 -2
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { getInitializedFastdbModule, initFastdb, } from '../wasm-loader.js';
|
|
2
|
+
export const ABI_VERSION = 1;
|
|
3
|
+
export const SHA256_SIZE = 32;
|
|
4
|
+
export const CAPABILITIES_SIZE = 72;
|
|
5
|
+
export const POINTER_SIZE = 4;
|
|
6
|
+
export const U64_MAX = 0xffffffffffffffffn;
|
|
7
|
+
export async function initPayloadModule() {
|
|
8
|
+
const module = await initFastdb();
|
|
9
|
+
assertAbiVersion(module);
|
|
10
|
+
return module;
|
|
11
|
+
}
|
|
12
|
+
export function payloadModule() {
|
|
13
|
+
const module = getInitializedFastdbModule();
|
|
14
|
+
assertAbiVersion(module);
|
|
15
|
+
return module;
|
|
16
|
+
}
|
|
17
|
+
function assertAbiVersion(module) {
|
|
18
|
+
const actual = module._fdb_payload_v1_abi_version();
|
|
19
|
+
if (actual !== ABI_VERSION) {
|
|
20
|
+
throw new Error(`FastDB payload ABI mismatch: expected ${ABI_VERSION}, received ${actual}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function allocate(module, size) {
|
|
24
|
+
if (!Number.isSafeInteger(size) || size <= 0) {
|
|
25
|
+
throw new RangeError(`invalid Wasm allocation size: ${size}`);
|
|
26
|
+
}
|
|
27
|
+
const pointer = module._malloc(size);
|
|
28
|
+
if (pointer === 0) {
|
|
29
|
+
throw new Error(`FastDB Wasm allocation failed for ${size} bytes`);
|
|
30
|
+
}
|
|
31
|
+
module.HEAPU8.fill(0, pointer, pointer + size);
|
|
32
|
+
return pointer;
|
|
33
|
+
}
|
|
34
|
+
export function withAllocation(module, size, operation) {
|
|
35
|
+
const pointer = allocate(module, size);
|
|
36
|
+
try {
|
|
37
|
+
return operation(pointer);
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
module._free(pointer);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function withInputBytes(module, bytes, operation) {
|
|
44
|
+
if (bytes.byteLength === 0) {
|
|
45
|
+
return operation(0, 0n);
|
|
46
|
+
}
|
|
47
|
+
return withAllocation(module, bytes.byteLength, (pointer) => {
|
|
48
|
+
module.HEAPU8.set(bytes, pointer);
|
|
49
|
+
return operation(pointer, BigInt(bytes.byteLength));
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export function withSha256(module, digest, operation) {
|
|
53
|
+
if (!(digest instanceof Uint8Array) || digest.byteLength !== SHA256_SIZE) {
|
|
54
|
+
throw new RangeError(`expectedSha256 must contain ${SHA256_SIZE} bytes`);
|
|
55
|
+
}
|
|
56
|
+
return withInputBytes(module, digest, (pointer) => operation(pointer));
|
|
57
|
+
}
|
|
58
|
+
export function withInputU16(module, units, operation) {
|
|
59
|
+
if (units.length === 0) {
|
|
60
|
+
return operation(0, 0n);
|
|
61
|
+
}
|
|
62
|
+
return withAllocation(module, units.length * 2, (pointer) => {
|
|
63
|
+
const view = new DataView(module.HEAPU8.buffer);
|
|
64
|
+
for (let index = 0; index < units.length; index += 1) {
|
|
65
|
+
view.setUint16(pointer + index * 2, units[index], true);
|
|
66
|
+
}
|
|
67
|
+
return operation(pointer, BigInt(units.length));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export function readU32(module, pointer) {
|
|
71
|
+
return new DataView(module.HEAPU8.buffer).getUint32(pointer, true);
|
|
72
|
+
}
|
|
73
|
+
export function readU64(module, pointer) {
|
|
74
|
+
return new DataView(module.HEAPU8.buffer).getBigUint64(pointer, true);
|
|
75
|
+
}
|
|
76
|
+
export function writeU32(module, pointer, value) {
|
|
77
|
+
new DataView(module.HEAPU8.buffer).setUint32(pointer, value, true);
|
|
78
|
+
}
|
|
79
|
+
export function writeU64(module, pointer, value) {
|
|
80
|
+
new DataView(module.HEAPU8.buffer).setBigUint64(pointer, value, true);
|
|
81
|
+
}
|
|
82
|
+
export function copyBytes(module, pointer, size) {
|
|
83
|
+
if (size === 0n) {
|
|
84
|
+
return new Uint8Array();
|
|
85
|
+
}
|
|
86
|
+
if (pointer === 0) {
|
|
87
|
+
throw new Error('FastDB Core returned non-empty bytes with null storage');
|
|
88
|
+
}
|
|
89
|
+
if (size > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
90
|
+
throw new RangeError('FastDB byte span exceeds the JavaScript address space');
|
|
91
|
+
}
|
|
92
|
+
const numericSize = Number(size);
|
|
93
|
+
const end = pointer + numericSize;
|
|
94
|
+
if (!Number.isSafeInteger(end) || end > module.HEAPU8.byteLength) {
|
|
95
|
+
throw new RangeError('FastDB byte span exceeds the current Wasm memory');
|
|
96
|
+
}
|
|
97
|
+
return module.HEAPU8.slice(pointer, end);
|
|
98
|
+
}
|
|
99
|
+
export function checkedU32(value, name) {
|
|
100
|
+
if (!Number.isInteger(value) || value < 0 || value > 0xffff_ffff) {
|
|
101
|
+
throw new RangeError(`${name} must be an unsigned 32-bit integer`);
|
|
102
|
+
}
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
export function checkedU16(value, name) {
|
|
106
|
+
if (!Number.isInteger(value) || value < 0 || value > 0xffff) {
|
|
107
|
+
throw new RangeError(`${name} must be an unsigned 16-bit integer`);
|
|
108
|
+
}
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
export function checkedU8(value, name) {
|
|
112
|
+
if (!Number.isInteger(value) || value < 0 || value > 0xff) {
|
|
113
|
+
throw new RangeError(`${name} must be an unsigned 8-bit integer`);
|
|
114
|
+
}
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
export function checkedI32(value, name) {
|
|
118
|
+
if (!Number.isInteger(value) ||
|
|
119
|
+
value < -0x8000_0000 ||
|
|
120
|
+
value > 0x7fff_ffff) {
|
|
121
|
+
throw new RangeError(`${name} must be a signed 32-bit integer`);
|
|
122
|
+
}
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
export function checkedU64(value, name) {
|
|
126
|
+
if (typeof value !== 'bigint' || value < 0n || value > U64_MAX) {
|
|
127
|
+
throw new RangeError(`${name} must be an unsigned 64-bit bigint`);
|
|
128
|
+
}
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
export function f32Bits(value) {
|
|
132
|
+
if (typeof value !== 'number') {
|
|
133
|
+
throw new TypeError('value must be a number');
|
|
134
|
+
}
|
|
135
|
+
const storage = new ArrayBuffer(4);
|
|
136
|
+
const view = new DataView(storage);
|
|
137
|
+
view.setFloat32(0, value, true);
|
|
138
|
+
return view.getUint32(0, true);
|
|
139
|
+
}
|
|
140
|
+
export function f64Bits(value) {
|
|
141
|
+
if (typeof value !== 'number') {
|
|
142
|
+
throw new TypeError('value must be a number');
|
|
143
|
+
}
|
|
144
|
+
const storage = new ArrayBuffer(8);
|
|
145
|
+
const view = new DataView(storage);
|
|
146
|
+
view.setFloat64(0, value, true);
|
|
147
|
+
return view.getBigUint64(0, true);
|
|
148
|
+
}
|
|
149
|
+
export function f32FromBits(bits) {
|
|
150
|
+
const storage = new ArrayBuffer(4);
|
|
151
|
+
const view = new DataView(storage);
|
|
152
|
+
view.setUint32(0, bits, true);
|
|
153
|
+
return view.getFloat32(0, true);
|
|
154
|
+
}
|
|
155
|
+
export function f64FromBits(bits) {
|
|
156
|
+
const storage = new ArrayBuffer(8);
|
|
157
|
+
const view = new DataView(storage);
|
|
158
|
+
view.setBigUint64(0, bits, true);
|
|
159
|
+
return view.getFloat64(0, true);
|
|
160
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { CompiledSpec } from './spec.js';
|
|
2
|
+
import { type BuildPolicy, type BuildResult, type WasmMemoryBacking } from './runtime.js';
|
|
3
|
+
declare const handleConstructionToken: unique symbol;
|
|
4
|
+
declare const objectHandleValue: unique symbol;
|
|
5
|
+
declare const createObjectHandle: unique symbol;
|
|
6
|
+
declare const createBuildPlan: unique symbol;
|
|
7
|
+
declare const planHandleValue: unique symbol;
|
|
8
|
+
export interface BuilderOptions {
|
|
9
|
+
flags?: number;
|
|
10
|
+
maxValueNodes?: bigint;
|
|
11
|
+
maxListElements?: bigint;
|
|
12
|
+
maxTextBytes?: bigint;
|
|
13
|
+
maxOpaqueBytes?: bigint;
|
|
14
|
+
maxNestingDepth?: bigint;
|
|
15
|
+
maxTotalBuilderBytes?: bigint;
|
|
16
|
+
maxGraphObjects?: bigint;
|
|
17
|
+
}
|
|
18
|
+
export declare class FixedRun {
|
|
19
|
+
readonly data: Uint8Array;
|
|
20
|
+
readonly count: bigint;
|
|
21
|
+
readonly strideBytes: bigint;
|
|
22
|
+
readonly validity?: Uint8Array;
|
|
23
|
+
readonly validityBitOffset: bigint;
|
|
24
|
+
constructor(data: Uint8Array, count: bigint, strideBytes: bigint, validity?: Uint8Array, validityBitOffset?: bigint);
|
|
25
|
+
}
|
|
26
|
+
export declare class ObjectHandle {
|
|
27
|
+
#private;
|
|
28
|
+
private constructor();
|
|
29
|
+
static [createObjectHandle](raw: bigint, token: typeof handleConstructionToken): ObjectHandle;
|
|
30
|
+
/** @internal */
|
|
31
|
+
[objectHandleValue](): bigint;
|
|
32
|
+
}
|
|
33
|
+
export declare class PlanInfo {
|
|
34
|
+
readonly flags: number;
|
|
35
|
+
readonly totalBytes: bigint;
|
|
36
|
+
readonly regionCount: bigint;
|
|
37
|
+
readonly logicalValueCount: bigint;
|
|
38
|
+
readonly listElementCount: bigint;
|
|
39
|
+
readonly textBytes: bigint;
|
|
40
|
+
readonly opaqueBytes: bigint;
|
|
41
|
+
readonly validationWork: bigint;
|
|
42
|
+
readonly maxAlignment: number;
|
|
43
|
+
readonly directBuildStatus: number;
|
|
44
|
+
readonly graphObjectCount: bigint;
|
|
45
|
+
constructor(flags: number, totalBytes: bigint, regionCount: bigint, logicalValueCount: bigint, listElementCount: bigint, textBytes: bigint, opaqueBytes: bigint, validationWork: bigint, maxAlignment: number, directBuildStatus: number, graphObjectCount: bigint);
|
|
46
|
+
}
|
|
47
|
+
export declare class BuildPlan {
|
|
48
|
+
#private;
|
|
49
|
+
private constructor();
|
|
50
|
+
static [createBuildPlan](handle: number, token: typeof handleConstructionToken): BuildPlan;
|
|
51
|
+
clone(): BuildPlan;
|
|
52
|
+
dispose(): void;
|
|
53
|
+
info(): PlanInfo;
|
|
54
|
+
execute(policy: BuildPolicy, backing?: WasmMemoryBacking): BuildResult;
|
|
55
|
+
/** @internal */
|
|
56
|
+
[planHandleValue](): number;
|
|
57
|
+
private requireHandle;
|
|
58
|
+
}
|
|
59
|
+
export declare function buildPlanHandle(plan: BuildPlan): number;
|
|
60
|
+
export declare class Builder {
|
|
61
|
+
#private;
|
|
62
|
+
private constructor();
|
|
63
|
+
static create(spec: CompiledSpec, options?: BuilderOptions): Builder;
|
|
64
|
+
dispose(): void;
|
|
65
|
+
requireSpecSha256(expectedSha256: Uint8Array): void;
|
|
66
|
+
entryBegin(entryIndex: number, valueCount: bigint): Builder;
|
|
67
|
+
declareObject(componentIndex: number): ObjectHandle;
|
|
68
|
+
objectFillBegin(object: ObjectHandle): Builder;
|
|
69
|
+
valueNull(): Builder;
|
|
70
|
+
valueBool(value: boolean): Builder;
|
|
71
|
+
valueU8(value: number): Builder;
|
|
72
|
+
valueU16(value: number): Builder;
|
|
73
|
+
valueU32(value: number): Builder;
|
|
74
|
+
valueI32(value: number): Builder;
|
|
75
|
+
valueU8n(value: number): Builder;
|
|
76
|
+
valueU8nBits(bits: bigint): Builder;
|
|
77
|
+
valueU16n(value: number): Builder;
|
|
78
|
+
valueU16nBits(bits: bigint): Builder;
|
|
79
|
+
valueF32(value: number): Builder;
|
|
80
|
+
valueF32Bits(bits: number): Builder;
|
|
81
|
+
valueF64(value: number): Builder;
|
|
82
|
+
valueF64Bits(bits: bigint): Builder;
|
|
83
|
+
valueStr(value: string): Builder;
|
|
84
|
+
valueStrBytes(value: Uint8Array): Builder;
|
|
85
|
+
valueWstr(value: string): Builder;
|
|
86
|
+
valueWstrUnits(value: Uint16Array): Builder;
|
|
87
|
+
valueBytes(value: Uint8Array): Builder;
|
|
88
|
+
valueFixedRun(run: FixedRun): Builder;
|
|
89
|
+
valueComponentBegin(): Builder;
|
|
90
|
+
valueListBegin(itemCount: bigint): Builder;
|
|
91
|
+
valueObject(object: ObjectHandle): Builder;
|
|
92
|
+
valueRef(object: ObjectHandle): Builder;
|
|
93
|
+
freeze(): BuildPlan;
|
|
94
|
+
private call;
|
|
95
|
+
private callBytes;
|
|
96
|
+
private requireHandle;
|
|
97
|
+
}
|
|
98
|
+
export {};
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { POINTER_SIZE, checkedI32, checkedU8, checkedU16, checkedU32, checkedU64, f32Bits, f64Bits, payloadModule, readU32, readU64, withAllocation, withInputBytes, withInputU16, withSha256, writeU32, writeU64, } from './abi.js';
|
|
2
|
+
import { bindingError, checkStatus } from './error.js';
|
|
3
|
+
import { compiledSpecHandle } from './spec.js';
|
|
4
|
+
import { executePlan, } from './runtime.js';
|
|
5
|
+
const BUILDER_OPTIONS_SIZE = 96;
|
|
6
|
+
const FIXED_RUN_SIZE = 96;
|
|
7
|
+
const PLAN_INFO_SIZE = 112;
|
|
8
|
+
const encoder = new TextEncoder();
|
|
9
|
+
const handleConstructionToken = Symbol('fastdb.payload.handleConstructionToken');
|
|
10
|
+
const objectHandleValue = Symbol('fastdb.payload.objectHandleValue');
|
|
11
|
+
const createObjectHandle = Symbol('fastdb.payload.createObjectHandle');
|
|
12
|
+
const createBuildPlan = Symbol('fastdb.payload.createBuildPlan');
|
|
13
|
+
const planHandleValue = Symbol('fastdb.payload.planHandleValue');
|
|
14
|
+
export class FixedRun {
|
|
15
|
+
data;
|
|
16
|
+
count;
|
|
17
|
+
strideBytes;
|
|
18
|
+
validity;
|
|
19
|
+
validityBitOffset;
|
|
20
|
+
constructor(data, count, strideBytes, validity, validityBitOffset = 0n) {
|
|
21
|
+
this.data = data.slice();
|
|
22
|
+
this.count = checkedU64(count, 'count');
|
|
23
|
+
this.strideBytes = checkedU64(strideBytes, 'strideBytes');
|
|
24
|
+
this.validity = validity?.slice();
|
|
25
|
+
this.validityBitOffset = checkedU64(validityBitOffset, 'validityBitOffset');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class ObjectHandle {
|
|
29
|
+
#raw;
|
|
30
|
+
constructor(raw, token) {
|
|
31
|
+
if (token !== handleConstructionToken) {
|
|
32
|
+
throw new TypeError('ObjectHandle values are created only by FastDB');
|
|
33
|
+
}
|
|
34
|
+
this.#raw = raw;
|
|
35
|
+
}
|
|
36
|
+
static [createObjectHandle](raw, token) {
|
|
37
|
+
if (token !== handleConstructionToken) {
|
|
38
|
+
throw new TypeError('ObjectHandle values are created only by FastDB');
|
|
39
|
+
}
|
|
40
|
+
if (raw === 0n) {
|
|
41
|
+
throw bindingError('FastDB Core returned success without an object handle', 'missing_object_handle');
|
|
42
|
+
}
|
|
43
|
+
return new ObjectHandle(raw, handleConstructionToken);
|
|
44
|
+
}
|
|
45
|
+
/** @internal */
|
|
46
|
+
[objectHandleValue]() {
|
|
47
|
+
return this.#raw;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export class PlanInfo {
|
|
51
|
+
flags;
|
|
52
|
+
totalBytes;
|
|
53
|
+
regionCount;
|
|
54
|
+
logicalValueCount;
|
|
55
|
+
listElementCount;
|
|
56
|
+
textBytes;
|
|
57
|
+
opaqueBytes;
|
|
58
|
+
validationWork;
|
|
59
|
+
maxAlignment;
|
|
60
|
+
directBuildStatus;
|
|
61
|
+
graphObjectCount;
|
|
62
|
+
constructor(flags, totalBytes, regionCount, logicalValueCount, listElementCount, textBytes, opaqueBytes, validationWork, maxAlignment, directBuildStatus, graphObjectCount) {
|
|
63
|
+
this.flags = flags;
|
|
64
|
+
this.totalBytes = totalBytes;
|
|
65
|
+
this.regionCount = regionCount;
|
|
66
|
+
this.logicalValueCount = logicalValueCount;
|
|
67
|
+
this.listElementCount = listElementCount;
|
|
68
|
+
this.textBytes = textBytes;
|
|
69
|
+
this.opaqueBytes = opaqueBytes;
|
|
70
|
+
this.validationWork = validationWork;
|
|
71
|
+
this.maxAlignment = maxAlignment;
|
|
72
|
+
this.directBuildStatus = directBuildStatus;
|
|
73
|
+
this.graphObjectCount = graphObjectCount;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const planFinalizer = new FinalizationRegistry((handle) => {
|
|
77
|
+
try {
|
|
78
|
+
payloadModule()._fdb_payload_v1_plan_release(handle);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// Explicit disposal is authoritative; finalization is only a fallback.
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
export class BuildPlan {
|
|
85
|
+
#handle;
|
|
86
|
+
#finalizerToken = {};
|
|
87
|
+
constructor(handle, token) {
|
|
88
|
+
if (token !== handleConstructionToken) {
|
|
89
|
+
throw new TypeError('BuildPlan handles are created only by FastDB');
|
|
90
|
+
}
|
|
91
|
+
if (handle === 0) {
|
|
92
|
+
throw bindingError('FastDB Core returned success without a build plan', 'missing_plan_handle');
|
|
93
|
+
}
|
|
94
|
+
this.#handle = handle;
|
|
95
|
+
planFinalizer.register(this, handle, this.#finalizerToken);
|
|
96
|
+
}
|
|
97
|
+
static [createBuildPlan](handle, token) {
|
|
98
|
+
if (token !== handleConstructionToken) {
|
|
99
|
+
throw new TypeError('BuildPlan handles are created only by FastDB');
|
|
100
|
+
}
|
|
101
|
+
return new BuildPlan(handle, handleConstructionToken);
|
|
102
|
+
}
|
|
103
|
+
clone() {
|
|
104
|
+
const handle = this.requireHandle();
|
|
105
|
+
payloadModule()._fdb_payload_v1_plan_retain(handle);
|
|
106
|
+
return new BuildPlan(handle, handleConstructionToken);
|
|
107
|
+
}
|
|
108
|
+
dispose() {
|
|
109
|
+
if (this.#handle !== 0) {
|
|
110
|
+
const handle = this.#handle;
|
|
111
|
+
this.#handle = 0;
|
|
112
|
+
planFinalizer.unregister(this.#finalizerToken);
|
|
113
|
+
payloadModule()._fdb_payload_v1_plan_release(handle);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
info() {
|
|
117
|
+
const module = payloadModule();
|
|
118
|
+
return withAllocation(module, PLAN_INFO_SIZE + POINTER_SIZE, (outputs) => {
|
|
119
|
+
module._fdb_payload_v1_plan_info_init(outputs);
|
|
120
|
+
const status = module._fdb_payload_v1_plan_info(this.requireHandle(), outputs, outputs + PLAN_INFO_SIZE);
|
|
121
|
+
checkStatus(status, outputs + PLAN_INFO_SIZE);
|
|
122
|
+
return new PlanInfo(readU32(module, outputs + 4), readU64(module, outputs + 8), readU64(module, outputs + 16), readU64(module, outputs + 24), readU64(module, outputs + 32), readU64(module, outputs + 40), readU64(module, outputs + 48), readU64(module, outputs + 56), readU32(module, outputs + 64), readU32(module, outputs + 68), readU64(module, outputs + 104));
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
execute(policy, backing) {
|
|
126
|
+
return executePlan(this, policy, backing);
|
|
127
|
+
}
|
|
128
|
+
/** @internal */
|
|
129
|
+
[planHandleValue]() {
|
|
130
|
+
return this.requireHandle();
|
|
131
|
+
}
|
|
132
|
+
requireHandle() {
|
|
133
|
+
if (this.#handle === 0) {
|
|
134
|
+
throw bindingError('BuildPlan is disposed', 'disposed_handle');
|
|
135
|
+
}
|
|
136
|
+
return this.#handle;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export function buildPlanHandle(plan) {
|
|
140
|
+
if (!(plan instanceof BuildPlan)) {
|
|
141
|
+
throw new TypeError('plan must be BuildPlan');
|
|
142
|
+
}
|
|
143
|
+
return BuildPlan.prototype[planHandleValue].call(plan);
|
|
144
|
+
}
|
|
145
|
+
const builderFinalizer = new FinalizationRegistry((handle) => {
|
|
146
|
+
try {
|
|
147
|
+
payloadModule()._fdb_payload_v1_builder_release(handle);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
// Explicit disposal is authoritative; finalization is only a fallback.
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
export class Builder {
|
|
154
|
+
#handle;
|
|
155
|
+
#finalizerToken = {};
|
|
156
|
+
constructor(handle, token) {
|
|
157
|
+
if (token !== handleConstructionToken) {
|
|
158
|
+
throw new TypeError('Builder handles are created only by FastDB');
|
|
159
|
+
}
|
|
160
|
+
if (handle === 0) {
|
|
161
|
+
throw bindingError('FastDB Core returned success without a builder', 'missing_builder_handle');
|
|
162
|
+
}
|
|
163
|
+
this.#handle = handle;
|
|
164
|
+
builderFinalizer.register(this, handle, this.#finalizerToken);
|
|
165
|
+
}
|
|
166
|
+
static create(spec, options) {
|
|
167
|
+
const module = payloadModule();
|
|
168
|
+
return withAllocation(module, POINTER_SIZE * 2, (outputs) => {
|
|
169
|
+
const invoke = (optionsPointer) => {
|
|
170
|
+
const status = module._fdb_payload_v1_builder_create(compiledSpecHandle(spec), optionsPointer, outputs, outputs + POINTER_SIZE);
|
|
171
|
+
checkStatus(status, outputs + POINTER_SIZE);
|
|
172
|
+
return new Builder(readU32(module, outputs), handleConstructionToken);
|
|
173
|
+
};
|
|
174
|
+
if (options === undefined) {
|
|
175
|
+
return invoke(0);
|
|
176
|
+
}
|
|
177
|
+
return withAllocation(module, BUILDER_OPTIONS_SIZE, (rawOptions) => {
|
|
178
|
+
module._fdb_payload_v1_builder_options_init(rawOptions);
|
|
179
|
+
applyBuilderOptions(module, rawOptions, options);
|
|
180
|
+
return invoke(rawOptions);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
dispose() {
|
|
185
|
+
if (this.#handle !== 0) {
|
|
186
|
+
const handle = this.#handle;
|
|
187
|
+
this.#handle = 0;
|
|
188
|
+
builderFinalizer.unregister(this.#finalizerToken);
|
|
189
|
+
payloadModule()._fdb_payload_v1_builder_release(handle);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
requireSpecSha256(expectedSha256) {
|
|
193
|
+
const module = payloadModule();
|
|
194
|
+
withSha256(module, expectedSha256, (digest) => {
|
|
195
|
+
this.call((handle, error) => module._fdb_payload_v1_builder_require_spec_sha256(handle, digest, error));
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
entryBegin(entryIndex, valueCount) {
|
|
199
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_entry_begin(handle, checkedU32(entryIndex, 'entryIndex'), checkedU64(valueCount, 'valueCount'), error));
|
|
200
|
+
}
|
|
201
|
+
declareObject(componentIndex) {
|
|
202
|
+
const module = payloadModule();
|
|
203
|
+
return withAllocation(module, 16, (outputs) => {
|
|
204
|
+
const status = module._fdb_payload_v1_builder_object_declare(this.requireHandle(), checkedU32(componentIndex, 'componentIndex'), outputs, outputs + 8);
|
|
205
|
+
checkStatus(status, outputs + 8);
|
|
206
|
+
return ObjectHandle[createObjectHandle](readU64(module, outputs), handleConstructionToken);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
objectFillBegin(object) {
|
|
210
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_object_fill_begin(handle, objectValue(object), error));
|
|
211
|
+
}
|
|
212
|
+
valueNull() {
|
|
213
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_value_null(handle, error));
|
|
214
|
+
}
|
|
215
|
+
valueBool(value) {
|
|
216
|
+
if (typeof value !== 'boolean') {
|
|
217
|
+
throw new TypeError('value must be boolean');
|
|
218
|
+
}
|
|
219
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_value_bool(handle, value ? 1 : 0, error));
|
|
220
|
+
}
|
|
221
|
+
valueU8(value) {
|
|
222
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_value_u8(handle, checkedU8(value, 'value'), error));
|
|
223
|
+
}
|
|
224
|
+
valueU16(value) {
|
|
225
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_value_u16(handle, checkedU16(value, 'value'), error));
|
|
226
|
+
}
|
|
227
|
+
valueU32(value) {
|
|
228
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_value_u32(handle, checkedU32(value, 'value'), error));
|
|
229
|
+
}
|
|
230
|
+
valueI32(value) {
|
|
231
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_value_i32(handle, checkedI32(value, 'value'), error));
|
|
232
|
+
}
|
|
233
|
+
valueU8n(value) {
|
|
234
|
+
return this.valueU8nBits(f64Bits(value));
|
|
235
|
+
}
|
|
236
|
+
valueU8nBits(bits) {
|
|
237
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_value_u8n_f64_bits(handle, checkedU64(bits, 'bits'), error));
|
|
238
|
+
}
|
|
239
|
+
valueU16n(value) {
|
|
240
|
+
return this.valueU16nBits(f64Bits(value));
|
|
241
|
+
}
|
|
242
|
+
valueU16nBits(bits) {
|
|
243
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_value_u16n_f64_bits(handle, checkedU64(bits, 'bits'), error));
|
|
244
|
+
}
|
|
245
|
+
valueF32(value) {
|
|
246
|
+
return this.valueF32Bits(f32Bits(value));
|
|
247
|
+
}
|
|
248
|
+
valueF32Bits(bits) {
|
|
249
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_value_f32_bits(handle, checkedU32(bits, 'bits'), error));
|
|
250
|
+
}
|
|
251
|
+
valueF64(value) {
|
|
252
|
+
return this.valueF64Bits(f64Bits(value));
|
|
253
|
+
}
|
|
254
|
+
valueF64Bits(bits) {
|
|
255
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_value_f64_bits(handle, checkedU64(bits, 'bits'), error));
|
|
256
|
+
}
|
|
257
|
+
valueStr(value) {
|
|
258
|
+
if (typeof value !== 'string') {
|
|
259
|
+
throw new TypeError('value must be string');
|
|
260
|
+
}
|
|
261
|
+
return this.valueStrBytes(encoder.encode(value));
|
|
262
|
+
}
|
|
263
|
+
valueStrBytes(value) {
|
|
264
|
+
return this.callBytes(value, (handle, pointer, size, error) => payloadModule()._fdb_payload_v1_builder_value_str(handle, pointer, size, error));
|
|
265
|
+
}
|
|
266
|
+
valueWstr(value) {
|
|
267
|
+
if (typeof value !== 'string') {
|
|
268
|
+
throw new TypeError('value must be string');
|
|
269
|
+
}
|
|
270
|
+
const units = new Uint16Array(value.length);
|
|
271
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
272
|
+
units[index] = value.charCodeAt(index);
|
|
273
|
+
}
|
|
274
|
+
return this.valueWstrUnits(units);
|
|
275
|
+
}
|
|
276
|
+
valueWstrUnits(value) {
|
|
277
|
+
const module = payloadModule();
|
|
278
|
+
return withInputU16(module, value, (pointer, size) => this.call((handle, error) => module._fdb_payload_v1_builder_value_wstr(handle, pointer, size, error)));
|
|
279
|
+
}
|
|
280
|
+
valueBytes(value) {
|
|
281
|
+
return this.callBytes(value, (handle, pointer, size, error) => payloadModule()._fdb_payload_v1_builder_value_bytes(handle, pointer, size, error));
|
|
282
|
+
}
|
|
283
|
+
valueFixedRun(run) {
|
|
284
|
+
if (!(run instanceof FixedRun)) {
|
|
285
|
+
throw new TypeError('run must be FixedRun');
|
|
286
|
+
}
|
|
287
|
+
const module = payloadModule();
|
|
288
|
+
const validity = run.validity ?? new Uint8Array();
|
|
289
|
+
return withInputBytes(module, run.data, (data, dataSize) => withInputBytes(module, validity, (validityData, validitySize) => withAllocation(module, FIXED_RUN_SIZE, (raw) => {
|
|
290
|
+
module._fdb_payload_v1_fixed_run_init(raw);
|
|
291
|
+
writeU32(module, raw + 8, data);
|
|
292
|
+
writeU64(module, raw + 16, dataSize);
|
|
293
|
+
writeU64(module, raw + 24, run.count);
|
|
294
|
+
writeU64(module, raw + 32, run.strideBytes);
|
|
295
|
+
writeU32(module, raw + 40, validityData);
|
|
296
|
+
writeU64(module, raw + 48, validitySize);
|
|
297
|
+
writeU64(module, raw + 56, run.validityBitOffset);
|
|
298
|
+
return this.call((handle, error) => module._fdb_payload_v1_builder_value_fixed_run(handle, raw, error));
|
|
299
|
+
})));
|
|
300
|
+
}
|
|
301
|
+
valueComponentBegin() {
|
|
302
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_value_component_begin(handle, error));
|
|
303
|
+
}
|
|
304
|
+
valueListBegin(itemCount) {
|
|
305
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_value_list_begin(handle, checkedU64(itemCount, 'itemCount'), error));
|
|
306
|
+
}
|
|
307
|
+
valueObject(object) {
|
|
308
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_value_object(handle, objectValue(object), error));
|
|
309
|
+
}
|
|
310
|
+
valueRef(object) {
|
|
311
|
+
return this.call((handle, error) => payloadModule()._fdb_payload_v1_builder_value_ref(handle, objectValue(object), error));
|
|
312
|
+
}
|
|
313
|
+
freeze() {
|
|
314
|
+
const module = payloadModule();
|
|
315
|
+
return withAllocation(module, POINTER_SIZE * 2, (outputs) => {
|
|
316
|
+
const status = module._fdb_payload_v1_builder_freeze(this.requireHandle(), outputs, outputs + POINTER_SIZE);
|
|
317
|
+
checkStatus(status, outputs + POINTER_SIZE);
|
|
318
|
+
return BuildPlan[createBuildPlan](readU32(module, outputs), handleConstructionToken);
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
call(operation) {
|
|
322
|
+
const module = payloadModule();
|
|
323
|
+
return withAllocation(module, POINTER_SIZE, (outError) => {
|
|
324
|
+
const status = operation(this.requireHandle(), outError);
|
|
325
|
+
checkStatus(status, outError);
|
|
326
|
+
return this;
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
callBytes(bytes, operation) {
|
|
330
|
+
const module = payloadModule();
|
|
331
|
+
return withInputBytes(module, bytes, (pointer, size) => this.call((handle, error) => operation(handle, pointer, size, error)));
|
|
332
|
+
}
|
|
333
|
+
requireHandle() {
|
|
334
|
+
if (this.#handle === 0) {
|
|
335
|
+
throw bindingError('Builder is disposed', 'disposed_handle');
|
|
336
|
+
}
|
|
337
|
+
return this.#handle;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
function objectValue(object) {
|
|
341
|
+
if (!(object instanceof ObjectHandle)) {
|
|
342
|
+
throw new TypeError('object must be ObjectHandle');
|
|
343
|
+
}
|
|
344
|
+
return ObjectHandle.prototype[objectHandleValue].call(object);
|
|
345
|
+
}
|
|
346
|
+
function applyBuilderOptions(module, pointer, options) {
|
|
347
|
+
if (options.flags !== undefined) {
|
|
348
|
+
writeU32(module, pointer + 4, checkedU32(options.flags, 'flags'));
|
|
349
|
+
}
|
|
350
|
+
const values = [
|
|
351
|
+
[options.maxValueNodes, 8, 'maxValueNodes'],
|
|
352
|
+
[options.maxListElements, 16, 'maxListElements'],
|
|
353
|
+
[options.maxTextBytes, 24, 'maxTextBytes'],
|
|
354
|
+
[options.maxOpaqueBytes, 32, 'maxOpaqueBytes'],
|
|
355
|
+
[options.maxNestingDepth, 40, 'maxNestingDepth'],
|
|
356
|
+
[options.maxTotalBuilderBytes, 48, 'maxTotalBuilderBytes'],
|
|
357
|
+
[options.maxGraphObjects, 88, 'maxGraphObjects'],
|
|
358
|
+
];
|
|
359
|
+
for (const [value, offset, name] of values) {
|
|
360
|
+
if (value !== undefined) {
|
|
361
|
+
writeU64(module, pointer + offset, checkedU64(value, name));
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare enum CodegenTarget {
|
|
2
|
+
Cpp = 1,
|
|
3
|
+
Rust = 2,
|
|
4
|
+
Python = 4,
|
|
5
|
+
TypeScript = 8
|
|
6
|
+
}
|
|
7
|
+
export declare enum ArtifactKind {
|
|
8
|
+
Source = 1
|
|
9
|
+
}
|
|
10
|
+
export interface CodegenOptionValues {
|
|
11
|
+
flags?: number;
|
|
12
|
+
maxArtifacts?: bigint;
|
|
13
|
+
maxTotalBytes?: bigint;
|
|
14
|
+
}
|
|
15
|
+
export declare class CodegenOptions {
|
|
16
|
+
readonly flags: number;
|
|
17
|
+
readonly maxArtifacts: bigint;
|
|
18
|
+
readonly maxTotalBytes: bigint;
|
|
19
|
+
constructor(values?: CodegenOptionValues);
|
|
20
|
+
}
|
|
21
|
+
export declare class Artifact {
|
|
22
|
+
#private;
|
|
23
|
+
readonly relativePath: string;
|
|
24
|
+
readonly kind: ArtifactKind;
|
|
25
|
+
constructor(relativePath: string, kind: ArtifactKind, bytes: Uint8Array, sha256: Uint8Array);
|
|
26
|
+
get bytes(): Uint8Array;
|
|
27
|
+
get sha256(): Uint8Array;
|
|
28
|
+
}
|
|
29
|
+
declare const artifactSetToken: unique symbol;
|
|
30
|
+
declare const createArtifactSet: unique symbol;
|
|
31
|
+
export declare class ArtifactSet {
|
|
32
|
+
#private;
|
|
33
|
+
private constructor();
|
|
34
|
+
static [createArtifactSet](handle: number, token: typeof artifactSetToken): ArtifactSet;
|
|
35
|
+
clone(): ArtifactSet;
|
|
36
|
+
dispose(): void;
|
|
37
|
+
size(): bigint;
|
|
38
|
+
artifact(index: bigint): Artifact;
|
|
39
|
+
private queryBlob;
|
|
40
|
+
private requireHandle;
|
|
41
|
+
}
|
|
42
|
+
export declare function generateArtifacts(specHandle: number, target: CodegenTarget, options?: CodegenOptions): ArtifactSet;
|
|
43
|
+
export {};
|