@ontrails/drizzle 1.0.0-beta.15 → 1.0.0-beta.17
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/CHANGELOG.md +47 -0
- package/README.md +3 -1
- package/package.json +11 -3
- package/src/runtime.ts +25 -20
- package/src/schema.ts +1 -1
- package/src/types.ts +20 -4
- package/.turbo/turbo-build.log +0 -1
- package/.turbo/turbo-lint.log +0 -3
- package/.turbo/turbo-typecheck.log +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/runtime.d.ts +0 -17
- package/dist/runtime.d.ts.map +0 -1
- package/dist/runtime.js +0 -755
- package/dist/runtime.js.map +0 -1
- package/dist/schema.d.ts +0 -15
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js +0 -332
- package/dist/schema.js.map +0 -1
- package/dist/types.d.ts +0 -38
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/src/__tests__/drizzle.test.ts +0 -997
- package/tsconfig.json +0 -9
- package/tsconfig.tests.json +0 -10
- package/tsconfig.tsbuildinfo +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# @ontrails/drizzle
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [3dc8254]
|
|
8
|
+
- @ontrails/core@1.0.0-beta.17
|
|
9
|
+
- @ontrails/store@1.0.0-beta.17
|
|
10
|
+
|
|
11
|
+
## 1.0.0-beta.16
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- f5c6777: Move adapter package workspaces from `connectors/*` to `adapters/*` as part of
|
|
16
|
+
the package-boundary taxonomy cutover. Package names and public APIs are
|
|
17
|
+
unchanged.
|
|
18
|
+
- 3395234: Move store adapter-binding helpers to `@ontrails/store/adapter-support` and topographer direct database/admin helpers to `@ontrails/topographer/backend-support`, keeping root exports focused on contract-level APIs.
|
|
19
|
+
- 6300f70: BREAKING: rename the shared store backend option type from `StoreConnectorOptions` to `StoreAdapterOptions`.
|
|
20
|
+
- 49c2e7d: Refresh published package README taxonomy to use adapter language instead of retired connector vocabulary.
|
|
21
|
+
- df9a7d0: Add project-aware public export-map governance for @ontrails workspace docs,
|
|
22
|
+
imports, root barrels, and bin-only package surfaces.
|
|
23
|
+
- Updated dependencies [73622ae]
|
|
24
|
+
- Updated dependencies [6300f70]
|
|
25
|
+
- Updated dependencies [d172013]
|
|
26
|
+
- Updated dependencies [c3fc5c3]
|
|
27
|
+
- Updated dependencies [20d7a5c]
|
|
28
|
+
- Updated dependencies [be5fb46]
|
|
29
|
+
- Updated dependencies [e898cc4]
|
|
30
|
+
- Updated dependencies [3395234]
|
|
31
|
+
- Updated dependencies [bcdc484]
|
|
32
|
+
- Updated dependencies [6300f70]
|
|
33
|
+
- Updated dependencies [49c2e7d]
|
|
34
|
+
- Updated dependencies [331e3a9]
|
|
35
|
+
- Updated dependencies [4399fdb]
|
|
36
|
+
- Updated dependencies [4b8d13b]
|
|
37
|
+
- Updated dependencies [112b9f2]
|
|
38
|
+
- Updated dependencies [893025e]
|
|
39
|
+
- Updated dependencies [eec5e9d]
|
|
40
|
+
- Updated dependencies [ebd4434]
|
|
41
|
+
- Updated dependencies [863d473]
|
|
42
|
+
- Updated dependencies [344f2f7]
|
|
43
|
+
- Updated dependencies [26f9ffd]
|
|
44
|
+
- Updated dependencies [10eae9a]
|
|
45
|
+
- Updated dependencies [22c6c06]
|
|
46
|
+
- Updated dependencies [df9a7d0]
|
|
47
|
+
- @ontrails/core@1.0.0-beta.16
|
|
48
|
+
- @ontrails/store@1.0.0-beta.16
|
|
49
|
+
|
|
3
50
|
## 1.0.0-beta.15
|
|
4
51
|
|
|
5
52
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @ontrails/drizzle
|
|
2
2
|
|
|
3
|
-
Drizzle
|
|
3
|
+
Drizzle adapter for Trails stores. Use this package to bind a backend-agnostic `store(...)` definition from `@ontrails/store` to a concrete Drizzle runtime.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
@@ -30,7 +30,9 @@ bun add @ontrails/store @ontrails/drizzle zod
|
|
|
30
30
|
|
|
31
31
|
## Migration
|
|
32
32
|
|
|
33
|
+
<!-- warden-ignore-next-line -->
|
|
33
34
|
This package replaces the old `@ontrails/store/drizzle` subpath.
|
|
34
35
|
|
|
36
|
+
<!-- warden-ignore-next-line -->
|
|
35
37
|
- Before: `import { connectDrizzle } from '@ontrails/store/drizzle'`
|
|
36
38
|
- After: `import { connectDrizzle } from '@ontrails/drizzle'`
|
package/package.json
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ontrails/drizzle",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.17",
|
|
4
|
+
"files": [
|
|
5
|
+
"src/**/*.ts",
|
|
6
|
+
"!src/**/__tests__/**",
|
|
7
|
+
"!src/**/*.test.ts",
|
|
8
|
+
"!src/**/*.test-d.ts",
|
|
9
|
+
"README.md",
|
|
10
|
+
"CHANGELOG.md"
|
|
11
|
+
],
|
|
4
12
|
"type": "module",
|
|
5
13
|
"exports": {
|
|
6
14
|
".": "./src/index.ts",
|
|
@@ -14,11 +22,11 @@
|
|
|
14
22
|
"clean": "rm -rf dist *.tsbuildinfo"
|
|
15
23
|
},
|
|
16
24
|
"dependencies": {
|
|
17
|
-
"@ontrails/core": "^1.0.0-beta.
|
|
25
|
+
"@ontrails/core": "^1.0.0-beta.16",
|
|
18
26
|
"drizzle-orm": "^0.45.2"
|
|
19
27
|
},
|
|
20
28
|
"peerDependencies": {
|
|
21
|
-
"@ontrails/store": "^1.0.0-beta.
|
|
29
|
+
"@ontrails/store": "^1.0.0-beta.16",
|
|
22
30
|
"zod": "^4.3.5"
|
|
23
31
|
}
|
|
24
32
|
}
|
package/src/runtime.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
resource,
|
|
12
12
|
} from '@ontrails/core';
|
|
13
13
|
import { versionFieldName } from '@ontrails/store';
|
|
14
|
-
import { bindStoreDefinition } from '@ontrails/store/
|
|
14
|
+
import { bindStoreDefinition } from '@ontrails/store/adapter-support';
|
|
15
15
|
import type {
|
|
16
16
|
AnyStoreDefinition,
|
|
17
17
|
AnyStoreTable,
|
|
@@ -32,7 +32,7 @@ import { and, eq, sql } from 'drizzle-orm';
|
|
|
32
32
|
import { drizzle } from 'drizzle-orm/bun-sqlite';
|
|
33
33
|
import type { AnySQLiteColumn, AnySQLiteTable } from 'drizzle-orm/sqlite-core';
|
|
34
34
|
import type { z } from 'zod';
|
|
35
|
-
import type { TrailContext } from '@ontrails/core';
|
|
35
|
+
import type { Signal, TrailContext } from '@ontrails/core';
|
|
36
36
|
|
|
37
37
|
import {
|
|
38
38
|
deriveDrizzleTables,
|
|
@@ -196,7 +196,7 @@ const isVersionManagedField = <TTable extends AnyStoreTable>(
|
|
|
196
196
|
/**
|
|
197
197
|
* Synthesize a value for a generated field during insert.
|
|
198
198
|
*
|
|
199
|
-
* The
|
|
199
|
+
* The adapter recognizes these conventions for generated fields:
|
|
200
200
|
*
|
|
201
201
|
* - **Primary key** (`integer` type): auto-increment, left to SQLite.
|
|
202
202
|
* - **Timestamp fields** (`createdAt`, `updatedAt`, `created_at`,
|
|
@@ -474,7 +474,7 @@ const ensureNotCyclic = (
|
|
|
474
474
|
}
|
|
475
475
|
|
|
476
476
|
throw new ValidationError(
|
|
477
|
-
`Store definition contains a reference cycle involving "${tableName}", which the SQLite
|
|
477
|
+
`Store definition contains a reference cycle involving "${tableName}", which the SQLite adapter cannot seed automatically`
|
|
478
478
|
);
|
|
479
479
|
};
|
|
480
480
|
|
|
@@ -1045,19 +1045,16 @@ type BoundFireFn = NonNullable<TrailContext['fire']>;
|
|
|
1045
1045
|
*/
|
|
1046
1046
|
const fireDerivedSignal = async <TTable extends AnyStoreTable>(
|
|
1047
1047
|
fire: BoundFireFn,
|
|
1048
|
-
|
|
1048
|
+
derivedSignal: Signal<unknown>,
|
|
1049
1049
|
entity: EntityOf<TTable>
|
|
1050
1050
|
): Promise<void> => {
|
|
1051
1051
|
try {
|
|
1052
|
-
|
|
1053
|
-
if (fired.isErr()) {
|
|
1054
|
-
console.warn(
|
|
1055
|
-
`[drizzle] signal "${signalId}" emission failed:`,
|
|
1056
|
-
fired.error
|
|
1057
|
-
);
|
|
1058
|
-
}
|
|
1052
|
+
await fire(derivedSignal, entity);
|
|
1059
1053
|
} catch (error) {
|
|
1060
|
-
console.warn(
|
|
1054
|
+
console.warn(
|
|
1055
|
+
`[drizzle] signal "${derivedSignal.id}" emission threw:`,
|
|
1056
|
+
error
|
|
1057
|
+
);
|
|
1061
1058
|
}
|
|
1062
1059
|
};
|
|
1063
1060
|
|
|
@@ -1084,7 +1081,7 @@ const bindWritableAccessorSignals = <TTable extends AnyStoreTable>(
|
|
|
1084
1081
|
...accessor,
|
|
1085
1082
|
async insert(input: InsertOf<TTable>) {
|
|
1086
1083
|
const created = await accessor.insert(input);
|
|
1087
|
-
await fireDerivedSignal(fire, table.signals.created
|
|
1084
|
+
await fireDerivedSignal(fire, table.signals.created, created);
|
|
1088
1085
|
return created;
|
|
1089
1086
|
},
|
|
1090
1087
|
async remove(id: StoreIdentifierOf<TTable>) {
|
|
@@ -1095,7 +1092,7 @@ const bindWritableAccessorSignals = <TTable extends AnyStoreTable>(
|
|
|
1095
1092
|
const existing = await accessor.get(id);
|
|
1096
1093
|
const removed = await accessor.remove(id);
|
|
1097
1094
|
if (removed.deleted && existing !== null) {
|
|
1098
|
-
await fireDerivedSignal(fire, table.signals.removed
|
|
1095
|
+
await fireDerivedSignal(fire, table.signals.removed, existing);
|
|
1099
1096
|
}
|
|
1100
1097
|
return removed;
|
|
1101
1098
|
},
|
|
@@ -1106,14 +1103,14 @@ const bindWritableAccessorSignals = <TTable extends AnyStoreTable>(
|
|
|
1106
1103
|
// and fire unconditionally on successful update.
|
|
1107
1104
|
const updated = await accessor.update(id, input);
|
|
1108
1105
|
if (updated !== null) {
|
|
1109
|
-
await fireDerivedSignal(fire, table.signals.updated
|
|
1106
|
+
await fireDerivedSignal(fire, table.signals.updated, updated);
|
|
1110
1107
|
}
|
|
1111
1108
|
return updated;
|
|
1112
1109
|
}
|
|
1113
1110
|
const existing = await accessor.get(id);
|
|
1114
1111
|
const updated = await accessor.update(id, input);
|
|
1115
1112
|
if (changedEntity(existing, updated)) {
|
|
1116
|
-
await fireDerivedSignal(fire, table.signals.updated
|
|
1113
|
+
await fireDerivedSignal(fire, table.signals.updated, updated);
|
|
1117
1114
|
}
|
|
1118
1115
|
return updated;
|
|
1119
1116
|
},
|
|
@@ -1128,12 +1125,12 @@ const bindWritableAccessorSignals = <TTable extends AnyStoreTable>(
|
|
|
1128
1125
|
const written = await accessor.upsert(input);
|
|
1129
1126
|
|
|
1130
1127
|
if (existing === null) {
|
|
1131
|
-
await fireDerivedSignal(fire, table.signals.created
|
|
1128
|
+
await fireDerivedSignal(fire, table.signals.created, written);
|
|
1132
1129
|
return written;
|
|
1133
1130
|
}
|
|
1134
1131
|
|
|
1135
1132
|
if (changedEntity(existing, written)) {
|
|
1136
|
-
await fireDerivedSignal(fire, table.signals.updated
|
|
1133
|
+
await fireDerivedSignal(fire, table.signals.updated, written);
|
|
1137
1134
|
}
|
|
1138
1135
|
return written;
|
|
1139
1136
|
},
|
|
@@ -1238,7 +1235,7 @@ const connectionHealth = (
|
|
|
1238
1235
|
* `Database` client is tracked via `WeakMap`).
|
|
1239
1236
|
*
|
|
1240
1237
|
* Note: the `search` field on `StoreTableInput` is not yet interpreted by
|
|
1241
|
-
* this
|
|
1238
|
+
* this adapter — it is reserved for future full-text search support.
|
|
1242
1239
|
*/
|
|
1243
1240
|
export const connectDrizzle = <const TStore extends AnyStoreDefinition>(
|
|
1244
1241
|
definition: TStore,
|
|
@@ -1264,6 +1261,14 @@ export const connectDrizzle = <const TStore extends AnyStoreDefinition>(
|
|
|
1264
1261
|
throw error;
|
|
1265
1262
|
}
|
|
1266
1263
|
const db = drizzle({ client, schema: tables });
|
|
1264
|
+
if (options.seed !== undefined) {
|
|
1265
|
+
try {
|
|
1266
|
+
seedFixtures(store, tables, db, options.seed);
|
|
1267
|
+
} catch (error) {
|
|
1268
|
+
client.close();
|
|
1269
|
+
throw error;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1267
1272
|
return Result.ok(createWritableConnection(store, tables, db, client));
|
|
1268
1273
|
} catch (error) {
|
|
1269
1274
|
return Result.err(
|
package/src/schema.ts
CHANGED
|
@@ -200,7 +200,7 @@ const inferFieldKind = (
|
|
|
200
200
|
}
|
|
201
201
|
default: {
|
|
202
202
|
throw new ValidationError(
|
|
203
|
-
`Store field "${field}" uses unsupported schema type "${schema.def.type}" for the Drizzle SQLite
|
|
203
|
+
`Store field "${field}" uses unsupported schema type "${schema.def.type}" for the Drizzle SQLite adapter`
|
|
204
204
|
);
|
|
205
205
|
}
|
|
206
206
|
}
|
package/src/types.ts
CHANGED
|
@@ -3,7 +3,8 @@ import type {
|
|
|
3
3
|
AnyStoreDefinition,
|
|
4
4
|
ReadOnlyStoreConnection,
|
|
5
5
|
StoreAccessMode,
|
|
6
|
-
|
|
6
|
+
StoreAdapterOptions,
|
|
7
|
+
StoreMockSeed,
|
|
7
8
|
StoreTableConnection,
|
|
8
9
|
} from '@ontrails/store';
|
|
9
10
|
import type { BunSQLiteDatabase } from 'drizzle-orm/bun-sqlite';
|
|
@@ -21,17 +22,32 @@ export interface DrizzleQueryContext<TStore extends AnyStoreDefinition> {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
|
-
* Options accepted by the Drizzle store
|
|
25
|
+
* Options accepted by the Drizzle store adapter.
|
|
25
26
|
*
|
|
26
|
-
* Extends {@link
|
|
27
|
+
* Extends {@link StoreAdapterOptions} with drizzle-specific fields. The
|
|
27
28
|
* read-only vs writable distinction is enforced by the factory that consumes
|
|
28
29
|
* these options, not by the options type itself.
|
|
29
30
|
*/
|
|
30
31
|
export interface DrizzleStoreOptions<
|
|
31
32
|
TDef extends AnyStoreDefinition = AnyStoreDefinition,
|
|
32
|
-
> extends
|
|
33
|
+
> extends StoreAdapterOptions<TDef> {
|
|
33
34
|
/** Path to the SQLite database file. Use `":memory:"` for ephemeral runs. */
|
|
34
35
|
readonly url: string;
|
|
36
|
+
/**
|
|
37
|
+
* Optional fixture overrides applied when the writable runtime database is
|
|
38
|
+
* first created.
|
|
39
|
+
*
|
|
40
|
+
* Mirrors {@link StoreAdapterOptions.mockSeed} but for the `create`
|
|
41
|
+
* (runtime) path: when supplied, the adapter seeds these rows into the
|
|
42
|
+
* writable database immediately after schema initialization. Use this for
|
|
43
|
+
* demo/dogfood apps that want commands and examples to find pre-loaded
|
|
44
|
+
* entities on a fresh `:memory:` boot. Defaults to `undefined` — runtime
|
|
45
|
+
* databases are not auto-seeded from `table.fixtures`.
|
|
46
|
+
*
|
|
47
|
+
* Has no effect on the read-only adapter, which receives runtime data
|
|
48
|
+
* from disk rather than from fixtures.
|
|
49
|
+
*/
|
|
50
|
+
readonly seed?: StoreMockSeed<TDef>;
|
|
35
51
|
}
|
|
36
52
|
|
|
37
53
|
export type ReadOnlyDrizzleStoreConnection<TStore extends AnyStoreDefinition> =
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
$ tsc -b
|
package/.turbo/turbo-lint.log
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
$ tsc --noEmit
|
package/dist/index.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { connectDrizzle, connectReadOnlyDrizzle } from './runtime.js';
|
|
2
|
-
export type { DrizzleQueryContext, DrizzleStoreConnection, DrizzleStoreOptions, DrizzleStoreResource, DrizzleStoreSchema, ReadOnlyDrizzleStoreConnection, } from './types.js';
|
|
3
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtE,YAAY,EACV,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,8BAA8B,GAC/B,MAAM,YAAY,CAAC"}
|
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/runtime.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { AnyStoreDefinition } from '@ontrails/store';
|
|
2
|
-
import type { DrizzleStoreConnection, DrizzleStoreOptions, DrizzleStoreResource, ReadOnlyDrizzleStoreConnection } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Bind a store definition to a Drizzle-backed SQLite resource.
|
|
5
|
-
*
|
|
6
|
-
* The returned resource manages its own connection lifecycle. The `mock()`
|
|
7
|
-
* factory creates an in-memory SQLite database seeded with fixtures — callers
|
|
8
|
-
* who obtain a mock connection are responsible for calling `closeConnection()`
|
|
9
|
-
* when done, or letting the connection be garbage-collected (the underlying
|
|
10
|
-
* `Database` client is tracked via `WeakMap`).
|
|
11
|
-
*
|
|
12
|
-
* Note: the `search` field on `StoreTableInput` is not yet interpreted by
|
|
13
|
-
* this connector — it is reserved for future full-text search support.
|
|
14
|
-
*/
|
|
15
|
-
export declare const connectDrizzle: <const TStore extends AnyStoreDefinition>(definition: TStore, options: DrizzleStoreOptions<TStore>) => DrizzleStoreResource<TStore, DrizzleStoreConnection<TStore>, "readwrite">;
|
|
16
|
-
export declare const connectReadOnlyDrizzle: <const TStore extends AnyStoreDefinition>(definition: TStore, options: DrizzleStoreOptions<TStore>) => DrizzleStoreResource<TStore, ReadOnlyDrizzleStoreConnection<TStore>, "readonly">;
|
|
17
|
-
//# sourceMappingURL=runtime.d.ts.map
|
package/dist/runtime.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,kBAAkB,EAcnB,MAAM,iBAAiB,CAAC;AAYzB,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EAEpB,8BAA8B,EAC/B,MAAM,YAAY,CAAC;AA+pCpB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,CAAC,MAAM,SAAS,kBAAkB,EACpE,YAAY,MAAM,EAClB,SAAS,mBAAmB,CAAC,MAAM,CAAC,KACnC,oBAAoB,CACrB,MAAM,EACN,sBAAsB,CAAC,MAAM,CAAC,EAC9B,WAAW,CAqDZ,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,KAAK,CAAC,MAAM,SAAS,kBAAkB,EAC5E,YAAY,MAAM,EAClB,SAAS,mBAAmB,CAAC,MAAM,CAAC,KACnC,oBAAoB,CACrB,MAAM,EACN,8BAA8B,CAAC,MAAM,CAAC,EACtC,UAAU,CAoCX,CAAC"}
|