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
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ArtifactSet, CodegenOptions, CodegenTarget } from './codegen.js';
|
|
2
|
+
export declare enum Profile {
|
|
3
|
+
RecordV1 = 1,
|
|
4
|
+
ObjectGraphV1 = 2
|
|
5
|
+
}
|
|
6
|
+
export declare class Capabilities {
|
|
7
|
+
readonly profile: Profile;
|
|
8
|
+
readonly semanticFlags: bigint;
|
|
9
|
+
readonly operationFlags: bigint;
|
|
10
|
+
readonly codegenTargetFlags: bigint;
|
|
11
|
+
readonly directBuildStatus: number;
|
|
12
|
+
constructor(profile: Profile, semanticFlags: bigint, operationFlags: bigint, codegenTargetFlags: bigint, directBuildStatus: number);
|
|
13
|
+
}
|
|
14
|
+
declare const specHandleValue: unique symbol;
|
|
15
|
+
export declare class CompiledSpec {
|
|
16
|
+
#private;
|
|
17
|
+
private constructor();
|
|
18
|
+
static compile(source: Uint8Array): CompiledSpec;
|
|
19
|
+
clone(): CompiledSpec;
|
|
20
|
+
dispose(): void;
|
|
21
|
+
[specHandleValue](): number;
|
|
22
|
+
canonicalJson(): Uint8Array;
|
|
23
|
+
manifestJson(): Uint8Array;
|
|
24
|
+
sha256(): Uint8Array;
|
|
25
|
+
profile(): Profile;
|
|
26
|
+
capabilities(): Capabilities;
|
|
27
|
+
generate(target: CodegenTarget, options?: CodegenOptions): ArtifactSet;
|
|
28
|
+
entryCount(): number;
|
|
29
|
+
entryId(index: number): string;
|
|
30
|
+
entryIndex(identifier: string): number;
|
|
31
|
+
componentCount(): number;
|
|
32
|
+
componentId(index: number): string;
|
|
33
|
+
componentIndex(identifier: string): number;
|
|
34
|
+
componentFieldCount(componentIndex: number): number;
|
|
35
|
+
componentFieldId(componentIndex: number, fieldIndex: number): string;
|
|
36
|
+
componentFieldIndex(componentIndex: number, identifier: string): number;
|
|
37
|
+
private requireHandle;
|
|
38
|
+
private queryBlob;
|
|
39
|
+
private queryCount;
|
|
40
|
+
private queryIndexedId;
|
|
41
|
+
private queryNamedIndex;
|
|
42
|
+
}
|
|
43
|
+
export declare function compiledSpecHandle(spec: CompiledSpec): number;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { CAPABILITIES_SIZE, POINTER_SIZE, SHA256_SIZE, checkedU32, copyBytes, payloadModule, readU32, readU64, withAllocation, withInputBytes, } from './abi.js';
|
|
2
|
+
import { PayloadError, bindingError, checkStatus } from './error.js';
|
|
3
|
+
import { CodegenOptions, generateArtifacts, } from './codegen.js';
|
|
4
|
+
export var Profile;
|
|
5
|
+
(function (Profile) {
|
|
6
|
+
Profile[Profile["RecordV1"] = 1] = "RecordV1";
|
|
7
|
+
Profile[Profile["ObjectGraphV1"] = 2] = "ObjectGraphV1";
|
|
8
|
+
})(Profile || (Profile = {}));
|
|
9
|
+
export class Capabilities {
|
|
10
|
+
profile;
|
|
11
|
+
semanticFlags;
|
|
12
|
+
operationFlags;
|
|
13
|
+
codegenTargetFlags;
|
|
14
|
+
directBuildStatus;
|
|
15
|
+
constructor(profile, semanticFlags, operationFlags, codegenTargetFlags, directBuildStatus) {
|
|
16
|
+
this.profile = profile;
|
|
17
|
+
this.semanticFlags = semanticFlags;
|
|
18
|
+
this.operationFlags = operationFlags;
|
|
19
|
+
this.codegenTargetFlags = codegenTargetFlags;
|
|
20
|
+
this.directBuildStatus = directBuildStatus;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const encoder = new TextEncoder();
|
|
24
|
+
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
25
|
+
const handleConstructionToken = Symbol('fastdb.payload.specHandleConstructionToken');
|
|
26
|
+
const specHandleValue = Symbol('fastdb.payload.specHandleValue');
|
|
27
|
+
const specFinalizer = new FinalizationRegistry((handle) => {
|
|
28
|
+
try {
|
|
29
|
+
payloadModule()._fdb_payload_v1_spec_release(handle);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// Explicit dispose is authoritative; finalization is only a fallback.
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
export class CompiledSpec {
|
|
36
|
+
#handle;
|
|
37
|
+
#finalizerToken = {};
|
|
38
|
+
constructor(handle, token) {
|
|
39
|
+
if (token !== handleConstructionToken) {
|
|
40
|
+
throw new TypeError('CompiledSpec handles are created only by FastDB');
|
|
41
|
+
}
|
|
42
|
+
if (handle === 0) {
|
|
43
|
+
throw bindingError('FastDB Core returned success without a compiled spec', 'missing_spec_handle');
|
|
44
|
+
}
|
|
45
|
+
this.#handle = handle;
|
|
46
|
+
specFinalizer.register(this, handle, this.#finalizerToken);
|
|
47
|
+
}
|
|
48
|
+
static compile(source) {
|
|
49
|
+
const module = payloadModule();
|
|
50
|
+
return withInputBytes(module, source, (sourcePointer, sourceSize) => withAllocation(module, POINTER_SIZE * 2, (outputs) => {
|
|
51
|
+
const status = module._fdb_payload_v1_spec_compile_json(sourcePointer, sourceSize, 0, outputs, outputs + POINTER_SIZE);
|
|
52
|
+
checkStatus(status, outputs + POINTER_SIZE);
|
|
53
|
+
return new CompiledSpec(readU32(module, outputs), handleConstructionToken);
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
clone() {
|
|
57
|
+
const handle = this.requireHandle();
|
|
58
|
+
payloadModule()._fdb_payload_v1_spec_retain(handle);
|
|
59
|
+
return new CompiledSpec(handle, handleConstructionToken);
|
|
60
|
+
}
|
|
61
|
+
dispose() {
|
|
62
|
+
if (this.#handle !== 0) {
|
|
63
|
+
const handle = this.#handle;
|
|
64
|
+
this.#handle = 0;
|
|
65
|
+
specFinalizer.unregister(this.#finalizerToken);
|
|
66
|
+
payloadModule()._fdb_payload_v1_spec_release(handle);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
[specHandleValue]() {
|
|
70
|
+
return this.requireHandle();
|
|
71
|
+
}
|
|
72
|
+
canonicalJson() {
|
|
73
|
+
const module = payloadModule();
|
|
74
|
+
return this.queryBlob(module._fdb_payload_v1_spec_canonical_json.bind(module));
|
|
75
|
+
}
|
|
76
|
+
manifestJson() {
|
|
77
|
+
const module = payloadModule();
|
|
78
|
+
return this.queryBlob(module._fdb_payload_v1_spec_manifest_json.bind(module));
|
|
79
|
+
}
|
|
80
|
+
sha256() {
|
|
81
|
+
const module = payloadModule();
|
|
82
|
+
return withAllocation(module, SHA256_SIZE + POINTER_SIZE, (outputs) => {
|
|
83
|
+
const status = module._fdb_payload_v1_spec_sha256(this.requireHandle(), outputs, outputs + SHA256_SIZE);
|
|
84
|
+
checkStatus(status, outputs + SHA256_SIZE);
|
|
85
|
+
return module.HEAPU8.slice(outputs, outputs + SHA256_SIZE);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
profile() {
|
|
89
|
+
const module = payloadModule();
|
|
90
|
+
return withAllocation(module, POINTER_SIZE * 2, (outputs) => {
|
|
91
|
+
const status = module._fdb_payload_v1_spec_profile(this.requireHandle(), outputs, outputs + POINTER_SIZE);
|
|
92
|
+
checkStatus(status, outputs + POINTER_SIZE);
|
|
93
|
+
return checkedProfile(readU32(module, outputs));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
capabilities() {
|
|
97
|
+
const module = payloadModule();
|
|
98
|
+
return withAllocation(module, CAPABILITIES_SIZE + POINTER_SIZE, (outputs) => {
|
|
99
|
+
module._fdb_payload_v1_capabilities_init(outputs);
|
|
100
|
+
const status = module._fdb_payload_v1_spec_capabilities(this.requireHandle(), outputs, outputs + CAPABILITIES_SIZE);
|
|
101
|
+
checkStatus(status, outputs + CAPABILITIES_SIZE);
|
|
102
|
+
return new Capabilities(checkedProfile(readU32(module, outputs + 4)), readU64(module, outputs + 8), readU64(module, outputs + 16), readU64(module, outputs + 24), readU32(module, outputs + 32));
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
generate(target, options = new CodegenOptions()) {
|
|
106
|
+
return generateArtifacts(this.requireHandle(), target, options);
|
|
107
|
+
}
|
|
108
|
+
entryCount() {
|
|
109
|
+
const module = payloadModule();
|
|
110
|
+
return this.queryCount(module._fdb_payload_v1_spec_entry_count.bind(module));
|
|
111
|
+
}
|
|
112
|
+
entryId(index) {
|
|
113
|
+
const module = payloadModule();
|
|
114
|
+
return this.queryIndexedId(module._fdb_payload_v1_spec_entry_id.bind(module), checkedU32(index, 'entryIndex'));
|
|
115
|
+
}
|
|
116
|
+
entryIndex(identifier) {
|
|
117
|
+
const module = payloadModule();
|
|
118
|
+
return this.queryNamedIndex(module._fdb_payload_v1_spec_entry_index.bind(module), identifier);
|
|
119
|
+
}
|
|
120
|
+
componentCount() {
|
|
121
|
+
const module = payloadModule();
|
|
122
|
+
return this.queryCount(module._fdb_payload_v1_spec_component_count.bind(module));
|
|
123
|
+
}
|
|
124
|
+
componentId(index) {
|
|
125
|
+
const module = payloadModule();
|
|
126
|
+
return this.queryIndexedId(module._fdb_payload_v1_spec_component_id.bind(module), checkedU32(index, 'componentIndex'));
|
|
127
|
+
}
|
|
128
|
+
componentIndex(identifier) {
|
|
129
|
+
const module = payloadModule();
|
|
130
|
+
return this.queryNamedIndex(module._fdb_payload_v1_spec_component_index.bind(module), identifier);
|
|
131
|
+
}
|
|
132
|
+
componentFieldCount(componentIndex) {
|
|
133
|
+
const module = payloadModule();
|
|
134
|
+
return withAllocation(module, POINTER_SIZE * 2, (outputs) => {
|
|
135
|
+
const status = module._fdb_payload_v1_spec_component_field_count(this.requireHandle(), checkedU32(componentIndex, 'componentIndex'), outputs, outputs + POINTER_SIZE);
|
|
136
|
+
checkStatus(status, outputs + POINTER_SIZE);
|
|
137
|
+
return readU32(module, outputs);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
componentFieldId(componentIndex, fieldIndex) {
|
|
141
|
+
const module = payloadModule();
|
|
142
|
+
const bytes = this.queryBlob((spec, outBlob, outError) => module._fdb_payload_v1_spec_component_field_id(spec, checkedU32(componentIndex, 'componentIndex'), checkedU32(fieldIndex, 'fieldIndex'), outBlob, outError));
|
|
143
|
+
try {
|
|
144
|
+
return decoder.decode(bytes);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
throw bindingError(`FastDB Core returned a non-UTF-8 field identifier: ${String(error)}`, 'invalid_utf8_identifier');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
componentFieldIndex(componentIndex, identifier) {
|
|
151
|
+
const module = payloadModule();
|
|
152
|
+
const bytes = encoder.encode(identifier);
|
|
153
|
+
return withInputBytes(module, bytes, (data, size) => withAllocation(module, POINTER_SIZE * 2, (outputs) => {
|
|
154
|
+
const status = module._fdb_payload_v1_spec_component_field_index(this.requireHandle(), checkedU32(componentIndex, 'componentIndex'), data, size, outputs, outputs + POINTER_SIZE);
|
|
155
|
+
checkStatus(status, outputs + POINTER_SIZE);
|
|
156
|
+
return readU32(module, outputs);
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
requireHandle() {
|
|
160
|
+
if (this.#handle === 0) {
|
|
161
|
+
throw bindingError('CompiledSpec is disposed', 'disposed_handle');
|
|
162
|
+
}
|
|
163
|
+
return this.#handle;
|
|
164
|
+
}
|
|
165
|
+
queryBlob(query) {
|
|
166
|
+
const module = payloadModule();
|
|
167
|
+
return withAllocation(module, POINTER_SIZE * 2, (outputs) => {
|
|
168
|
+
const status = query(this.requireHandle(), outputs, outputs + POINTER_SIZE);
|
|
169
|
+
checkStatus(status, outputs + POINTER_SIZE);
|
|
170
|
+
const blob = readU32(module, outputs);
|
|
171
|
+
if (blob === 0) {
|
|
172
|
+
throw bindingError('FastDB Core returned success without a blob', 'missing_blob_handle');
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
return copyBytes(module, module._fdb_payload_v1_blob_data(blob), module._fdb_payload_v1_blob_size(blob));
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
module._fdb_payload_v1_blob_release(blob);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
queryCount(query) {
|
|
183
|
+
const module = payloadModule();
|
|
184
|
+
return withAllocation(module, POINTER_SIZE * 2, (outputs) => {
|
|
185
|
+
const status = query(this.requireHandle(), outputs, outputs + POINTER_SIZE);
|
|
186
|
+
checkStatus(status, outputs + POINTER_SIZE);
|
|
187
|
+
return readU32(module, outputs);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
queryIndexedId(query, index) {
|
|
191
|
+
const bytes = this.queryBlob((spec, outBlob, outError) => query(spec, index, outBlob, outError));
|
|
192
|
+
try {
|
|
193
|
+
return decoder.decode(bytes);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
throw bindingError(`FastDB Core returned a non-UTF-8 identifier: ${String(error)}`, 'invalid_utf8_identifier');
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
queryNamedIndex(query, identifier) {
|
|
200
|
+
const module = payloadModule();
|
|
201
|
+
const bytes = encoder.encode(identifier);
|
|
202
|
+
return withInputBytes(module, bytes, (data, size) => withAllocation(module, POINTER_SIZE * 2, (outputs) => {
|
|
203
|
+
const status = query(this.requireHandle(), data, size, outputs, outputs + POINTER_SIZE);
|
|
204
|
+
checkStatus(status, outputs + POINTER_SIZE);
|
|
205
|
+
return readU32(module, outputs);
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export function compiledSpecHandle(spec) {
|
|
210
|
+
if (!(spec instanceof CompiledSpec)) {
|
|
211
|
+
throw new TypeError('spec must be CompiledSpec');
|
|
212
|
+
}
|
|
213
|
+
return CompiledSpec.prototype[specHandleValue].call(spec);
|
|
214
|
+
}
|
|
215
|
+
function checkedProfile(value) {
|
|
216
|
+
if (value === Profile.RecordV1 || value === Profile.ObjectGraphV1) {
|
|
217
|
+
return value;
|
|
218
|
+
}
|
|
219
|
+
throw new PayloadError(7002, 'UNSUPPORTED_ABI', '/profile', 'FastDB Core returned an unknown payload profile', `{"actual":${value},"reason":"unknown_profile"}`);
|
|
220
|
+
}
|
package/dist/schema.js
CHANGED
package/dist/serializer.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Legacy standalone serializer; not fastdb.payload.v1 or an external RPC format.
|
|
1
2
|
import { createFeature, Feature } from './feature.js';
|
|
2
3
|
import { getClassSchema, resolveListItem, } from './schema.js';
|
|
3
4
|
import { FastdbRuntimeError, FastdbUsageError } from './errors.js';
|