fastdb4ts 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,616 @@
1
+ import { createFeature, Feature } from './feature.js';
2
+ import { getClassSchema, resolveListItem, } from './schema.js';
3
+ import { FastdbRuntimeError, FastdbUsageError } from './errors.js';
4
+ import { getInitializedFastdbModule } from './wasm-loader.js';
5
+ import { isListField, isRefField } from './types.js';
6
+ const NUMERIC_LIST_LAYER_PREFIX = '__fastser_list__|';
7
+ const SERIALIZER_SCHEMA_CACHE = new WeakMap();
8
+ export class FastSerializer {
9
+ static dumps(obj) {
10
+ if (!(obj instanceof Feature)) {
11
+ throw new FastdbUsageError('Only fastdb4ts.Feature objects can be serialized.');
12
+ }
13
+ const module = getInitializedFastdbModule();
14
+ const ctx = new DumpContext();
15
+ ctx.register(obj);
16
+ const db = new module.WxDatabaseBuild();
17
+ db.begin('');
18
+ const layerBuilders = new Map();
19
+ for (const [ctor, layerIdx] of ctx.typeToLayer.entries()) {
20
+ const lb = db.createLayerBegin(ctor.name);
21
+ lb.setGeometryType(module.gtAny, module.cfDefault, false);
22
+ const schema = getSerializerSchema(ctor);
23
+ for (const field of schema.fieldList) {
24
+ const dbFieldIndex = schema.dbFieldIndexBySchema.get(field.index);
25
+ if (dbFieldIndex !== undefined && dbFieldIndex !== -1) {
26
+ lb.addField(field.name, field.entry.originType, 0, 1);
27
+ }
28
+ }
29
+ layerBuilders.set(layerIdx, lb);
30
+ }
31
+ const numericListLayers = new Map();
32
+ for (const ctor of ctx.typeToLayer.keys()) {
33
+ const schema = getSerializerSchema(ctor);
34
+ for (const field of schema.fieldList) {
35
+ const kind = schema.numericFieldKinds.get(field.name);
36
+ if (!kind) {
37
+ continue;
38
+ }
39
+ const layerName = makeNumericListLayerName(ctor.name, field.name, kind);
40
+ const aux = db.createLayerBegin(layerName);
41
+ aux.setGeometryType(module.gtAny, module.cfDefault, false);
42
+ aux.addField('owner_fid', module.ftU32, 0, 1);
43
+ numericListLayers.set(`${ctor.name}:${field.name}`, { kind, layer: aux });
44
+ }
45
+ }
46
+ const orderedObjects = [...ctx.objects].sort((left, right) => left.layerIdx - right.layerIdx || left.featureIdx - right.featureIdx);
47
+ for (const wrapper of orderedObjects) {
48
+ const ctor = wrapper.obj.constructor;
49
+ const schema = getSerializerSchema(ctor);
50
+ const layer = layerBuilders.get(wrapper.layerIdx);
51
+ if (!layer) {
52
+ throw new FastdbRuntimeError(`Missing layer builder for "${ctor.name}".`);
53
+ }
54
+ layer.addFeatureBegin();
55
+ const blob = new ByteWriter();
56
+ for (const field of schema.fieldList) {
57
+ const value = getFeatureFieldValue(wrapper.obj, field.name);
58
+ const numericKind = schema.numericFieldKinds.get(field.name);
59
+ if (numericKind) {
60
+ const aux = numericListLayers.get(`${ctor.name}:${field.name}`);
61
+ if (!aux) {
62
+ throw new FastdbRuntimeError(`Missing numeric-list layer for "${ctor.name}.${field.name}".`);
63
+ }
64
+ writeNumericListChunk(module, aux.layer, wrapper.featureIdx, value, numericKind);
65
+ continue;
66
+ }
67
+ if (isListField(field.entry)) {
68
+ packList(blob, field, value, ctx);
69
+ continue;
70
+ }
71
+ if (field.entry.kind === 'bytes') {
72
+ const bytes = normalizeBytes(value);
73
+ blob.writeU32(bytes.length);
74
+ blob.writeBytes(bytes);
75
+ continue;
76
+ }
77
+ if (isRefField(field.entry)) {
78
+ packFeatureRef(blob, value instanceof Feature ? value : null, ctx);
79
+ continue;
80
+ }
81
+ const dbFieldIndex = schema.dbFieldIndexBySchema.get(field.index);
82
+ if (dbFieldIndex === undefined || dbFieldIndex === -1 || value === null || value === undefined) {
83
+ continue;
84
+ }
85
+ switch (field.entry.kind) {
86
+ case 'bool':
87
+ layer.setFieldInt(dbFieldIndex, value ? 1 : 0);
88
+ break;
89
+ case 'u8':
90
+ case 'u16':
91
+ case 'u32':
92
+ case 'i32':
93
+ case 'u8n':
94
+ case 'u16n':
95
+ layer.setFieldInt(dbFieldIndex, Math.trunc(Number(value)));
96
+ break;
97
+ case 'f32':
98
+ case 'f64':
99
+ layer.setFieldDouble(dbFieldIndex, Number(value));
100
+ break;
101
+ case 'str':
102
+ case 'wstr':
103
+ layer.setFieldString(dbFieldIndex, String(value));
104
+ break;
105
+ default:
106
+ throw new FastdbUsageError(`Unsupported serializer scalar kind "${field.entry.kind}" on field "${field.name}".`);
107
+ }
108
+ }
109
+ const blobBytes = blob.finish();
110
+ if (blobBytes.length > 0) {
111
+ withHeapBytes(module, blobBytes, (ptr, size) => {
112
+ layer.setGeometryRaw(ptr, size);
113
+ });
114
+ }
115
+ layer.addFeatureEnd();
116
+ }
117
+ const stream = new module.WxMemoryStream();
118
+ db.post(stream);
119
+ const data = copyChunkToBytes(module, stream.dataView());
120
+ stream.delete();
121
+ db.delete();
122
+ return data;
123
+ }
124
+ static loads(data, rootType) {
125
+ const module = getInitializedFastdbModule();
126
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
127
+ const db = withHeapBytes(module, bytes, (ptr, size) => module.WxDatabase.loadFromHeap(ptr, size));
128
+ if (db.getLayerCount() === 0) {
129
+ return null;
130
+ }
131
+ const rootLayer = db.getLayer(0);
132
+ if (rootLayer.getFeatureCount() === 0) {
133
+ return null;
134
+ }
135
+ const ctx = new LoadContext(db, module);
136
+ discoverTypes(rootType, ctx.typeMap);
137
+ return ctx.getObject(0, 0, rootType);
138
+ }
139
+ }
140
+ class DumpContext {
141
+ objects = [];
142
+ typeToLayer = new Map();
143
+ objToRef = new WeakMap();
144
+ layerCounters = new Map();
145
+ register(obj) {
146
+ if (this.objToRef.has(obj)) {
147
+ return;
148
+ }
149
+ const ctor = obj.constructor;
150
+ let layerIdx = this.typeToLayer.get(ctor);
151
+ if (layerIdx === undefined) {
152
+ layerIdx = this.typeToLayer.size;
153
+ this.typeToLayer.set(ctor, layerIdx);
154
+ this.layerCounters.set(layerIdx, 0);
155
+ }
156
+ const featureIdx = this.layerCounters.get(layerIdx) ?? 0;
157
+ this.layerCounters.set(layerIdx, featureIdx + 1);
158
+ this.objToRef.set(obj, { layerIdx, featureIdx });
159
+ this.objects.push({ obj, layerIdx, featureIdx });
160
+ const schema = getSerializerSchema(ctor);
161
+ for (const field of schema.fieldList) {
162
+ const value = getFeatureFieldValue(obj, field.name);
163
+ if (value === null || value === undefined) {
164
+ continue;
165
+ }
166
+ if (isRefField(field.entry)) {
167
+ if (value instanceof Feature) {
168
+ this.register(value);
169
+ }
170
+ continue;
171
+ }
172
+ if (!isListField(field.entry) || !Array.isArray(value) || value.length === 0) {
173
+ continue;
174
+ }
175
+ const item = resolveListItem(field.entry);
176
+ if (isFieldType(item)) {
177
+ continue;
178
+ }
179
+ for (const nested of value) {
180
+ if (nested instanceof Feature) {
181
+ this.register(nested);
182
+ }
183
+ }
184
+ }
185
+ }
186
+ getRef(obj) {
187
+ if (!obj) {
188
+ return undefined;
189
+ }
190
+ return this.objToRef.get(obj);
191
+ }
192
+ }
193
+ class LoadContext {
194
+ db;
195
+ module;
196
+ objectCache = new Map();
197
+ typeMap = new Map();
198
+ numericListValues;
199
+ constructor(db, module) {
200
+ this.db = db;
201
+ this.module = module;
202
+ this.numericListValues = loadNumericListValues(db, module);
203
+ }
204
+ getObject(layerIdx, featureIdx, expectedType) {
205
+ const key = `${layerIdx}:${featureIdx}`;
206
+ const cached = this.objectCache.get(key);
207
+ if (cached) {
208
+ return cached;
209
+ }
210
+ const layer = this.db.getLayer(layerIdx);
211
+ const ctor = this.typeMap.get(layer.name()) ?? expectedType;
212
+ const row = layer.tryGetFeatureAt(featureIdx);
213
+ const obj = createFeature(ctor);
214
+ this.objectCache.set(key, obj);
215
+ const cache = obj._getCache();
216
+ const schema = getSerializerSchema(ctor);
217
+ const blob = copyChunkToBytes(this.module, row.geometryView());
218
+ const reader = new ByteReader(blob);
219
+ for (const field of schema.fieldList) {
220
+ const numericKind = schema.numericFieldKinds.get(field.name);
221
+ if (numericKind) {
222
+ cache[field.name] = this.numericListValues.get(`${ctor.name}:${field.name}:${featureIdx}`) ?? [];
223
+ continue;
224
+ }
225
+ if (isListField(field.entry)) {
226
+ cache[field.name] = unpackList(reader, field, this);
227
+ continue;
228
+ }
229
+ if (field.entry.kind === 'bytes') {
230
+ const size = reader.readU32();
231
+ cache[field.name] = reader.readBytes(size);
232
+ continue;
233
+ }
234
+ if (isRefField(field.entry)) {
235
+ const refLayer = reader.readU16();
236
+ const refFeature = reader.readU32();
237
+ if (refLayer === 0xffff) {
238
+ cache[field.name] = null;
239
+ continue;
240
+ }
241
+ if (!field.target) {
242
+ throw new FastdbRuntimeError(`Reference field "${field.name}" is missing a target type.`);
243
+ }
244
+ cache[field.name] = this.getObject(refLayer, refFeature, field.target);
245
+ continue;
246
+ }
247
+ const dbFieldIndex = schema.dbFieldIndexBySchema.get(field.index);
248
+ if (dbFieldIndex === undefined || dbFieldIndex === -1) {
249
+ continue;
250
+ }
251
+ switch (field.entry.kind) {
252
+ case 'bool':
253
+ cache[field.name] = row.getFieldAsInt(dbFieldIndex) !== 0;
254
+ break;
255
+ case 'u8':
256
+ case 'u16':
257
+ case 'u32':
258
+ case 'i32':
259
+ case 'u8n':
260
+ case 'u16n':
261
+ cache[field.name] = row.getFieldAsInt(dbFieldIndex);
262
+ break;
263
+ case 'f32':
264
+ case 'f64':
265
+ cache[field.name] = row.getFieldAsFloat(dbFieldIndex);
266
+ break;
267
+ case 'str':
268
+ case 'wstr':
269
+ cache[field.name] = row.getFieldAsString(dbFieldIndex);
270
+ break;
271
+ default:
272
+ throw new FastdbRuntimeError(`Unsupported load field kind "${field.entry.kind}".`);
273
+ }
274
+ }
275
+ return obj;
276
+ }
277
+ }
278
+ function getSerializerSchema(ctor) {
279
+ const cached = SERIALIZER_SCHEMA_CACHE.get(ctor);
280
+ if (cached) {
281
+ return cached;
282
+ }
283
+ const classSchema = getClassSchema(ctor);
284
+ const numericFieldKinds = new Map();
285
+ const dbFieldIndexBySchema = new Map();
286
+ let dbFieldIndex = 0;
287
+ for (const field of classSchema.fieldList) {
288
+ if (isListField(field.entry)) {
289
+ const item = resolveListItem(field.entry);
290
+ if (isFieldType(item) && item.kind === 'u32') {
291
+ numericFieldKinds.set(field.name, 'u32');
292
+ }
293
+ else if (isFieldType(item) && item.kind === 'f64') {
294
+ numericFieldKinds.set(field.name, 'f64');
295
+ }
296
+ dbFieldIndexBySchema.set(field.index, -1);
297
+ continue;
298
+ }
299
+ if (field.entry.kind === 'ref' || field.entry.kind === 'bytes') {
300
+ dbFieldIndexBySchema.set(field.index, -1);
301
+ continue;
302
+ }
303
+ dbFieldIndexBySchema.set(field.index, dbFieldIndex);
304
+ dbFieldIndex += 1;
305
+ }
306
+ const schema = {
307
+ fieldList: classSchema.fieldList,
308
+ numericFieldKinds,
309
+ dbFieldIndexBySchema,
310
+ };
311
+ SERIALIZER_SCHEMA_CACHE.set(ctor, schema);
312
+ return schema;
313
+ }
314
+ function discoverTypes(ctor, typeMap) {
315
+ if (typeMap.has(ctor.name)) {
316
+ return;
317
+ }
318
+ typeMap.set(ctor.name, ctor);
319
+ const schema = getSerializerSchema(ctor);
320
+ for (const field of schema.fieldList) {
321
+ if (isRefField(field.entry) && field.target) {
322
+ discoverTypes(field.target, typeMap);
323
+ continue;
324
+ }
325
+ if (!isListField(field.entry)) {
326
+ continue;
327
+ }
328
+ const item = resolveListItem(field.entry);
329
+ if (!isFieldType(item)) {
330
+ discoverTypes(item, typeMap);
331
+ }
332
+ }
333
+ }
334
+ function packFeatureRef(writer, value, ctx) {
335
+ const ref = value ? ctx.getRef(value) : undefined;
336
+ if (!ref) {
337
+ writer.writeU16(0xffff);
338
+ writer.writeU32(0xffffffff);
339
+ return;
340
+ }
341
+ writer.writeU16(ref.layerIdx);
342
+ writer.writeU32(ref.featureIdx);
343
+ }
344
+ function packList(writer, field, value, ctx) {
345
+ const list = Array.isArray(value) ? value : [];
346
+ writer.writeU32(list.length);
347
+ if (list.length === 0) {
348
+ return;
349
+ }
350
+ if (!isListField(field.entry)) {
351
+ throw new FastdbUsageError(`Field "${field.name}" is not declared as a list.`);
352
+ }
353
+ const item = resolveListItem(field.entry);
354
+ if (isFieldType(item)) {
355
+ switch (item.kind) {
356
+ case 'i32':
357
+ case 'u8':
358
+ case 'u16':
359
+ case 'bool':
360
+ for (const entry of list) {
361
+ writer.writeI32(Math.trunc(Number(entry)));
362
+ }
363
+ return;
364
+ case 'f32':
365
+ case 'f64':
366
+ for (const entry of list) {
367
+ writer.writeF64(Number(entry));
368
+ }
369
+ return;
370
+ case 'str':
371
+ case 'wstr':
372
+ for (const entry of list) {
373
+ const bytes = new TextEncoder().encode(String(entry));
374
+ writer.writeU32(bytes.length);
375
+ writer.writeBytes(bytes);
376
+ }
377
+ return;
378
+ default:
379
+ throw new FastdbUsageError(`Unsupported list item kind "${item.kind}" on field "${field.name}".`);
380
+ }
381
+ }
382
+ for (const entry of list) {
383
+ packFeatureRef(writer, entry instanceof Feature ? entry : null, ctx);
384
+ }
385
+ }
386
+ function unpackList(reader, field, ctx) {
387
+ const count = reader.readU32();
388
+ if (count === 0) {
389
+ return [];
390
+ }
391
+ if (!isListField(field.entry)) {
392
+ throw new FastdbRuntimeError(`Field "${field.name}" is not declared as a list.`);
393
+ }
394
+ const item = resolveListItem(field.entry);
395
+ const out = [];
396
+ if (isFieldType(item)) {
397
+ switch (item.kind) {
398
+ case 'i32':
399
+ case 'u8':
400
+ case 'u16':
401
+ case 'bool':
402
+ for (let i = 0; i < count; i += 1) {
403
+ out.push(reader.readI32());
404
+ }
405
+ return out;
406
+ case 'f32':
407
+ case 'f64':
408
+ for (let i = 0; i < count; i += 1) {
409
+ out.push(reader.readF64());
410
+ }
411
+ return out;
412
+ case 'str':
413
+ case 'wstr':
414
+ for (let i = 0; i < count; i += 1) {
415
+ out.push(new TextDecoder().decode(reader.readBytes(reader.readU32())));
416
+ }
417
+ return out;
418
+ default:
419
+ throw new FastdbRuntimeError(`Unsupported list item kind "${item.kind}" on field "${field.name}".`);
420
+ }
421
+ }
422
+ for (let i = 0; i < count; i += 1) {
423
+ const refLayer = reader.readU16();
424
+ const refFeature = reader.readU32();
425
+ out.push(refLayer === 0xffff ? null : ctx.getObject(refLayer, refFeature, item));
426
+ }
427
+ return out;
428
+ }
429
+ function writeNumericListChunk(module, layer, ownerFeatureId, value, kind) {
430
+ const list = Array.isArray(value) ? value : [];
431
+ layer.addFeatureBegin();
432
+ layer.setFieldInt(0, ownerFeatureId);
433
+ let payload = new Uint8Array(0);
434
+ if (list.length > 0) {
435
+ if (kind === 'u32') {
436
+ const view = new DataView(new ArrayBuffer(list.length * 4));
437
+ list.forEach((entry, index) => {
438
+ const iv = Number(entry);
439
+ if (!Number.isInteger(iv) || iv < 0 || iv > 0xffffffff) {
440
+ throw new FastdbUsageError(`List[U32] item out of range: ${entry}`);
441
+ }
442
+ view.setUint32(index * 4, iv, true);
443
+ });
444
+ payload = new Uint8Array(view.buffer);
445
+ }
446
+ else {
447
+ const view = new DataView(new ArrayBuffer(list.length * 8));
448
+ list.forEach((entry, index) => {
449
+ view.setFloat64(index * 8, Number(entry), true);
450
+ });
451
+ payload = new Uint8Array(view.buffer);
452
+ }
453
+ }
454
+ if (payload.length > 0) {
455
+ withHeapBytes(module, payload, (ptr, size) => {
456
+ layer.setGeometryRaw(ptr, size);
457
+ });
458
+ }
459
+ layer.addFeatureEnd();
460
+ }
461
+ function loadNumericListValues(db, module) {
462
+ const out = new Map();
463
+ for (let layerIdx = 0; layerIdx < db.getLayerCount(); layerIdx += 1) {
464
+ const layer = db.getLayer(layerIdx);
465
+ const parsed = parseNumericListLayerName(layer.name());
466
+ if (!parsed) {
467
+ continue;
468
+ }
469
+ for (let rowIdx = 0; rowIdx < layer.getFeatureCount(); rowIdx += 1) {
470
+ const row = layer.tryGetFeatureAt(rowIdx);
471
+ const ownerFeatureId = row.getFieldAsInt(0);
472
+ const chunk = copyChunkToBytes(module, row.geometryView());
473
+ out.set(`${parsed.className}:${parsed.fieldName}:${ownerFeatureId}`, decodeNumericListChunk(chunk, parsed.kind));
474
+ }
475
+ }
476
+ return out;
477
+ }
478
+ function decodeNumericListChunk(chunk, kind) {
479
+ if (chunk.length === 0) {
480
+ return [];
481
+ }
482
+ const view = new DataView(chunk.buffer, chunk.byteOffset, chunk.byteLength);
483
+ const out = [];
484
+ const step = kind === 'u32' ? 4 : 8;
485
+ for (let offset = 0; offset < chunk.length; offset += step) {
486
+ out.push(kind === 'u32' ? view.getUint32(offset, true) : view.getFloat64(offset, true));
487
+ }
488
+ return out;
489
+ }
490
+ function makeNumericListLayerName(className, fieldName, kind) {
491
+ return `${NUMERIC_LIST_LAYER_PREFIX}${className}|${fieldName}|${kind}`;
492
+ }
493
+ function parseNumericListLayerName(layerName) {
494
+ if (!layerName.startsWith(NUMERIC_LIST_LAYER_PREFIX)) {
495
+ return null;
496
+ }
497
+ const parts = layerName.slice(NUMERIC_LIST_LAYER_PREFIX.length).split('|');
498
+ if (parts.length !== 3) {
499
+ return null;
500
+ }
501
+ const [className, fieldName, kind] = parts;
502
+ if (kind !== 'u32' && kind !== 'f64') {
503
+ return null;
504
+ }
505
+ return { className, fieldName, kind };
506
+ }
507
+ function normalizeBytes(value) {
508
+ if (value instanceof Uint8Array) {
509
+ return value;
510
+ }
511
+ if (value instanceof ArrayBuffer) {
512
+ return new Uint8Array(value);
513
+ }
514
+ return new Uint8Array(0);
515
+ }
516
+ function withHeapBytes(module, bytes, fn) {
517
+ if (bytes.length === 0) {
518
+ return fn(0, 0);
519
+ }
520
+ const ptr = module._malloc(bytes.length);
521
+ try {
522
+ module.HEAPU8.set(bytes, ptr);
523
+ return fn(ptr, bytes.length);
524
+ }
525
+ finally {
526
+ module._free(ptr);
527
+ }
528
+ }
529
+ function copyChunkToBytes(module, chunk) {
530
+ return module.HEAPU8.slice(chunk.data, chunk.data + chunk.size);
531
+ }
532
+ function isFieldType(value) {
533
+ return typeof value === 'object' && value !== null && 'kind' in value && 'originType' in value;
534
+ }
535
+ function getFeatureFieldValue(feature, fieldName) {
536
+ const cache = feature._cache;
537
+ if (cache && fieldName in cache) {
538
+ return cache[fieldName];
539
+ }
540
+ return feature[fieldName];
541
+ }
542
+ class ByteWriter {
543
+ chunks = [];
544
+ totalSize = 0;
545
+ writeU16(value) {
546
+ const bytes = new Uint8Array(2);
547
+ new DataView(bytes.buffer).setUint16(0, value, true);
548
+ this.push(bytes);
549
+ }
550
+ writeU32(value) {
551
+ const bytes = new Uint8Array(4);
552
+ new DataView(bytes.buffer).setUint32(0, value, true);
553
+ this.push(bytes);
554
+ }
555
+ writeI32(value) {
556
+ const bytes = new Uint8Array(4);
557
+ new DataView(bytes.buffer).setInt32(0, value, true);
558
+ this.push(bytes);
559
+ }
560
+ writeF64(value) {
561
+ const bytes = new Uint8Array(8);
562
+ new DataView(bytes.buffer).setFloat64(0, value, true);
563
+ this.push(bytes);
564
+ }
565
+ writeBytes(bytes) {
566
+ if (bytes.length === 0) {
567
+ return;
568
+ }
569
+ this.push(bytes);
570
+ }
571
+ finish() {
572
+ const out = new Uint8Array(this.totalSize);
573
+ let offset = 0;
574
+ for (const chunk of this.chunks) {
575
+ out.set(chunk, offset);
576
+ offset += chunk.length;
577
+ }
578
+ return out;
579
+ }
580
+ push(bytes) {
581
+ this.chunks.push(bytes);
582
+ this.totalSize += bytes.length;
583
+ }
584
+ }
585
+ class ByteReader {
586
+ bytes;
587
+ offset = 0;
588
+ constructor(bytes) {
589
+ this.bytes = bytes;
590
+ }
591
+ readU16() {
592
+ const value = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength).getUint16(this.offset, true);
593
+ this.offset += 2;
594
+ return value;
595
+ }
596
+ readU32() {
597
+ const value = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength).getUint32(this.offset, true);
598
+ this.offset += 4;
599
+ return value;
600
+ }
601
+ readI32() {
602
+ const value = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength).getInt32(this.offset, true);
603
+ this.offset += 4;
604
+ return value;
605
+ }
606
+ readF64() {
607
+ const value = new DataView(this.bytes.buffer, this.bytes.byteOffset, this.bytes.byteLength).getFloat64(this.offset, true);
608
+ this.offset += 8;
609
+ return value;
610
+ }
611
+ readBytes(size) {
612
+ const out = this.bytes.slice(this.offset, this.offset + size);
613
+ this.offset += size;
614
+ return out;
615
+ }
616
+ }
@@ -0,0 +1,22 @@
1
+ import { type Feature, type FeatureClass } from './feature.js';
2
+ import type { FastdbModule, WxDatabaseBuildHandle, WxDatabaseHandle, WxLayerTableBuildHandle, WxLayerTableHandle } from './wasm-loader.js';
3
+ type TableOrigin = WxLayerTableHandle | WxLayerTableBuildHandle;
4
+ type DatabaseOrigin = WxDatabaseHandle | WxDatabaseBuildHandle;
5
+ export declare class Table<T extends Feature> {
6
+ readonly featureType: FeatureClass<T>;
7
+ readonly origin: TableOrigin;
8
+ readonly db: DatabaseOrigin;
9
+ readonly module: FastdbModule;
10
+ private columnAccessor;
11
+ constructor(featureType: FeatureClass<T>, origin: TableOrigin, db: DatabaseOrigin, module: FastdbModule);
12
+ get length(): number;
13
+ get fixed(): boolean;
14
+ get name(): string;
15
+ get(index: number): T;
16
+ get column(): T;
17
+ [Symbol.iterator](): Iterator<T>;
18
+ iterReuse(): Iterator<T>;
19
+ fill(columns: Record<string, ArrayLike<number>>): void;
20
+ private normalizeIndex;
21
+ }
22
+ export {};