fastdb4ts 0.0.1 → 0.0.3
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 +26 -7
- package/dist/call-db.d.ts +117 -0
- package/dist/call-db.js +1857 -0
- package/dist/column.d.ts +1 -0
- package/dist/column.js +39 -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 +53 -8
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/orm.d.ts +8 -1
- package/dist/orm.js +147 -28
- package/dist/serializer.d.ts +28 -1
- package/dist/serializer.js +142 -72
- 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 +12 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Browser-oriented TypeScript bindings for `fastdb`, powered by WebAssembly.
|
|
4
4
|
|
|
5
|
-
`fastdb4ts` brings the `fastdb` storage model to TypeScript with a browser-first API centered around typed schemas, structured table access, binary buffer transport
|
|
5
|
+
`fastdb4ts` brings the `fastdb` storage model to TypeScript with a browser-first API centered around typed schemas, structured table access, and binary buffer transport.
|
|
6
6
|
|
|
7
7
|
## What this package provides
|
|
8
8
|
|
|
@@ -12,8 +12,8 @@ Browser-oriented TypeScript bindings for `fastdb`, powered by WebAssembly.
|
|
|
12
12
|
- use `ORM`, `TableDefn`, `Table`, and column accessors
|
|
13
13
|
- **Binary buffer roundtrips**
|
|
14
14
|
- import/export databases as `Uint8Array` / `ArrayBuffer`
|
|
15
|
-
- **
|
|
16
|
-
-
|
|
15
|
+
- **Legacy graph serialization**
|
|
16
|
+
- `FastSerializer` remains available for existing nested-feature and cyclic-reference users, but new cross-runtime provider work should use neutral schema descriptors and explicit codec profiles
|
|
17
17
|
- **Shared native semantics**
|
|
18
18
|
- backed by the same C++ core as `fastdb4py`
|
|
19
19
|
|
|
@@ -26,7 +26,7 @@ Included:
|
|
|
26
26
|
- browser-first WASM runtime
|
|
27
27
|
- `Feature` + `defineSchema(...)`
|
|
28
28
|
- `ORM`, `TableDefn`, `Table`, column access
|
|
29
|
-
- `FastSerializer`
|
|
29
|
+
- `FastSerializer` legacy compatibility APIs
|
|
30
30
|
- `Uint8Array` / `ArrayBuffer` import/export
|
|
31
31
|
|
|
32
32
|
Not included in the current TS package:
|
|
@@ -81,6 +81,8 @@ console.log(table.get(1).x); // 2.5
|
|
|
81
81
|
|
|
82
82
|
Unlike `fastdb4py`, the TypeScript package uses explicit schema definitions rather than Python annotations.
|
|
83
83
|
|
|
84
|
+
You can write these schemas by hand, or **auto-generate them** from Python Feature classes using the `fdb codegen` CLI (see [Generating schemas from Python](#generating-schemas-from-python) below).
|
|
85
|
+
|
|
84
86
|
```ts
|
|
85
87
|
import {
|
|
86
88
|
F64,
|
|
@@ -157,9 +159,9 @@ const copyTable = copy.table(Particle);
|
|
|
157
159
|
console.log(copyTable.get(2).x); // 2.0
|
|
158
160
|
```
|
|
159
161
|
|
|
160
|
-
## FastSerializer
|
|
162
|
+
## FastSerializer Legacy Compatibility
|
|
161
163
|
|
|
162
|
-
`FastSerializer` is the graph-oriented layer for feature graphs that are more naturally represented as nested objects than flat tables.
|
|
164
|
+
`FastSerializer` is the legacy graph-oriented layer for feature graphs that are more naturally represented as nested objects than flat tables. It remains available for compatibility and migration tests, but it is not the foundation for new C-Two provider work.
|
|
163
165
|
|
|
164
166
|
Supported scenarios include:
|
|
165
167
|
|
|
@@ -259,6 +261,24 @@ Serializer interop validation is also available:
|
|
|
259
261
|
npm --prefix ts/fastdb4ts run test:serializer:interop
|
|
260
262
|
```
|
|
261
263
|
|
|
264
|
+
## Generating schemas from Python
|
|
265
|
+
|
|
266
|
+
If you define your canonical Feature classes in Python (`fastdb4py`), you can generate the equivalent TypeScript schemas automatically using the `fdb codegen` CLI:
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
pip install fastdb4py
|
|
270
|
+
fdb codegen --ts ./python_features/ ./ts_features/
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
This generates one `.ts` file per `.py` file, with:
|
|
274
|
+
|
|
275
|
+
- all field types mapped (`F64`, `STR`, `ref(...)`, `listOf(...)`, etc.)
|
|
276
|
+
- cross-file imports resolved to relative paths
|
|
277
|
+
- circular references using lazy refs `ref(() => ClassName)`
|
|
278
|
+
- topological class ordering within each file
|
|
279
|
+
|
|
280
|
+
See the [Python binding README](../../python/README.md) for full codegen documentation.
|
|
281
|
+
|
|
262
282
|
## Repository documentation
|
|
263
283
|
|
|
264
284
|
For fuller project documentation, see:
|
|
@@ -267,4 +287,3 @@ For fuller project documentation, see:
|
|
|
267
287
|
- TypeScript/WASM binding guide: [`ts/README.md`](../README.md)
|
|
268
288
|
- C++ core guide: [`fastcarto/README.md`](../../fastcarto/README.md)
|
|
269
289
|
- Python binding guide: [`python/README.md`](../../python/README.md)
|
|
270
|
-
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Feature, type FeatureClass } from './feature.js';
|
|
2
|
+
import { ORM } from './orm.js';
|
|
3
|
+
import { type FastdbDatabaseBytes } from './database-buffer.js';
|
|
4
|
+
import type { StridedColumn } from './column.js';
|
|
5
|
+
import { type FastdbModule, type WxDatabaseHandle } from './wasm-loader.js';
|
|
6
|
+
export interface FastdbFeatureCodecBinding<T extends Feature = Feature> {
|
|
7
|
+
readonly codecId: string;
|
|
8
|
+
readonly profile: string;
|
|
9
|
+
readonly schemaSha256: string;
|
|
10
|
+
readonly feature: FeatureClass<T>;
|
|
11
|
+
}
|
|
12
|
+
export interface FastdbCallDbScalarField {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly kind: string;
|
|
15
|
+
readonly parameter?: string;
|
|
16
|
+
readonly valuePosition: number;
|
|
17
|
+
}
|
|
18
|
+
export interface FastdbCallDbArrayItem {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly kind: string;
|
|
21
|
+
}
|
|
22
|
+
export interface FastdbCallDbFeatureDependency {
|
|
23
|
+
readonly feature: FeatureClass;
|
|
24
|
+
readonly featureSchemaSha256: string;
|
|
25
|
+
}
|
|
26
|
+
export interface FastdbCallDbTable {
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly kind: 'scalars' | 'array' | 'feature';
|
|
29
|
+
readonly cardinality: string;
|
|
30
|
+
readonly feature?: FeatureClass;
|
|
31
|
+
readonly featureSchemaSha256?: string;
|
|
32
|
+
readonly featureDependencies?: readonly FastdbCallDbFeatureDependency[];
|
|
33
|
+
readonly parameter?: string;
|
|
34
|
+
readonly returnIndex?: number;
|
|
35
|
+
readonly valuePosition?: number;
|
|
36
|
+
readonly fields?: readonly FastdbCallDbScalarField[];
|
|
37
|
+
readonly item?: FastdbCallDbArrayItem;
|
|
38
|
+
}
|
|
39
|
+
export interface FastdbCallDbBinding {
|
|
40
|
+
readonly codecId: string;
|
|
41
|
+
readonly profile: string;
|
|
42
|
+
readonly schemaSha256: string;
|
|
43
|
+
readonly method: string;
|
|
44
|
+
readonly direction: 'input' | 'output';
|
|
45
|
+
readonly tables: readonly FastdbCallDbTable[];
|
|
46
|
+
}
|
|
47
|
+
export declare function encodeFastdbFeature<T extends Feature>(binding: FastdbFeatureCodecBinding<T>, value: T): Uint8Array;
|
|
48
|
+
export declare function decodeFastdbFeature<T extends Feature>(binding: FastdbFeatureCodecBinding<T>, payload: FastdbDatabaseBytes): T;
|
|
49
|
+
export declare function encodeFastdbCallDb(binding: FastdbCallDbBinding, value: unknown): Uint8Array;
|
|
50
|
+
export declare function decodeFastdbCallDb(binding: FastdbCallDbBinding, payload: FastdbDatabaseBytes): unknown;
|
|
51
|
+
export declare function viewFastdbCallDb(binding: FastdbCallDbBinding, payload: FastdbDatabaseBytes): FastdbCallDbView;
|
|
52
|
+
export declare class FastdbCallDbView {
|
|
53
|
+
readonly binding: FastdbCallDbBinding;
|
|
54
|
+
private readonly storage;
|
|
55
|
+
private closed;
|
|
56
|
+
private readonly mode;
|
|
57
|
+
constructor(binding: FastdbCallDbBinding, storage: ORM | ObjectGraphLoadContext);
|
|
58
|
+
materialize(): unknown;
|
|
59
|
+
table(nameOrIndex: string | number): FastdbCallDbTableView;
|
|
60
|
+
feature(nameOrIndex: string | number): Feature;
|
|
61
|
+
array(nameOrIndex: string | number): FastdbCallDbArrayView;
|
|
62
|
+
scalar(nameOrIndex: string | number): unknown;
|
|
63
|
+
close(): void;
|
|
64
|
+
ensureOpen(): void;
|
|
65
|
+
tableLength(spec: FastdbCallDbTable): number;
|
|
66
|
+
tableFeature(spec: FastdbCallDbTable, index: number): Feature;
|
|
67
|
+
arrayValue(spec: FastdbCallDbTable, index: number): unknown;
|
|
68
|
+
tableColumn(spec: FastdbCallDbTable, fieldName: string): FastdbCallDbColumnSource | undefined;
|
|
69
|
+
private tableFor;
|
|
70
|
+
private objectGraphLayerIndex;
|
|
71
|
+
private orm;
|
|
72
|
+
private objectGraphContext;
|
|
73
|
+
private resolveTable;
|
|
74
|
+
private resolveScalarField;
|
|
75
|
+
}
|
|
76
|
+
type FastdbCallDbColumnArray = ReturnType<StridedColumn['toArray']> | unknown[];
|
|
77
|
+
interface FastdbCallDbColumnSource {
|
|
78
|
+
readonly length: number;
|
|
79
|
+
get(index: number): unknown;
|
|
80
|
+
toArray(): FastdbCallDbColumnArray;
|
|
81
|
+
forEach(fn: (value: unknown, index: number) => void): void;
|
|
82
|
+
}
|
|
83
|
+
export declare class FastdbCallDbTableView {
|
|
84
|
+
private readonly view;
|
|
85
|
+
private readonly spec;
|
|
86
|
+
private columnAccessor;
|
|
87
|
+
constructor(view: FastdbCallDbView, spec: FastdbCallDbTable);
|
|
88
|
+
get length(): number;
|
|
89
|
+
get column(): Record<string, FastdbCallDbColumnView>;
|
|
90
|
+
get(index: number): Feature;
|
|
91
|
+
[Symbol.iterator](): Iterator<Feature>;
|
|
92
|
+
}
|
|
93
|
+
export declare class FastdbCallDbArrayView {
|
|
94
|
+
private readonly view;
|
|
95
|
+
private readonly spec;
|
|
96
|
+
constructor(view: FastdbCallDbView, spec: FastdbCallDbTable);
|
|
97
|
+
get length(): number;
|
|
98
|
+
get(index: number): unknown;
|
|
99
|
+
toArray(): unknown[];
|
|
100
|
+
[Symbol.iterator](): Iterator<unknown>;
|
|
101
|
+
}
|
|
102
|
+
export declare class FastdbCallDbColumnView {
|
|
103
|
+
private readonly view;
|
|
104
|
+
private readonly column;
|
|
105
|
+
constructor(view: FastdbCallDbView, column: FastdbCallDbColumnSource);
|
|
106
|
+
get length(): number;
|
|
107
|
+
get(index: number): unknown;
|
|
108
|
+
toArray(): FastdbCallDbColumnArray;
|
|
109
|
+
forEach(fn: (value: unknown, index: number) => void): void;
|
|
110
|
+
}
|
|
111
|
+
interface ObjectGraphLoadContext {
|
|
112
|
+
readonly db: WxDatabaseHandle;
|
|
113
|
+
readonly module: FastdbModule;
|
|
114
|
+
readonly typeByLayerName: ReadonlyMap<string, FeatureClass>;
|
|
115
|
+
readonly seen: Map<string, Feature>;
|
|
116
|
+
}
|
|
117
|
+
export {};
|