@jarenjs/db 0.46.4 → 0.46.5
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 +9 -0
- package/package.json +4 -4
- package/types/index.d.ts +53 -11
- package/types/typed.d.ts +4 -4
package/README.md
CHANGED
|
@@ -56,6 +56,15 @@ const adults = await users.execute({
|
|
|
56
56
|
});
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
`execute` answers in the ENGINE's result shape (QUERY-FORMAT §1,
|
|
60
|
+
"singleton ≡ item"): `undefined` for no rows, the document itself for
|
|
61
|
+
exactly one, an array for more — typed `SequenceResult<R>`, with `R`
|
|
62
|
+
stated per call (`users.execute<User>(…)`) because only the caller
|
|
63
|
+
knows what its `$return` produces. `query()` answers the same document
|
|
64
|
+
as an item cursor (`for await`), one item per pull and never unwrapped —
|
|
65
|
+
the read to use when an item may itself be an array. The handle's own
|
|
66
|
+
shape binds at `store.collection<User>('users')`.
|
|
67
|
+
|
|
59
68
|
- **The pushdown planner with `explain()`.** A query compiles through
|
|
60
69
|
the engine's published AST into a dialect-neutral plan and renders
|
|
61
70
|
to guarded, parameter-bound SQL; whatever cannot be proven
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jarenjs/db",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.46.
|
|
4
|
+
"version": "0.46.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"types": "./types/index.d.ts",
|
|
@@ -71,9 +71,9 @@
|
|
|
71
71
|
"prepack": "npm run build:types"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@jarenjs/core": "^0.46.
|
|
75
|
-
"@jarenjs/json": "^0.46.
|
|
76
|
-
"@jarenjs/validate": "^0.46.
|
|
74
|
+
"@jarenjs/core": "^0.46.5",
|
|
75
|
+
"@jarenjs/json": "^0.46.5",
|
|
76
|
+
"@jarenjs/validate": "^0.46.5"
|
|
77
77
|
},
|
|
78
78
|
"bin": {
|
|
79
79
|
"jaren-db": "./src/cli.js"
|
package/types/index.d.ts
CHANGED
|
@@ -48,6 +48,35 @@ export declare class DbRuntimeError extends Error {
|
|
|
48
48
|
/** A single-column key, or the `{ prop: value, … }` composite form. */
|
|
49
49
|
export type EntityKeyArg = string | number | Readonly<Record<string, string | number>>;
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* What `execute` answers: the ENGINE's result shape (QUERY-FORMAT §1,
|
|
53
|
+
* "singleton ≡ item"). The empty sequence is `undefined`, a sequence of
|
|
54
|
+
* exactly one item IS that item, and anything longer is an array. A
|
|
55
|
+
* single array-valued item is therefore indistinguishable from many
|
|
56
|
+
* items — a consumer whose items may themselves be arrays reads them
|
|
57
|
+
* through `query()`, which answers one item per pull and never
|
|
58
|
+
* unwraps.
|
|
59
|
+
*/
|
|
60
|
+
export type SequenceResult<T = unknown> = T[] | T | undefined;
|
|
61
|
+
|
|
62
|
+
/** The D2 provider contract: a synchronous driver answers the value
|
|
63
|
+
* itself and an asynchronous one a promise of it, so a linq chain over
|
|
64
|
+
* a synchronous driver stays synchronous; `await` reads both. */
|
|
65
|
+
export type ValueOrPromise<T> = T | Promise<T>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The item cursor `query()` answers: one result item per `next()`,
|
|
69
|
+
* never singleton-unwrapped, so `for await` walks a result whose
|
|
70
|
+
* shape `SequenceResult` cannot say. `return()` releases the
|
|
71
|
+
* underlying statement early. Native and row modes stream row by row;
|
|
72
|
+
* a set residual materializes first (a barrier `explain()` names).
|
|
73
|
+
*/
|
|
74
|
+
export interface QueryCursor<T = unknown> {
|
|
75
|
+
next(): Promise<IteratorResult<T, undefined>>;
|
|
76
|
+
return(): Promise<IteratorResult<T, undefined>>;
|
|
77
|
+
[Symbol.asyncIterator](): QueryCursor<T>;
|
|
78
|
+
}
|
|
79
|
+
|
|
51
80
|
export interface ExecuteOptions {
|
|
52
81
|
externals?: Readonly<Record<string, unknown>>;
|
|
53
82
|
strict?: boolean;
|
|
@@ -126,10 +155,15 @@ export interface Collection<T = unknown> {
|
|
|
126
155
|
put(doc: T, key?: string | number): Promise<string | number>;
|
|
127
156
|
patch(key: string | number, ops: readonly unknown[]): Promise<T>;
|
|
128
157
|
delete(key: string | number): Promise<boolean>;
|
|
129
|
-
/**
|
|
130
|
-
*
|
|
131
|
-
|
|
132
|
-
|
|
158
|
+
/** Run a query document and answer in the engine's result shape.
|
|
159
|
+
* `R` is what the document's `$return` produces — a document, a
|
|
160
|
+
* projected value, an aggregate's number — and only the caller knows
|
|
161
|
+
* it, so it is stated per call and defaults to `unknown` rather than
|
|
162
|
+
* to a guess. The D2 provider: value-or-promise so a linq chain over
|
|
163
|
+
* a synchronous driver stays synchronous. */
|
|
164
|
+
execute<R = unknown>(document: unknown, options?: ExecuteOptions): ValueOrPromise<SequenceResult<R>>;
|
|
165
|
+
/** The same document as an item cursor — one item per pull. */
|
|
166
|
+
query<R = unknown>(document: unknown, options?: ExecuteOptions): QueryCursor<R>;
|
|
133
167
|
explain(document: unknown, options?: ExecuteOptions): Promise<unknown>;
|
|
134
168
|
/** Register a live query (LIVE-FORMAT §7); requires capture. */
|
|
135
169
|
live(document: unknown, options?: LiveOptions): Promise<LiveQuery>;
|
|
@@ -142,7 +176,7 @@ export interface SyncCollection<T = unknown> {
|
|
|
142
176
|
put(doc: T, key?: string | number): string | number;
|
|
143
177
|
patch(key: string | number, ops: readonly unknown[]): T;
|
|
144
178
|
delete(key: string | number): boolean;
|
|
145
|
-
execute(document: unknown, options?: ExecuteOptions):
|
|
179
|
+
execute<R = unknown>(document: unknown, options?: ExecuteOptions): SequenceResult<R>;
|
|
146
180
|
explain(document: unknown, options?: ExecuteOptions): unknown;
|
|
147
181
|
}
|
|
148
182
|
|
|
@@ -193,10 +227,12 @@ export interface SyncEntitySet<T = unknown, I = unknown> {
|
|
|
193
227
|
// ————— the store —————
|
|
194
228
|
|
|
195
229
|
export interface SyncStore {
|
|
196
|
-
collection
|
|
230
|
+
/** `T` is the collection's document shape — the model's schema in
|
|
231
|
+
* the consumer's words; the handle's writes take it and reads answer it. */
|
|
232
|
+
collection<T = unknown>(name: string): SyncCollection<T>;
|
|
197
233
|
entity(name: string): SyncEntitySet;
|
|
198
234
|
transaction<R>(fn: (store: Store) => R): R;
|
|
199
|
-
execute
|
|
235
|
+
execute?<R = unknown>(document: unknown, options?: ExecuteOptions): SequenceResult<R>;
|
|
200
236
|
saveChanges?(): SaveReport;
|
|
201
237
|
}
|
|
202
238
|
|
|
@@ -204,11 +240,14 @@ export interface Store {
|
|
|
204
240
|
readonly capabilities: StoreCapabilities;
|
|
205
241
|
readonly dialect: Dialect;
|
|
206
242
|
stats(): StoreStats;
|
|
207
|
-
collection
|
|
243
|
+
/** `T` is the collection's document shape — the model's schema in
|
|
244
|
+
* the consumer's words; the handle's writes take it and reads answer it. */
|
|
245
|
+
collection<T = unknown>(name: string): Collection<T>;
|
|
208
246
|
entity(name: string): EntitySet;
|
|
209
247
|
/** Entity documents over the multi-entity root (§10.1); present
|
|
210
|
-
* only when the model declares entities. Value-or-promise (D2)
|
|
211
|
-
|
|
248
|
+
* only when the model declares entities. Value-or-promise (D2),
|
|
249
|
+
* in the engine's result shape. */
|
|
250
|
+
execute?<R = unknown>(document: unknown, options?: ExecuteOptions): ValueOrPromise<SequenceResult<R>>;
|
|
212
251
|
explain?(document: unknown, options?: ExecuteOptions): Promise<unknown>;
|
|
213
252
|
/** The unit of work (§11); present only with entities. */
|
|
214
253
|
saveChanges?(): Promise<SaveReport>;
|
|
@@ -222,7 +261,10 @@ export interface Store {
|
|
|
222
261
|
/** Register a live query over an entity-root document (re-run
|
|
223
262
|
* strategy in this version); present only with entities. */
|
|
224
263
|
live?(document: unknown, options?: LiveOptions): Promise<LiveQuery>;
|
|
225
|
-
|
|
264
|
+
/** Close the store. Job workers are asked to stop and given
|
|
265
|
+
* `graceMs` to wind up; the connection closes whether or not they
|
|
266
|
+
* did, and a handler still in flight is reported as JD2062. */
|
|
267
|
+
close(options?: { graceMs?: number }): Promise<void>;
|
|
226
268
|
/** The queue surface; present when opened with `jobs` (JOBS-FORMAT). */
|
|
227
269
|
readonly jobs?: JobsApi;
|
|
228
270
|
/** Present exactly when the driver is synchronous — never stubs. */
|
package/types/typed.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
import type {
|
|
16
16
|
EntityKeyArg, LoadExplanation, SaveReport, Store, StoreCapabilities,
|
|
17
|
-
StoreStats, Collection, ExecuteOptions,
|
|
17
|
+
StoreStats, Collection, ExecuteOptions, SequenceResult, ValueOrPromise,
|
|
18
18
|
} from '@jarenjs/db';
|
|
19
19
|
|
|
20
20
|
/** The self-referential constraint an interface can satisfy: generated
|
|
@@ -91,12 +91,12 @@ export interface TypedEntitySet<E extends MetaMap<E>, M extends EntityMeta> {
|
|
|
91
91
|
export interface TypedStore<E extends MetaMap<E>> {
|
|
92
92
|
readonly capabilities: StoreCapabilities;
|
|
93
93
|
stats(): StoreStats;
|
|
94
|
-
collection(name: string): Collection
|
|
94
|
+
collection<T = unknown>(name: string): Collection<T>;
|
|
95
95
|
entity<K extends keyof E & string>(name: K): TypedEntitySet<E, E[K]>;
|
|
96
|
-
execute
|
|
96
|
+
execute?<R = unknown>(document: unknown, options?: ExecuteOptions): ValueOrPromise<SequenceResult<R>>;
|
|
97
97
|
saveChanges?(): Promise<SaveReport>;
|
|
98
98
|
transaction<R>(fn: (store: Store) => R | Promise<R>): Promise<Awaited<R>>;
|
|
99
|
-
close(): Promise<void>;
|
|
99
|
+
close(options?: { graceMs?: number }): Promise<void>;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/**
|