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.
- package/README.md +65 -14
- package/dist/LICENSE +21 -0
- package/dist/THIRD_PARTY_NOTICES.txt +1958 -0
- package/dist/feature.js +1 -0
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -1
- package/dist/orm.d.ts +0 -1
- package/dist/orm.js +2 -9
- 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.js +1 -0
- package/dist/wasm/fastdb4ts.js +1 -1
- package/dist/wasm/fastdb4ts.wasm +0 -0
- package/dist/wasm-loader.d.ts +134 -1
- package/package.json +6 -2
- package/dist/call-db.d.ts +0 -117
- package/dist/call-db.js +0 -1857
package/dist/feature.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Standalone feature metadata; not fastdb.payload.v1 authority.
|
|
1
2
|
import { FastdbRuntimeError, FastdbSchemaError, FastdbUsageError, } from './errors.js';
|
|
2
3
|
import { getClassSchema, getFieldDefinition, resolveListItem, } from './schema.js';
|
|
3
4
|
import { coerceBoolScalar, isListField, isNumericField, isRefField, } from './types.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -6,12 +6,10 @@ export { StridedColumn } from './column.js';
|
|
|
6
6
|
export { FastSerializer } from './serializer.js';
|
|
7
7
|
export { FastdbOwnedBytes, allocateFastdbOwnedBytes, loadDatabaseFromBytes, } from './database-buffer.js';
|
|
8
8
|
export type { FastdbDatabaseBytes } from './database-buffer.js';
|
|
9
|
-
export { decodeFastdbCallDb, decodeFastdbFeature, encodeFastdbCallDb, encodeFastdbFeature, viewFastdbCallDb, } from './call-db.js';
|
|
10
9
|
export { defineSchema, getClassSchema, } from './schema.js';
|
|
11
10
|
export { BOOL, BYTES, F32, F64, I32, REF, STR, U8, U8N, U16, U16N, U32, WSTR, listOf, ref, } from './types.js';
|
|
12
11
|
export { FastdbError, FastdbRuntimeError, FastdbSchemaError, FastdbUsageError, } from './errors.js';
|
|
13
12
|
export type { ChunkView, FieldDefView, FastdbModule, FastdbModuleFactory, WxDatabaseBuildHandle, WxDatabaseHandle, WxFeatureHandle, WxLayerTableBuildHandle, WxLayerTableHandle, WxMemoryStreamHandle, } from './wasm-loader.js';
|
|
14
13
|
export type { ClassSchema, SchemaDefinition, SchemaFieldDefinition, } from './schema.js';
|
|
15
|
-
export type { FastdbCallDbArrayItem, FastdbCallDbBinding, FastdbCallDbArrayView, FastdbCallDbColumnView, FastdbCallDbFeatureDependency, FastdbCallDbScalarField, FastdbCallDbTable, FastdbCallDbTableView, FastdbCallDbView, FastdbFeatureCodecBinding, } from './call-db.js';
|
|
16
14
|
export type { FeatureClass, FeatureDatabaseHandle, } from './feature.js';
|
|
17
15
|
export type { FieldKind, FieldTypeDef, ListFieldDef, ListItemDef, RefFieldDef, SchemaEntry, TypedArrayConstructor, TypedArrayInstance, } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,6 @@ export { Table } from './table.js';
|
|
|
5
5
|
export { StridedColumn } from './column.js';
|
|
6
6
|
export { FastSerializer } from './serializer.js';
|
|
7
7
|
export { FastdbOwnedBytes, allocateFastdbOwnedBytes, loadDatabaseFromBytes, } from './database-buffer.js';
|
|
8
|
-
export { decodeFastdbCallDb, decodeFastdbFeature, encodeFastdbCallDb, encodeFastdbFeature, viewFastdbCallDb, } from './call-db.js';
|
|
9
8
|
export { defineSchema, getClassSchema, } from './schema.js';
|
|
10
9
|
export { BOOL, BYTES, F32, F64, I32, REF, STR, U8, U8N, U16, U16N, U32, WSTR, listOf, ref, } from './types.js';
|
|
11
10
|
export { FastdbError, FastdbRuntimeError, FastdbSchemaError, FastdbUsageError, } from './errors.js';
|
package/dist/orm.d.ts
CHANGED
package/dist/orm.js
CHANGED
|
@@ -127,10 +127,10 @@ export class ORM {
|
|
|
127
127
|
build.post(stream);
|
|
128
128
|
const bytes = this.copyChunkToBytes(stream);
|
|
129
129
|
stream.delete();
|
|
130
|
-
this.
|
|
130
|
+
// Layer handles borrow their native storage from this builder.
|
|
131
|
+
this.tableMap.clear();
|
|
131
132
|
build.delete();
|
|
132
133
|
this.origin = ORM.fromBuffer(bytes).origin;
|
|
133
|
-
this.tableMap.clear();
|
|
134
134
|
}
|
|
135
135
|
toBuffer() {
|
|
136
136
|
if (this.fixed) {
|
|
@@ -223,13 +223,6 @@ export class ORM {
|
|
|
223
223
|
const chunk = stream.dataView();
|
|
224
224
|
return this.module.HEAPU8.slice(chunk.data, chunk.data + chunk.size);
|
|
225
225
|
}
|
|
226
|
-
disposeBuildTables() {
|
|
227
|
-
for (const table of this.tableMap.values()) {
|
|
228
|
-
if (!table.fixed) {
|
|
229
|
-
table.origin.delete();
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
226
|
}
|
|
234
227
|
function normalizeBytes(value) {
|
|
235
228
|
if (value === null || value === undefined) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FastdbModule } from '../wasm-loader.js';
|
|
2
|
+
export declare const ABI_VERSION = 1;
|
|
3
|
+
export declare const SHA256_SIZE = 32;
|
|
4
|
+
export declare const CAPABILITIES_SIZE = 72;
|
|
5
|
+
export declare const POINTER_SIZE = 4;
|
|
6
|
+
export declare const U64_MAX = 18446744073709551615n;
|
|
7
|
+
export declare function initPayloadModule(): Promise<FastdbModule>;
|
|
8
|
+
export declare function payloadModule(): FastdbModule;
|
|
9
|
+
export declare function allocate(module: FastdbModule, size: number): number;
|
|
10
|
+
export declare function withAllocation<T>(module: FastdbModule, size: number, operation: (pointer: number) => T): T;
|
|
11
|
+
export declare function withInputBytes<T>(module: FastdbModule, bytes: Uint8Array, operation: (pointer: number, size: bigint) => T): T;
|
|
12
|
+
export declare function withSha256<T>(module: FastdbModule, digest: Uint8Array, operation: (pointer: number) => T): T;
|
|
13
|
+
export declare function withInputU16<T>(module: FastdbModule, units: Uint16Array, operation: (pointer: number, size: bigint) => T): T;
|
|
14
|
+
export declare function readU32(module: FastdbModule, pointer: number): number;
|
|
15
|
+
export declare function readU64(module: FastdbModule, pointer: number): bigint;
|
|
16
|
+
export declare function writeU32(module: FastdbModule, pointer: number, value: number): void;
|
|
17
|
+
export declare function writeU64(module: FastdbModule, pointer: number, value: bigint): void;
|
|
18
|
+
export declare function copyBytes(module: FastdbModule, pointer: number, size: bigint): Uint8Array;
|
|
19
|
+
export declare function checkedU32(value: number, name: string): number;
|
|
20
|
+
export declare function checkedU16(value: number, name: string): number;
|
|
21
|
+
export declare function checkedU8(value: number, name: string): number;
|
|
22
|
+
export declare function checkedI32(value: number, name: string): number;
|
|
23
|
+
export declare function checkedU64(value: bigint, name: string): bigint;
|
|
24
|
+
export declare function f32Bits(value: number): number;
|
|
25
|
+
export declare function f64Bits(value: number): bigint;
|
|
26
|
+
export declare function f32FromBits(bits: number): number;
|
|
27
|
+
export declare function f64FromBits(bits: bigint): number;
|
|
@@ -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 {};
|