@n-dream/builders-sdk 1.0.0-next.0 → 1.4.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 +104 -7
- package/dist/auth.d.ts +25 -0
- package/dist/auth.js +159 -0
- package/dist/data.d.ts +3 -0
- package/dist/data.js +4 -0
- package/dist/db.d.ts +125 -0
- package/dist/db.js +581 -0
- package/dist/declared.d.ts +1 -0
- package/dist/declared.js +5 -0
- package/dist/engine.d.ts +236 -0
- package/dist/engine.js +981 -0
- package/dist/errors.d.ts +4 -1
- package/dist/errors.js +22 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -2
- package/dist/local-db.d.ts +15 -0
- package/dist/local-db.js +396 -0
- package/dist/local.d.ts +13 -0
- package/dist/local.js +70 -0
- package/dist/memory-storage.d.ts +55 -0
- package/dist/memory-storage.js +276 -0
- package/dist/rules.d.ts +219 -0
- package/dist/rules.js +768 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +6 -0
- package/dist/session.d.ts +5 -0
- package/dist/session.js +18 -0
- package/dist/testing.d.ts +14 -0
- package/dist/testing.js +50 -0
- package/dist/vite.d.ts +21 -0
- package/dist/vite.js +46 -0
- package/package.json +20 -2
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { type CollectionRule, type DataDeclaration, type DataLimits, type FileOut, type ItemOut, type LoginMode, type Ns, type Order, type Preset, type RuleError, type Viewer } from "./rules.js";
|
|
2
|
+
export declare const SERVER_TIME: Readonly<{
|
|
3
|
+
serverTime: true;
|
|
4
|
+
}>;
|
|
5
|
+
export declare const DELETE_FIELD: Readonly<{
|
|
6
|
+
deleteField: true;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const TIME_FIELDS: readonly ["createdAt", "updatedAt", "at", "removedAt", "resetAt", "expireAt"];
|
|
9
|
+
export type Stored = Record<string, unknown>;
|
|
10
|
+
export interface Row {
|
|
11
|
+
id: string;
|
|
12
|
+
data: Stored;
|
|
13
|
+
}
|
|
14
|
+
export interface StorageTx {
|
|
15
|
+
get(path: string): Promise<Stored | null>;
|
|
16
|
+
set(path: string, data: Stored, opts?: {
|
|
17
|
+
merge?: boolean;
|
|
18
|
+
}): void;
|
|
19
|
+
delete(path: string): void;
|
|
20
|
+
}
|
|
21
|
+
export interface StorageQuery {
|
|
22
|
+
ns: Ns;
|
|
23
|
+
scope: string;
|
|
24
|
+
owner?: string;
|
|
25
|
+
f1?: string;
|
|
26
|
+
f2?: string;
|
|
27
|
+
order: Order;
|
|
28
|
+
direction: "asc" | "desc";
|
|
29
|
+
limit: number;
|
|
30
|
+
after: [number | string, string] | null;
|
|
31
|
+
}
|
|
32
|
+
export interface DataStorage {
|
|
33
|
+
transaction<T>(fn: (tx: StorageTx) => Promise<T>): Promise<T>;
|
|
34
|
+
get(path: string): Promise<Stored | null>;
|
|
35
|
+
query(space: string, q: StorageQuery): Promise<{
|
|
36
|
+
rows: Row[];
|
|
37
|
+
readUs: number;
|
|
38
|
+
}>;
|
|
39
|
+
count(space: string, q: Omit<StorageQuery, "limit" | "after" | "direction" | "order">, max: number): Promise<number>;
|
|
40
|
+
changes(space: string, ns: Ns, scope: string, sinceUs: number, limit: number): Promise<{
|
|
41
|
+
rows: Row[];
|
|
42
|
+
removed: Row[];
|
|
43
|
+
readUs: number;
|
|
44
|
+
}>;
|
|
45
|
+
setMarker(path: string, removed: boolean): Promise<number>;
|
|
46
|
+
docsByPrefix(space: string, prefix: string, after: string | null, limit: number, sub?: "docs" | "files" | "marks"): Promise<Row[]>;
|
|
47
|
+
countByPrefix(space: string, prefix: string, max: number, sub?: "docs" | "files"): Promise<number>;
|
|
48
|
+
docsOfUser(space: string, uid: string, after: string | null, limit: number, sub?: "docs" | "files"): Promise<Row[]>;
|
|
49
|
+
listSub(space: string, sub: "marks" | "usage" | "colls" | "jobs", after: string | null, limit: number): Promise<Row[]>;
|
|
50
|
+
resetSpace(space: string): Promise<void>;
|
|
51
|
+
purgeSpace(space: string): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
export interface BlobStorage {
|
|
54
|
+
write(name: string, body: AsyncIterable<Uint8Array>, type: string): Promise<boolean>;
|
|
55
|
+
delete(name: string): Promise<void>;
|
|
56
|
+
exists(name: string): Promise<boolean>;
|
|
57
|
+
deletePrefix(prefix: string): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
export declare const spaceKey: (appId: string, space: "live" | "test") => string;
|
|
60
|
+
export declare const paths: {
|
|
61
|
+
doc: (key: string, docId: string) => string;
|
|
62
|
+
removed: (key: string, docId: string) => string;
|
|
63
|
+
mark: (key: string, ns: Ns, scope: string) => string;
|
|
64
|
+
colls: (key: string, ns: Ns, coll: string) => string;
|
|
65
|
+
usage: (key: string, uid: string) => string;
|
|
66
|
+
fileUsage: (key: string, uid: string) => string;
|
|
67
|
+
appUsage: (key: string) => string;
|
|
68
|
+
file: (key: string, docId: string) => string;
|
|
69
|
+
ownerUsage: (ownerId: string) => string;
|
|
70
|
+
};
|
|
71
|
+
export declare const ownerKey: (ownerId: string) => string;
|
|
72
|
+
export declare class RuleFailure extends Error {
|
|
73
|
+
readonly rule: RuleError;
|
|
74
|
+
constructor(rule: RuleError);
|
|
75
|
+
}
|
|
76
|
+
export declare function countedDelta(e: unknown): UsageDelta | null;
|
|
77
|
+
export interface AppTotals {
|
|
78
|
+
mBytes: number;
|
|
79
|
+
pItems: number;
|
|
80
|
+
pBytes: number;
|
|
81
|
+
fBytes: number;
|
|
82
|
+
}
|
|
83
|
+
export interface Ctx {
|
|
84
|
+
appId: string;
|
|
85
|
+
space: "live" | "test";
|
|
86
|
+
decl: DataDeclaration | null;
|
|
87
|
+
viewer: Viewer | null;
|
|
88
|
+
loginMode: LoginMode;
|
|
89
|
+
limits: DataLimits;
|
|
90
|
+
appTotals?: () => Promise<AppTotals>;
|
|
91
|
+
ownerFileBytes?: () => Promise<number>;
|
|
92
|
+
}
|
|
93
|
+
export interface Cost {
|
|
94
|
+
reads: number;
|
|
95
|
+
writes: number;
|
|
96
|
+
}
|
|
97
|
+
export interface UsageDelta {
|
|
98
|
+
ns: Ns | "f";
|
|
99
|
+
items: number;
|
|
100
|
+
bytes: number;
|
|
101
|
+
}
|
|
102
|
+
export interface WriteResult {
|
|
103
|
+
item: ItemOut | null;
|
|
104
|
+
marker: {
|
|
105
|
+
path: string;
|
|
106
|
+
removed: boolean;
|
|
107
|
+
} | null;
|
|
108
|
+
delta: UsageDelta | null;
|
|
109
|
+
cost: Cost;
|
|
110
|
+
}
|
|
111
|
+
export interface Usage {
|
|
112
|
+
items: number;
|
|
113
|
+
bytes: number;
|
|
114
|
+
}
|
|
115
|
+
export interface FileWriteResult {
|
|
116
|
+
file: FileOut;
|
|
117
|
+
delta: UsageDelta;
|
|
118
|
+
cost: Cost;
|
|
119
|
+
}
|
|
120
|
+
export type Changes = {
|
|
121
|
+
resync: true;
|
|
122
|
+
cost: Cost;
|
|
123
|
+
} | {
|
|
124
|
+
resync: false;
|
|
125
|
+
items: ItemOut[];
|
|
126
|
+
removed: string[];
|
|
127
|
+
cursor: number;
|
|
128
|
+
cost: Cost;
|
|
129
|
+
};
|
|
130
|
+
export declare const SERVER_TIME_MARGIN_US = 1000000;
|
|
131
|
+
export interface EngineDeps {
|
|
132
|
+
storage: DataStorage;
|
|
133
|
+
now: () => number;
|
|
134
|
+
randomId: () => string;
|
|
135
|
+
instance: string;
|
|
136
|
+
}
|
|
137
|
+
export declare class DataEngine {
|
|
138
|
+
private readonly d;
|
|
139
|
+
private readonly colls;
|
|
140
|
+
private readonly running;
|
|
141
|
+
constructor(d: EngineDeps);
|
|
142
|
+
idle(): Promise<void>;
|
|
143
|
+
private rule;
|
|
144
|
+
private key;
|
|
145
|
+
private out;
|
|
146
|
+
get(ctx: Ctx, coll: string, rawId: unknown): Promise<{
|
|
147
|
+
item: ItemOut | null;
|
|
148
|
+
cost: Cost;
|
|
149
|
+
}>;
|
|
150
|
+
private planRead;
|
|
151
|
+
list(ctx: Ctx, coll: string, raw: unknown): Promise<{
|
|
152
|
+
items: ItemOut[];
|
|
153
|
+
next: string | null;
|
|
154
|
+
readUs: number;
|
|
155
|
+
cost: Cost;
|
|
156
|
+
}>;
|
|
157
|
+
count(ctx: Ctx, coll: string, raw: unknown): Promise<{
|
|
158
|
+
count: number;
|
|
159
|
+
cost: Cost;
|
|
160
|
+
}>;
|
|
161
|
+
watchTarget(ctx: Ctx, coll: string): {
|
|
162
|
+
path: string;
|
|
163
|
+
access: Preset;
|
|
164
|
+
};
|
|
165
|
+
changes(ctx: Ctx, coll: string, cursorUs: number): Promise<Changes>;
|
|
166
|
+
add(ctx: Ctx, coll: string, data: unknown): Promise<WriteResult>;
|
|
167
|
+
set(ctx: Ctx, coll: string, rawId: unknown, data: unknown, ifRev?: unknown): Promise<WriteResult>;
|
|
168
|
+
update(ctx: Ctx, coll: string, rawId: unknown, patch: unknown, ifRev?: unknown): Promise<WriteResult>;
|
|
169
|
+
private writeRef;
|
|
170
|
+
private write;
|
|
171
|
+
remove(ctx: Ctx, coll: string, rawId: unknown): Promise<WriteResult>;
|
|
172
|
+
usage(ctx: Ctx): Promise<{
|
|
173
|
+
bytes: number;
|
|
174
|
+
bytesLimit: number;
|
|
175
|
+
fileBytes: number;
|
|
176
|
+
fileBytesLimit: number;
|
|
177
|
+
cost: Cost;
|
|
178
|
+
}>;
|
|
179
|
+
fileUser(ctx: Ctx, set: unknown): {
|
|
180
|
+
set: string;
|
|
181
|
+
uid: string;
|
|
182
|
+
};
|
|
183
|
+
private fileOut;
|
|
184
|
+
private fileRoom;
|
|
185
|
+
upload(ctx: Ctx, rawSet: unknown, meta: {
|
|
186
|
+
name?: unknown;
|
|
187
|
+
type?: unknown;
|
|
188
|
+
size?: number | null;
|
|
189
|
+
}, body: AsyncIterable<Uint8Array>, blobs: BlobStorage): Promise<FileWriteResult>;
|
|
190
|
+
private dropBytes;
|
|
191
|
+
listFiles(ctx: Ctx, rawSet: unknown, raw: unknown): Promise<{
|
|
192
|
+
files: FileOut[];
|
|
193
|
+
next: string | null;
|
|
194
|
+
cost: Cost;
|
|
195
|
+
}>;
|
|
196
|
+
file(ctx: Ctx, rawSet: unknown, rawId: unknown): Promise<{
|
|
197
|
+
file: FileOut;
|
|
198
|
+
object: string;
|
|
199
|
+
cost: Cost;
|
|
200
|
+
}>;
|
|
201
|
+
removeFile(ctx: Ctx, rawSet: unknown, rawId: unknown, blobs: BlobStorage): Promise<{
|
|
202
|
+
delta: UsageDelta | null;
|
|
203
|
+
cost: Cost;
|
|
204
|
+
}>;
|
|
205
|
+
indexState(ctx: Ctx, coll: string, rule: CollectionRule): Promise<"ready" | "preparing">;
|
|
206
|
+
private kick;
|
|
207
|
+
private reindex;
|
|
208
|
+
}
|
|
209
|
+
export declare function fileRecordDelta(storage: DataStorage, key: string, docId: string, opts?: {
|
|
210
|
+
nonce?: string;
|
|
211
|
+
counts?: string[];
|
|
212
|
+
}): Promise<UsageDelta>;
|
|
213
|
+
export declare const DELETE_BATCH = 100;
|
|
214
|
+
export declare const DELETE_PARALLEL = 16;
|
|
215
|
+
export declare function eachParallel<T>(items: readonly T[], n: number, fn: (x: T) => Promise<void>): Promise<void>;
|
|
216
|
+
export declare function deleteFiles(storage: DataStorage, key: string, docIds: readonly string[], counts?: readonly string[], onlyIf?: (rec: Stored) => boolean): Promise<UsageDelta>;
|
|
217
|
+
export declare function deleteItems(storage: DataStorage, key: string, docIds: readonly string[], opts: {
|
|
218
|
+
log: boolean;
|
|
219
|
+
nowUs: number;
|
|
220
|
+
onlyIf?: (doc: Stored) => boolean;
|
|
221
|
+
}): Promise<{
|
|
222
|
+
items: number;
|
|
223
|
+
markers: string[];
|
|
224
|
+
}>;
|
|
225
|
+
export declare function restoreItems(storage: DataStorage, key: string, rows: readonly Row[]): Promise<{
|
|
226
|
+
items: number;
|
|
227
|
+
markers: string[];
|
|
228
|
+
}>;
|
|
229
|
+
export declare function restoreFiles(storage: DataStorage, key: string, rows: readonly Row[], counts?: readonly string[]): Promise<UsageDelta>;
|
|
230
|
+
export declare function emptySpace(storage: DataStorage, key: string, nowUs: number): Promise<number>;
|
|
231
|
+
export declare function dropFileRecords(storage: DataStorage, key: string, prefix: string, counts: readonly string[]): Promise<UsageDelta>;
|
|
232
|
+
export declare function resetTestSpace(storage: DataStorage, blobs: BlobStorage, appId: string, ownerId: string, hooks?: {
|
|
233
|
+
step?: (name: string) => Promise<void>;
|
|
234
|
+
nowUs?: number;
|
|
235
|
+
}): Promise<UsageDelta>;
|
|
236
|
+
export declare function randomItemId(): string;
|