@jarenjs/db 0.34.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/ARCHITECTURE.md +397 -0
- package/README.md +218 -0
- package/dist/types/algebra.d.ts +133 -0
- package/dist/types/app.d.ts +49 -0
- package/dist/types/capture.d.ts +85 -0
- package/dist/types/cli.d.ts +2 -0
- package/dist/types/dag-job.d.ts +40 -0
- package/dist/types/ddl.d.ts +170 -0
- package/dist/types/dialect.d.ts +130 -0
- package/dist/types/dialects/sqlite.d.ts +9 -0
- package/dist/types/driver.d.ts +128 -0
- package/dist/types/drivers/bun.d.ts +47 -0
- package/dist/types/drivers/node.d.ts +37 -0
- package/dist/types/drivers/wasm.d.ts +65 -0
- package/dist/types/emit-model.d.ts +44 -0
- package/dist/types/emit.d.ts +72 -0
- package/dist/types/entity.d.ts +23 -0
- package/dist/types/errors.d.ts +165 -0
- package/dist/types/graph.d.ts +28 -0
- package/dist/types/index.d.ts +35 -0
- package/dist/types/jobs.d.ts +134 -0
- package/dist/types/live.d.ts +62 -0
- package/dist/types/migrate.d.ts +163 -0
- package/dist/types/model.d.ts +36 -0
- package/dist/types/patch-sql.d.ts +37 -0
- package/dist/types/plan.d.ts +119 -0
- package/dist/types/profile.d.ts +80 -0
- package/dist/types/query.d.ts +100 -0
- package/dist/types/residual.d.ts +50 -0
- package/dist/types/store.d.ts +53 -0
- package/dist/types/tracker.d.ts +43 -0
- package/dist/types/typed.d.ts +15 -0
- package/dist/types/types.d.ts +26 -0
- package/dist/types/udf.d.ts +70 -0
- package/dist/types/window.d.ts +52 -0
- package/docs/JOBS-FORMAT.md +218 -0
- package/docs/LIVE-FORMAT.md +348 -0
- package/docs/MIGRATION-FORMAT.md +302 -0
- package/docs/MODEL-FORMAT.md +928 -0
- package/package.json +81 -0
- package/schemas/jaren-migration.draft-07.schema.json +144 -0
- package/schemas/jaren-migration.schema.json +144 -0
- package/schemas/jaren-model.draft-07.schema.json +149 -0
- package/schemas/jaren-model.schema.json +149 -0
- package/src/algebra.js +105 -0
- package/src/app.js +108 -0
- package/src/capture.js +584 -0
- package/src/cli.js +264 -0
- package/src/dag-job.js +86 -0
- package/src/ddl.js +588 -0
- package/src/dialect.js +297 -0
- package/src/dialects/sqlite.js +175 -0
- package/src/driver.js +419 -0
- package/src/drivers/bun.js +101 -0
- package/src/drivers/node.js +93 -0
- package/src/drivers/wasm.js +178 -0
- package/src/emit-model.js +208 -0
- package/src/emit.js +393 -0
- package/src/entity.js +367 -0
- package/src/errors.js +173 -0
- package/src/graph.js +101 -0
- package/src/index.js +64 -0
- package/src/jobs.js +507 -0
- package/src/live.js +899 -0
- package/src/migrate.js +1411 -0
- package/src/model.js +476 -0
- package/src/patch-sql.js +150 -0
- package/src/plan.js +1038 -0
- package/src/profile.js +131 -0
- package/src/query.js +1010 -0
- package/src/residual.js +91 -0
- package/src/store.js +1422 -0
- package/src/tracker.js +776 -0
- package/src/typed.js +19 -0
- package/src/types.js +36 -0
- package/src/udf.js +132 -0
- package/src/window.js +125 -0
- package/types/app.d.ts +36 -0
- package/types/bun.d.ts +9 -0
- package/types/index.d.ts +592 -0
- package/types/node.d.ts +15 -0
- package/types/typed.d.ts +108 -0
- package/types/wasm.d.ts +5 -0
package/types/typed.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The typed-store surface: bind a generated `EntityMetaMap` (from
|
|
3
|
+
* `entityEmitModel` + `@jarenjs/emit`) to an opened store and the
|
|
4
|
+
* entity sets speak the generated shapes — inputs on `create`/`add`,
|
|
5
|
+
* documents on reads, and `load` results WIDENED by their include
|
|
6
|
+
* specification, relation by relation, `count: true` as a number,
|
|
7
|
+
* to-one includes as `Doc | null`.
|
|
8
|
+
*
|
|
9
|
+
* THE LINE, again: where clauses and orderings are query expressions
|
|
10
|
+
* with their own format — they stay `unknown` here, checked by the
|
|
11
|
+
* runtime's refusal codes, not by TypeScript. The include SHAPE is
|
|
12
|
+
* what only a model knows, and that is what this file types.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type {
|
|
16
|
+
EntityKeyArg, LoadExplanation, SaveReport, Store, StoreCapabilities,
|
|
17
|
+
StoreStats, Collection, ExecuteOptions,
|
|
18
|
+
} from '@jarenjs/db';
|
|
19
|
+
|
|
20
|
+
/** The self-referential constraint an interface can satisfy: generated
|
|
21
|
+
* `EntityMetaMap` interfaces carry no index signature, so the generics
|
|
22
|
+
* constrain against their own keys instead of `Record<string, …>`. */
|
|
23
|
+
export type MetaMap<E> = { [K in keyof E]: EntityMeta };
|
|
24
|
+
|
|
25
|
+
/** One entity's generated metadata: the `EntityMetaMap` entry shape. */
|
|
26
|
+
export interface EntityMeta {
|
|
27
|
+
doc: object;
|
|
28
|
+
input: object;
|
|
29
|
+
key: unknown;
|
|
30
|
+
relations: Record<string, { entity: string; doc: object; many: boolean }>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The include clause for one relation of `M`, recursing through the
|
|
34
|
+
* metadata map so nested includes stay precise. */
|
|
35
|
+
export type TypedInclude<E extends MetaMap<E>, M extends EntityMeta> = {
|
|
36
|
+
readonly [K in keyof M['relations']]?:
|
|
37
|
+
true
|
|
38
|
+
| { count: true }
|
|
39
|
+
| TypedLoadSpec<E, E[M['relations'][K]['entity'] & keyof E]>;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export interface TypedLoadSpecBase {
|
|
43
|
+
/** A query expression over `$it` — its format is the runtime's. */
|
|
44
|
+
where?: unknown;
|
|
45
|
+
orderBy?: unknown;
|
|
46
|
+
take?: number;
|
|
47
|
+
skip?: number;
|
|
48
|
+
maxDepth?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type TypedLoadSpec<E extends MetaMap<E>, M extends EntityMeta> =
|
|
52
|
+
TypedLoadSpecBase & {
|
|
53
|
+
after?: M['key'] extends string | number ? M['key'] : never;
|
|
54
|
+
include?: TypedInclude<E, M>;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** The result of one load: the document, widened by what the include
|
|
58
|
+
* specification asked for. A wrong include key never types. */
|
|
59
|
+
export type Loaded<
|
|
60
|
+
E extends MetaMap<E>,
|
|
61
|
+
M extends EntityMeta,
|
|
62
|
+
S,
|
|
63
|
+
> = M['doc'] & (S extends { include: infer I } ? {
|
|
64
|
+
-readonly [K in keyof I & keyof M['relations']]-?:
|
|
65
|
+
I[K] extends { count: true } ? number
|
|
66
|
+
: M['relations'][K]['many'] extends true
|
|
67
|
+
? Array<Loaded<E, E[M['relations'][K]['entity'] & keyof E], I[K]>>
|
|
68
|
+
: Loaded<E, E[M['relations'][K]['entity'] & keyof E], I[K]> | null;
|
|
69
|
+
} : NonNullable<unknown>);
|
|
70
|
+
|
|
71
|
+
export interface TypedUntrackedReads<E extends MetaMap<E>, M extends EntityMeta> {
|
|
72
|
+
get(key: EntityKeyArg): Promise<M['doc'] | undefined>;
|
|
73
|
+
load<const S extends TypedLoadSpec<E, M>>(spec?: S): Promise<Array<Loaded<E, M, S>>>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface TypedEntitySet<E extends MetaMap<E>, M extends EntityMeta> {
|
|
77
|
+
create(doc: M['input']): Promise<Readonly<M['doc']>>;
|
|
78
|
+
get(key: EntityKeyArg): Promise<Readonly<M['doc']> | undefined>;
|
|
79
|
+
update(key: EntityKeyArg, changes: Partial<M['doc']>): Promise<Readonly<M['doc']>>;
|
|
80
|
+
delete(key: EntityKeyArg): Promise<boolean>;
|
|
81
|
+
load<const S extends TypedLoadSpec<E, M>>(spec?: S):
|
|
82
|
+
Promise<Array<Readonly<Loaded<E, M, S>>>>;
|
|
83
|
+
explainLoad(spec?: TypedLoadSpec<E, M>): LoadExplanation;
|
|
84
|
+
add(doc: M['input']): Readonly<M['doc']>;
|
|
85
|
+
put(next: M['doc']): Readonly<M['doc']>;
|
|
86
|
+
remove(key: EntityKeyArg | M['doc']): void;
|
|
87
|
+
discard(key: EntityKeyArg | M['doc']): void;
|
|
88
|
+
asNoTracking(): TypedUntrackedReads<E, M>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface TypedStore<E extends MetaMap<E>> {
|
|
92
|
+
readonly capabilities: StoreCapabilities;
|
|
93
|
+
stats(): StoreStats;
|
|
94
|
+
collection(name: string): Collection;
|
|
95
|
+
entity<K extends keyof E & string>(name: K): TypedEntitySet<E, E[K]>;
|
|
96
|
+
execute?(document: unknown, options?: ExecuteOptions): unknown;
|
|
97
|
+
saveChanges?(): Promise<SaveReport>;
|
|
98
|
+
transaction<R>(fn: (store: Store) => R | Promise<R>): Promise<Awaited<R>>;
|
|
99
|
+
close(): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Bind a store to its generated entity metadata. Identity at runtime;
|
|
104
|
+
* every guarantee is in the types.
|
|
105
|
+
*/
|
|
106
|
+
export declare function typedStore<E extends MetaMap<E>>(
|
|
107
|
+
store: Store,
|
|
108
|
+
): TypedStore<E>;
|
package/types/wasm.d.ts
ADDED