fastdb4ts 0.0.3 → 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.
@@ -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 {};
@@ -0,0 +1,182 @@
1
+ import { POINTER_SIZE, SHA256_SIZE, checkedU32, checkedU64, copyBytes, payloadModule, readU32, readU64, withAllocation, writeU32, writeU64, } from './abi.js';
2
+ import { bindingError, checkStatus } from './error.js';
3
+ const CODEGEN_OPTIONS_SIZE = 48;
4
+ export var CodegenTarget;
5
+ (function (CodegenTarget) {
6
+ CodegenTarget[CodegenTarget["Cpp"] = 1] = "Cpp";
7
+ CodegenTarget[CodegenTarget["Rust"] = 2] = "Rust";
8
+ CodegenTarget[CodegenTarget["Python"] = 4] = "Python";
9
+ CodegenTarget[CodegenTarget["TypeScript"] = 8] = "TypeScript";
10
+ })(CodegenTarget || (CodegenTarget = {}));
11
+ export var ArtifactKind;
12
+ (function (ArtifactKind) {
13
+ ArtifactKind[ArtifactKind["Source"] = 1] = "Source";
14
+ })(ArtifactKind || (ArtifactKind = {}));
15
+ export class CodegenOptions {
16
+ flags;
17
+ maxArtifacts;
18
+ maxTotalBytes;
19
+ constructor(values = {}) {
20
+ const module = payloadModule();
21
+ const defaults = withAllocation(module, CODEGEN_OPTIONS_SIZE, (pointer) => {
22
+ module._fdb_payload_v1_codegen_options_init(pointer);
23
+ return {
24
+ flags: readU32(module, pointer + 4),
25
+ maxArtifacts: readU64(module, pointer + 8),
26
+ maxTotalBytes: readU64(module, pointer + 16),
27
+ };
28
+ });
29
+ this.flags = checkedU32(values.flags ?? defaults.flags, 'flags');
30
+ this.maxArtifacts = checkedU64(values.maxArtifacts ?? defaults.maxArtifacts, 'maxArtifacts');
31
+ this.maxTotalBytes = checkedU64(values.maxTotalBytes ?? defaults.maxTotalBytes, 'maxTotalBytes');
32
+ }
33
+ }
34
+ export class Artifact {
35
+ relativePath;
36
+ kind;
37
+ #bytes;
38
+ #sha256;
39
+ constructor(relativePath, kind, bytes, sha256) {
40
+ this.relativePath = relativePath;
41
+ this.kind = kind;
42
+ this.#bytes = bytes.slice();
43
+ this.#sha256 = sha256.slice();
44
+ }
45
+ get bytes() {
46
+ return this.#bytes.slice();
47
+ }
48
+ get sha256() {
49
+ return this.#sha256.slice();
50
+ }
51
+ }
52
+ const decoder = new TextDecoder('utf-8', { fatal: true });
53
+ const artifactSetToken = Symbol('fastdb.payload.artifactSetToken');
54
+ const createArtifactSet = Symbol('fastdb.payload.createArtifactSet');
55
+ const artifactSetFinalizer = new FinalizationRegistry((handle) => {
56
+ try {
57
+ payloadModule()._fdb_payload_v1_codegen_result_release(handle);
58
+ }
59
+ catch {
60
+ // Explicit disposal is authoritative; finalization is only a fallback.
61
+ }
62
+ });
63
+ export class ArtifactSet {
64
+ #handle;
65
+ #finalizerToken = {};
66
+ constructor(handle, token) {
67
+ if (token !== artifactSetToken) {
68
+ throw new TypeError('ArtifactSet handles are created only by FastDB');
69
+ }
70
+ if (handle === 0) {
71
+ throw bindingError('FastDB Core returned success without an artifact set', 'missing_codegen_result');
72
+ }
73
+ this.#handle = handle;
74
+ artifactSetFinalizer.register(this, handle, this.#finalizerToken);
75
+ }
76
+ static [createArtifactSet](handle, token) {
77
+ if (token !== artifactSetToken) {
78
+ throw new TypeError('ArtifactSet handles are created only by FastDB');
79
+ }
80
+ try {
81
+ return new ArtifactSet(handle, artifactSetToken);
82
+ }
83
+ catch (error) {
84
+ if (handle !== 0) {
85
+ payloadModule()._fdb_payload_v1_codegen_result_release(handle);
86
+ }
87
+ throw error;
88
+ }
89
+ }
90
+ clone() {
91
+ const handle = this.requireHandle();
92
+ payloadModule()._fdb_payload_v1_codegen_result_retain(handle);
93
+ return ArtifactSet[createArtifactSet](handle, artifactSetToken);
94
+ }
95
+ dispose() {
96
+ if (this.#handle !== 0) {
97
+ const handle = this.#handle;
98
+ this.#handle = 0;
99
+ artifactSetFinalizer.unregister(this.#finalizerToken);
100
+ payloadModule()._fdb_payload_v1_codegen_result_release(handle);
101
+ }
102
+ }
103
+ size() {
104
+ const module = payloadModule();
105
+ return withAllocation(module, 8 + POINTER_SIZE, (outputs) => {
106
+ const status = module._fdb_payload_v1_codegen_result_artifact_count(this.requireHandle(), outputs, outputs + 8);
107
+ checkStatus(status, outputs + 8);
108
+ return readU64(module, outputs);
109
+ });
110
+ }
111
+ artifact(index) {
112
+ const checkedIndex = checkedU64(index, 'artifactIndex');
113
+ const module = payloadModule();
114
+ const pathBytes = this.queryBlob(checkedIndex, module._fdb_payload_v1_codegen_result_artifact_relative_path.bind(module));
115
+ let relativePath;
116
+ try {
117
+ relativePath = decoder.decode(pathBytes);
118
+ }
119
+ catch (error) {
120
+ throw bindingError(`FastDB Core returned a non-UTF-8 artifact path: ${String(error)}`, 'invalid_utf8_artifact_path');
121
+ }
122
+ const kind = withAllocation(module, POINTER_SIZE * 2, (outputs) => {
123
+ const status = module._fdb_payload_v1_codegen_result_artifact_kind(this.requireHandle(), checkedIndex, outputs, outputs + POINTER_SIZE);
124
+ checkStatus(status, outputs + POINTER_SIZE);
125
+ const value = readU32(module, outputs);
126
+ if (value !== ArtifactKind.Source) {
127
+ throw bindingError('FastDB Core returned an unknown artifact kind', 'unknown_artifact_kind');
128
+ }
129
+ return value;
130
+ });
131
+ const bytes = this.queryBlob(checkedIndex, module._fdb_payload_v1_codegen_result_artifact_bytes.bind(module));
132
+ const sha256 = withAllocation(module, SHA256_SIZE + POINTER_SIZE, (outputs) => {
133
+ const status = module._fdb_payload_v1_codegen_result_artifact_sha256(this.requireHandle(), checkedIndex, outputs, outputs + SHA256_SIZE);
134
+ checkStatus(status, outputs + SHA256_SIZE);
135
+ return module.HEAPU8.slice(outputs, outputs + SHA256_SIZE);
136
+ });
137
+ return new Artifact(relativePath, kind, bytes, sha256);
138
+ }
139
+ queryBlob(index, query) {
140
+ const module = payloadModule();
141
+ return withAllocation(module, POINTER_SIZE * 2, (outputs) => {
142
+ const status = query(this.requireHandle(), index, outputs, outputs + POINTER_SIZE);
143
+ checkStatus(status, outputs + POINTER_SIZE);
144
+ const blob = readU32(module, outputs);
145
+ if (blob === 0) {
146
+ throw bindingError('FastDB Core returned success without a blob', 'missing_blob_handle');
147
+ }
148
+ try {
149
+ return copyBytes(module, module._fdb_payload_v1_blob_data(blob), module._fdb_payload_v1_blob_size(blob));
150
+ }
151
+ finally {
152
+ module._fdb_payload_v1_blob_release(blob);
153
+ }
154
+ });
155
+ }
156
+ requireHandle() {
157
+ if (this.#handle === 0) {
158
+ throw bindingError('ArtifactSet is disposed', 'disposed_handle');
159
+ }
160
+ return this.#handle;
161
+ }
162
+ }
163
+ export function generateArtifacts(specHandle, target, options = new CodegenOptions()) {
164
+ if (target !== CodegenTarget.Cpp &&
165
+ target !== CodegenTarget.Rust &&
166
+ target !== CodegenTarget.Python &&
167
+ target !== CodegenTarget.TypeScript) {
168
+ throw new RangeError('target must be a CodegenTarget');
169
+ }
170
+ const module = payloadModule();
171
+ return withAllocation(module, CODEGEN_OPTIONS_SIZE, (rawOptions) => {
172
+ module._fdb_payload_v1_codegen_options_init(rawOptions);
173
+ writeU32(module, rawOptions + 4, checkedU32(options.flags, 'flags'));
174
+ writeU64(module, rawOptions + 8, checkedU64(options.maxArtifacts, 'maxArtifacts'));
175
+ writeU64(module, rawOptions + 16, checkedU64(options.maxTotalBytes, 'maxTotalBytes'));
176
+ return withAllocation(module, POINTER_SIZE * 2, (outputs) => {
177
+ const status = module._fdb_payload_v1_spec_codegen(specHandle, BigInt(target), rawOptions, outputs, outputs + POINTER_SIZE);
178
+ checkStatus(status, outputs + POINTER_SIZE);
179
+ return ArtifactSet[createArtifactSet](readU32(module, outputs), artifactSetToken);
180
+ });
181
+ });
182
+ }
@@ -0,0 +1,9 @@
1
+ export declare class PayloadError extends Error {
2
+ readonly code: number;
3
+ readonly symbol: string;
4
+ readonly path: string;
5
+ readonly detailsJson: string;
6
+ constructor(code: number, symbol: string, path: string, message: string, detailsJson: string);
7
+ }
8
+ export declare function bindingError(message: string, reason: string): PayloadError;
9
+ export declare function checkStatus(status: number, errorOut: number): void;
@@ -0,0 +1,53 @@
1
+ import { copyBytes, payloadModule, readU32, readU64, withAllocation, } from './abi.js';
2
+ const decoder = new TextDecoder('utf-8');
3
+ const ERROR_SIZE_OFFSET = 8;
4
+ const ERROR_OUTPUT_SIZE = 16;
5
+ export class PayloadError extends Error {
6
+ code;
7
+ symbol;
8
+ path;
9
+ detailsJson;
10
+ constructor(code, symbol, path, message, detailsJson) {
11
+ super(message);
12
+ this.name = 'PayloadError';
13
+ this.code = code;
14
+ this.symbol = symbol;
15
+ this.path = path;
16
+ this.detailsJson = detailsJson;
17
+ }
18
+ }
19
+ export function bindingError(message, reason) {
20
+ return new PayloadError(9001, 'BINDING_CONTRACT', '', message, `{"reason":"${reason}"}`);
21
+ }
22
+ function copyErrorField(error, accessor) {
23
+ const module = payloadModule();
24
+ return withAllocation(module, ERROR_OUTPUT_SIZE, (outputs) => {
25
+ accessor(error, outputs, outputs + ERROR_SIZE_OFFSET);
26
+ const data = readU32(module, outputs);
27
+ const size = readU64(module, outputs + ERROR_SIZE_OFFSET);
28
+ return decoder.decode(copyBytes(module, data, size));
29
+ });
30
+ }
31
+ function takeNativeError(status, error) {
32
+ if (error === 0) {
33
+ return new PayloadError(status || 9001, 'BINDING_CONTRACT', '', 'FastDB Core returned a failure without an owned error', '{"reason":"missing_error_handle"}');
34
+ }
35
+ const module = payloadModule();
36
+ try {
37
+ return new PayloadError(module._fdb_payload_v1_error_code(error), copyErrorField(error, module._fdb_payload_v1_error_symbol.bind(module)), copyErrorField(error, module._fdb_payload_v1_error_path.bind(module)), copyErrorField(error, module._fdb_payload_v1_error_message.bind(module)), copyErrorField(error, module._fdb_payload_v1_error_details_json.bind(module)));
38
+ }
39
+ finally {
40
+ module._fdb_payload_v1_error_release(error);
41
+ }
42
+ }
43
+ export function checkStatus(status, errorOut) {
44
+ const module = payloadModule();
45
+ const error = readU32(module, errorOut);
46
+ if (status !== 0) {
47
+ throw takeNativeError(status, error);
48
+ }
49
+ if (error !== 0) {
50
+ module._fdb_payload_v1_error_release(error);
51
+ throw bindingError('FastDB Core returned success with an error handle', 'unexpected_error_handle');
52
+ }
53
+ }
@@ -0,0 +1,9 @@
1
+ export { BuildPlan, Builder, FixedRun, ObjectHandle, PlanInfo, } from './builder.js';
2
+ export type { BuilderOptions } from './builder.js';
3
+ export { Artifact, ArtifactKind, ArtifactSet, CodegenOptions, CodegenTarget, } from './codegen.js';
4
+ export type { CodegenOptionValues } from './codegen.js';
5
+ export { PayloadError } from './error.js';
6
+ export { Capabilities, CompiledSpec, Profile } from './spec.js';
7
+ export { Access, BuildPolicy, BuildResult, ExecutionMode, ExecutionReport, FallbackReason, GraphIdentity, OpenOptions, Payload, WasmMemoryBacking, WasmOwnedBytes, View, ViewKind, } from './runtime.js';
8
+ export type { OpenOptionValues, PayloadBackingStats, WasmMemoryBackingOptions, } from './runtime.js';
9
+ export declare function initPayload(): Promise<void>;
@@ -0,0 +1,9 @@
1
+ import { initPayloadModule } from './abi.js';
2
+ export { BuildPlan, Builder, FixedRun, ObjectHandle, PlanInfo, } from './builder.js';
3
+ export { Artifact, ArtifactKind, ArtifactSet, CodegenOptions, CodegenTarget, } from './codegen.js';
4
+ export { PayloadError } from './error.js';
5
+ export { Capabilities, CompiledSpec, Profile } from './spec.js';
6
+ export { Access, BuildPolicy, BuildResult, ExecutionMode, ExecutionReport, FallbackReason, GraphIdentity, OpenOptions, Payload, WasmMemoryBacking, WasmOwnedBytes, View, ViewKind, } from './runtime.js';
7
+ export async function initPayload() {
8
+ await initPayloadModule();
9
+ }