@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.
Files changed (83) hide show
  1. package/ARCHITECTURE.md +397 -0
  2. package/README.md +218 -0
  3. package/dist/types/algebra.d.ts +133 -0
  4. package/dist/types/app.d.ts +49 -0
  5. package/dist/types/capture.d.ts +85 -0
  6. package/dist/types/cli.d.ts +2 -0
  7. package/dist/types/dag-job.d.ts +40 -0
  8. package/dist/types/ddl.d.ts +170 -0
  9. package/dist/types/dialect.d.ts +130 -0
  10. package/dist/types/dialects/sqlite.d.ts +9 -0
  11. package/dist/types/driver.d.ts +128 -0
  12. package/dist/types/drivers/bun.d.ts +47 -0
  13. package/dist/types/drivers/node.d.ts +37 -0
  14. package/dist/types/drivers/wasm.d.ts +65 -0
  15. package/dist/types/emit-model.d.ts +44 -0
  16. package/dist/types/emit.d.ts +72 -0
  17. package/dist/types/entity.d.ts +23 -0
  18. package/dist/types/errors.d.ts +165 -0
  19. package/dist/types/graph.d.ts +28 -0
  20. package/dist/types/index.d.ts +35 -0
  21. package/dist/types/jobs.d.ts +134 -0
  22. package/dist/types/live.d.ts +62 -0
  23. package/dist/types/migrate.d.ts +163 -0
  24. package/dist/types/model.d.ts +36 -0
  25. package/dist/types/patch-sql.d.ts +37 -0
  26. package/dist/types/plan.d.ts +119 -0
  27. package/dist/types/profile.d.ts +80 -0
  28. package/dist/types/query.d.ts +100 -0
  29. package/dist/types/residual.d.ts +50 -0
  30. package/dist/types/store.d.ts +53 -0
  31. package/dist/types/tracker.d.ts +43 -0
  32. package/dist/types/typed.d.ts +15 -0
  33. package/dist/types/types.d.ts +26 -0
  34. package/dist/types/udf.d.ts +70 -0
  35. package/dist/types/window.d.ts +52 -0
  36. package/docs/JOBS-FORMAT.md +218 -0
  37. package/docs/LIVE-FORMAT.md +348 -0
  38. package/docs/MIGRATION-FORMAT.md +302 -0
  39. package/docs/MODEL-FORMAT.md +928 -0
  40. package/package.json +81 -0
  41. package/schemas/jaren-migration.draft-07.schema.json +144 -0
  42. package/schemas/jaren-migration.schema.json +144 -0
  43. package/schemas/jaren-model.draft-07.schema.json +149 -0
  44. package/schemas/jaren-model.schema.json +149 -0
  45. package/src/algebra.js +105 -0
  46. package/src/app.js +108 -0
  47. package/src/capture.js +584 -0
  48. package/src/cli.js +264 -0
  49. package/src/dag-job.js +86 -0
  50. package/src/ddl.js +588 -0
  51. package/src/dialect.js +297 -0
  52. package/src/dialects/sqlite.js +175 -0
  53. package/src/driver.js +419 -0
  54. package/src/drivers/bun.js +101 -0
  55. package/src/drivers/node.js +93 -0
  56. package/src/drivers/wasm.js +178 -0
  57. package/src/emit-model.js +208 -0
  58. package/src/emit.js +393 -0
  59. package/src/entity.js +367 -0
  60. package/src/errors.js +173 -0
  61. package/src/graph.js +101 -0
  62. package/src/index.js +64 -0
  63. package/src/jobs.js +507 -0
  64. package/src/live.js +899 -0
  65. package/src/migrate.js +1411 -0
  66. package/src/model.js +476 -0
  67. package/src/patch-sql.js +150 -0
  68. package/src/plan.js +1038 -0
  69. package/src/profile.js +131 -0
  70. package/src/query.js +1010 -0
  71. package/src/residual.js +91 -0
  72. package/src/store.js +1422 -0
  73. package/src/tracker.js +776 -0
  74. package/src/typed.js +19 -0
  75. package/src/types.js +36 -0
  76. package/src/udf.js +132 -0
  77. package/src/window.js +125 -0
  78. package/types/app.d.ts +36 -0
  79. package/types/bun.d.ts +9 -0
  80. package/types/index.d.ts +592 -0
  81. package/types/node.d.ts +15 -0
  82. package/types/typed.d.ts +108 -0
  83. package/types/wasm.d.ts +5 -0
@@ -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>;
@@ -0,0 +1,5 @@
1
+ /** Hand-authored declarations for @jarenjs/db/wasm (strategy 1). */
2
+ import type { Driver } from '@jarenjs/db';
3
+
4
+ /** A driver over an injected wasm SQLite handle (possibly async). */
5
+ export declare function wasmDriver(handle: unknown): Driver;