@fougere/adapter-sql 0.9.2-alpha.0 → 0.10.0-alpha.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/dist/check.d.ts +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/{crud.d.ts → crud/SqlStorage.d.ts} +4 -8
- package/dist/crud/SqlStorage.d.ts.map +1 -0
- package/dist/{crud.js → crud/SqlStorage.js} +6 -9
- package/dist/crud/SqlStorage.js.map +1 -0
- package/dist/crud/StorageFactoryOptions.d.ts +5 -0
- package/dist/crud/StorageFactoryOptions.d.ts.map +1 -0
- package/dist/crud/StorageFactoryOptions.js +2 -0
- package/dist/crud/StorageFactoryOptions.js.map +1 -0
- package/dist/ddl/GenerateOptions.d.ts +8 -0
- package/dist/ddl/GenerateOptions.d.ts.map +1 -0
- package/dist/ddl/GenerateOptions.js +2 -0
- package/dist/ddl/GenerateOptions.js.map +1 -0
- package/dist/{ddl.d.ts → ddl/SqlSink.d.ts} +6 -10
- package/dist/ddl/SqlSink.d.ts.map +1 -0
- package/dist/{ddl.js → ddl/SqlSink.js} +6 -7
- package/dist/ddl/SqlSink.js.map +1 -0
- package/dist/{dialect.d.ts → dialect/Dialect.d.ts} +3 -4
- package/dist/dialect/Dialect.d.ts.map +1 -0
- package/dist/{dialect.js → dialect/Dialect.js} +1 -1
- package/dist/dialect/Dialect.js.map +1 -0
- package/dist/dialect/DialectName.d.ts +2 -0
- package/dist/dialect/DialectName.d.ts.map +1 -0
- package/dist/dialect/DialectName.js +2 -0
- package/dist/dialect/DialectName.js.map +1 -0
- package/dist/{diff.d.ts → diff/Change.d.ts} +7 -8
- package/dist/diff/Change.d.ts.map +1 -0
- package/dist/{diff.js → diff/Change.js} +6 -8
- package/dist/diff/Change.js.map +1 -0
- package/dist/diff/SchemaState.d.ts +6 -0
- package/dist/diff/SchemaState.d.ts.map +1 -0
- package/dist/diff/SchemaState.js +11 -0
- package/dist/diff/SchemaState.js.map +1 -0
- package/dist/drift.d.ts +1 -1
- package/dist/drift.d.ts.map +1 -1
- package/dist/drift.js +1 -1
- package/dist/drift.js.map +1 -1
- package/dist/fields/Engine.d.ts +4 -0
- package/dist/fields/Engine.d.ts.map +1 -0
- package/dist/fields/Engine.js +2 -0
- package/dist/fields/Engine.js.map +1 -0
- package/dist/fields/SqlField.d.ts +6 -0
- package/dist/fields/SqlField.d.ts.map +1 -0
- package/dist/fields/SqlField.js +2 -0
- package/dist/fields/SqlField.js.map +1 -0
- package/dist/{fields.d.ts → fields/SqlFields.d.ts} +2 -9
- package/dist/fields/SqlFields.d.ts.map +1 -0
- package/dist/{fields.js → fields/SqlFields.js} +2 -2
- package/dist/fields/SqlFields.js.map +1 -0
- package/dist/index.d.ts +23 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -9
- package/dist/index.js.map +1 -1
- package/dist/order/FkEdge.d.ts +7 -0
- package/dist/order/FkEdge.d.ts.map +1 -0
- package/dist/order/FkEdge.js +2 -0
- package/dist/order/FkEdge.js.map +1 -0
- package/dist/{order.d.ts → order/TableOrder.d.ts} +3 -10
- package/dist/order/TableOrder.d.ts.map +1 -0
- package/dist/{order.js → order/TableOrder.js} +1 -1
- package/dist/order/TableOrder.js.map +1 -0
- package/dist/query/QueryEvent.d.ts +17 -0
- package/dist/query/QueryEvent.d.ts.map +1 -0
- package/dist/query/QueryEvent.js +2 -0
- package/dist/query/QueryEvent.js.map +1 -0
- package/dist/query/QuerySink.d.ts +8 -0
- package/dist/query/QuerySink.d.ts.map +1 -0
- package/dist/{query.js → query/QuerySink.js} +13 -1
- package/dist/query/QuerySink.js.map +1 -0
- package/dist/source/Setup.d.ts +4 -0
- package/dist/source/Setup.d.ts.map +1 -0
- package/dist/source/Setup.js +2 -0
- package/dist/source/Setup.js.map +1 -0
- package/dist/{source.d.ts → source/SqlSource.d.ts} +5 -13
- package/dist/source/SqlSource.d.ts.map +1 -0
- package/dist/{source.js → source/SqlSource.js} +6 -7
- package/dist/source/SqlSource.js.map +1 -0
- package/dist/source/SqlSourceOptions.d.ts +8 -0
- package/dist/source/SqlSourceOptions.d.ts.map +1 -0
- package/dist/source/SqlSourceOptions.js +2 -0
- package/dist/source/SqlSourceOptions.js.map +1 -0
- package/dist/{sqlite.d.ts → sqlite/SqliteSource.d.ts} +3 -6
- package/dist/sqlite/SqliteSource.d.ts.map +1 -0
- package/dist/{sqlite.js → sqlite/SqliteSource.js} +7 -8
- package/dist/sqlite/SqliteSource.js.map +1 -0
- package/dist/sqlite/SqliteSourceOptions.d.ts +6 -0
- package/dist/sqlite/SqliteSourceOptions.d.ts.map +1 -0
- package/dist/sqlite/SqliteSourceOptions.js +2 -0
- package/dist/sqlite/SqliteSourceOptions.js.map +1 -0
- package/dist/sqlite/index.d.ts +3 -0
- package/dist/sqlite/index.d.ts.map +1 -0
- package/dist/sqlite/index.js +2 -0
- package/dist/sqlite/index.js.map +1 -0
- package/dist/{step.d.ts → step/Plan.d.ts} +6 -28
- package/dist/step/Plan.d.ts.map +1 -0
- package/dist/{step.js → step/Plan.js} +5 -6
- package/dist/step/Plan.js.map +1 -0
- package/dist/step/PlanOptions.d.ts +8 -0
- package/dist/step/PlanOptions.d.ts.map +1 -0
- package/dist/step/PlanOptions.js +2 -0
- package/dist/step/PlanOptions.js.map +1 -0
- package/dist/step/Refusal.d.ts +7 -0
- package/dist/step/Refusal.d.ts.map +1 -0
- package/dist/step/Refusal.js +2 -0
- package/dist/step/Refusal.js.map +1 -0
- package/dist/step/StepChange.d.ts +12 -0
- package/dist/step/StepChange.d.ts.map +1 -0
- package/dist/step/StepChange.js +2 -0
- package/dist/step/StepChange.js.map +1 -0
- package/dist/table/AppLike.d.ts +12 -0
- package/dist/table/AppLike.d.ts.map +1 -0
- package/dist/table/AppLike.js +2 -0
- package/dist/table/AppLike.js.map +1 -0
- package/dist/table/ColumnDef.d.ts +34 -0
- package/dist/table/ColumnDef.d.ts.map +1 -0
- package/dist/table/ColumnDef.js +2 -0
- package/dist/table/ColumnDef.js.map +1 -0
- package/dist/table/ColumnReference.d.ts +6 -0
- package/dist/table/ColumnReference.d.ts.map +1 -0
- package/dist/table/ColumnReference.js +2 -0
- package/dist/table/ColumnReference.js.map +1 -0
- package/dist/table/EntityEntry.d.ts +7 -0
- package/dist/table/EntityEntry.d.ts.map +1 -0
- package/dist/table/EntityEntry.js +2 -0
- package/dist/table/EntityEntry.js.map +1 -0
- package/dist/table/FrondLike.d.ts +6 -0
- package/dist/table/FrondLike.d.ts.map +1 -0
- package/dist/table/FrondLike.js +2 -0
- package/dist/table/FrondLike.js.map +1 -0
- package/dist/table/HostedNames.d.ts +8 -0
- package/dist/table/HostedNames.d.ts.map +1 -0
- package/dist/table/HostedNames.js +2 -0
- package/dist/table/HostedNames.js.map +1 -0
- package/dist/table/RelationResolve.d.ts +12 -0
- package/dist/table/RelationResolve.d.ts.map +1 -0
- package/dist/table/RelationResolve.js +2 -0
- package/dist/table/RelationResolve.js.map +1 -0
- package/dist/table/TableDef.d.ts +29 -0
- package/dist/table/TableDef.d.ts.map +1 -0
- package/dist/{table.js → table/TableDef.js} +3 -4
- package/dist/table/TableDef.js.map +1 -0
- package/package.json +6 -6
- package/src/check.ts +1 -1
- package/src/{crud.ts → crud/SqlStorage.ts} +7 -14
- package/src/crud/StorageFactoryOptions.ts +4 -0
- package/src/ddl/GenerateOptions.ts +8 -0
- package/src/{ddl.ts → ddl/SqlSink.ts} +8 -21
- package/src/{dialect.ts → dialect/Dialect.ts} +2 -4
- package/src/dialect/DialectName.ts +1 -0
- package/src/{diff.ts → diff/Change.ts} +10 -17
- package/src/diff/SchemaState.ts +13 -0
- package/src/drift.ts +2 -2
- package/src/fields/Engine.ts +4 -0
- package/src/fields/SqlField.ts +6 -0
- package/src/{fields.ts → fields/SqlFields.ts} +5 -10
- package/src/index.ts +23 -22
- package/src/order/FkEdge.ts +7 -0
- package/src/{order.ts → order/TableOrder.ts} +2 -10
- package/src/query/QueryEvent.ts +16 -0
- package/src/{query.ts → query/QuerySink.ts} +16 -13
- package/src/source/Setup.ts +4 -0
- package/src/{source.ts → source/SqlSource.ts} +8 -18
- package/src/source/SqlSourceOptions.ts +8 -0
- package/src/{sqlite.ts → sqlite/SqliteSource.ts} +7 -12
- package/src/sqlite/SqliteSourceOptions.ts +6 -0
- package/src/sqlite/index.ts +2 -0
- package/src/{step.ts → step/Plan.ts} +8 -27
- package/src/step/PlanOptions.ts +8 -0
- package/src/step/Refusal.ts +6 -0
- package/src/step/StepChange.ts +4 -0
- package/src/table/AppLike.ts +10 -0
- package/src/table/ColumnDef.ts +34 -0
- package/src/table/ColumnReference.ts +5 -0
- package/src/table/EntityEntry.ts +7 -0
- package/src/table/FrondLike.ts +6 -0
- package/src/table/HostedNames.ts +7 -0
- package/src/table/RelationResolve.ts +12 -0
- package/src/{table.ts → table/TableDef.ts} +10 -77
- package/dist/crud.d.ts.map +0 -1
- package/dist/crud.js.map +0 -1
- package/dist/ddl.d.ts.map +0 -1
- package/dist/ddl.js.map +0 -1
- package/dist/dialect.d.ts.map +0 -1
- package/dist/dialect.js.map +0 -1
- package/dist/diff.d.ts.map +0 -1
- package/dist/diff.js.map +0 -1
- package/dist/fields.d.ts.map +0 -1
- package/dist/fields.js.map +0 -1
- package/dist/order.d.ts.map +0 -1
- package/dist/order.js.map +0 -1
- package/dist/query.d.ts +0 -19
- package/dist/query.d.ts.map +0 -1
- package/dist/query.js.map +0 -1
- package/dist/source.d.ts.map +0 -1
- package/dist/source.js.map +0 -1
- package/dist/sqlite.d.ts.map +0 -1
- package/dist/sqlite.js.map +0 -1
- package/dist/step.d.ts.map +0 -1
- package/dist/step.js.map +0 -1
- package/dist/table.d.ts +0 -97
- package/dist/table.d.ts.map +0 -1
- package/dist/table.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StepChange.d.ts","sourceRoot":"","sources":["../../src/step/StepChange.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GACjE;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StepChange.js","sourceRoot":"","sources":["../../src/step/StepChange.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type SchemaView } from '@fougere/schema';
|
|
2
|
+
import type { FrondLike } from './FrondLike.js';
|
|
3
|
+
export interface AppLike {
|
|
4
|
+
fronds: FrondLike[];
|
|
5
|
+
/** Auth runtime entities are migrated alongside scanned fronds when present. */
|
|
6
|
+
auth?: {
|
|
7
|
+
entities: Record<string, SchemaView>;
|
|
8
|
+
};
|
|
9
|
+
/** Entities this app hosts in ANOTHER source — named so a miss can be read. */
|
|
10
|
+
elsewhere?: string[];
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=AppLike.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppLike.d.ts","sourceRoot":"","sources":["../../src/table/AppLike.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,gFAAgF;IAChF,IAAI,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;KAAE,CAAC;IAChD,+EAA+E;IAC/E,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppLike.js","sourceRoot":"","sources":["../../src/table/AppLike.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ShapeType } from '@fougere/schema';
|
|
2
|
+
import { type ShapeBounds } from '../check.js';
|
|
3
|
+
import { type SqlField } from '../fields/SqlField.js';
|
|
4
|
+
import type { ColumnReference } from './ColumnReference.js';
|
|
5
|
+
/** One column, described by the axes — plus, at most, what the entity stated for sql. */
|
|
6
|
+
export interface ColumnDef {
|
|
7
|
+
/** Field key on the entity. */
|
|
8
|
+
field: string;
|
|
9
|
+
/** SQL column name (snake_case). */
|
|
10
|
+
name: string;
|
|
11
|
+
/** What every projection here dispatches on — a `date()` and a bounded set included. */
|
|
12
|
+
type?: ShapeType;
|
|
13
|
+
nullable: boolean;
|
|
14
|
+
primary: boolean;
|
|
15
|
+
/** A literal default (`lifecycle.create.value`), when the field declares one. */
|
|
16
|
+
default?: unknown;
|
|
17
|
+
/** A {@link Unique} of one — realized as a column constraint the database enforces. */
|
|
18
|
+
unique?: boolean;
|
|
19
|
+
/** `role.index` — realized as a separate `CREATE INDEX`, never a constraint. */
|
|
20
|
+
index?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* What the shape bounds beyond its type — `oneOf`, `min`, `max`. Realized as a
|
|
23
|
+
* `CHECK`, so the rule holds on every write and not only at the façade.
|
|
24
|
+
*/
|
|
25
|
+
bounds?: ShapeBounds;
|
|
26
|
+
/** The FK target, from `role.relation` when it's a `ref()` (kind `'one'`). */
|
|
27
|
+
references?: ColumnReference;
|
|
28
|
+
/**
|
|
29
|
+
* What the entity stated for THIS adapter — never an axis. It says how the column is
|
|
30
|
+
* realized here; drop it and the column is still describable.
|
|
31
|
+
*/
|
|
32
|
+
stated?: SqlField;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=ColumnDef.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColumnDef.d.ts","sourceRoot":"","sources":["../../src/table/ColumnDef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,yFAAyF;AACzF,MAAM,WAAW,SAAS;IACxB,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,wFAAwF;IACxF,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,iFAAiF;IACjF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uFAAuF;IACvF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gFAAgF;IAChF,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B;;;OAGG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColumnDef.js","sourceRoot":"","sources":["../../src/table/ColumnDef.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColumnReference.d.ts","sourceRoot":"","sources":["../../src/table/ColumnReference.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;CAChD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColumnReference.js","sourceRoot":"","sources":["../../src/table/ColumnReference.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type SchemaView } from '@fougere/schema';
|
|
2
|
+
export interface EntityEntry {
|
|
3
|
+
name: string;
|
|
4
|
+
/** A live class in-process, or one rebuilt from the card of a frond that never crossed. */
|
|
5
|
+
entityClass: SchemaView;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=EntityEntry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityEntry.d.ts","sourceRoot":"","sources":["../../src/table/EntityEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,2FAA2F;IAC3F,WAAW,EAAE,UAAU,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityEntry.js","sourceRoot":"","sources":["../../src/table/EntityEntry.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FrondLike.d.ts","sourceRoot":"","sources":["../../src/table/FrondLike.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FrondLike.js","sourceRoot":"","sources":["../../src/table/FrondLike.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** The two name sets a cross-source batch is read against — see {@link referenceFor}. */
|
|
2
|
+
export interface HostedNames {
|
|
3
|
+
/** Registration names in THIS batch. */
|
|
4
|
+
here: ReadonlySet<string>;
|
|
5
|
+
/** Registration names the app hosts in another source — see {@link AppLike.elsewhere}. */
|
|
6
|
+
elsewhere: ReadonlySet<string>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=HostedNames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HostedNames.d.ts","sourceRoot":"","sources":["../../src/table/HostedNames.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,MAAM,WAAW,WAAW;IAC1B,wCAAwC;IACxC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC1B,0FAA0F;IAC1F,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HostedNames.js","sourceRoot":"","sources":["../../src/table/HostedNames.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type SchemaView } from '@fougere/schema';
|
|
2
|
+
import type { HostedNames } from './HostedNames.js';
|
|
3
|
+
/** How a `ref()` field's target table+column is resolved — see {@link referenceFor}. */
|
|
4
|
+
export interface RelationResolve {
|
|
5
|
+
/** Same resolver used for every entity's own table (default or a custom `tableName`). */
|
|
6
|
+
resolve: (name: string) => string;
|
|
7
|
+
/** Live entity class → its already-resolved table name, reused instead of re-derived. */
|
|
8
|
+
tableNameOf?: Map<SchemaView, string>;
|
|
9
|
+
/** Which entities this batch holds and which live in another source — decided by NAME. */
|
|
10
|
+
hosted?: HostedNames;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=RelationResolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RelationResolve.d.ts","sourceRoot":"","sources":["../../src/table/RelationResolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,wFAAwF;AACxF,MAAM,WAAW,eAAe;IAC9B,yFAAyF;IACzF,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAClC,yFAAyF;IACzF,WAAW,CAAC,EAAE,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACtC,0FAA0F;IAC1F,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RelationResolve.js","sourceRoot":"","sources":["../../src/table/RelationResolve.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type SchemaView } from '@fougere/schema';
|
|
2
|
+
import type { ColumnDef } from './ColumnDef.js';
|
|
3
|
+
import type { RelationResolve } from './RelationResolve.js';
|
|
4
|
+
import type { AppLike } from './AppLike.js';
|
|
5
|
+
export interface TableDef {
|
|
6
|
+
name: string;
|
|
7
|
+
columns: ColumnDef[];
|
|
8
|
+
/** PK column names when the key is composite — empty for a simple key. */
|
|
9
|
+
compositePrimary: string[];
|
|
10
|
+
/** Column groups unique together, from `entity(fields, { unique: [...] })`. */
|
|
11
|
+
uniqueGroups: string[][];
|
|
12
|
+
}
|
|
13
|
+
/** camelCase → snake_case */
|
|
14
|
+
export declare function toSnakeCase(str: string): string;
|
|
15
|
+
/** Describe one entity as a table — the single reader of the axes. */
|
|
16
|
+
export declare function toTable(tableName: string, schema: SchemaView, relations?: RelationResolve): TableDef;
|
|
17
|
+
/**
|
|
18
|
+
* Is this column part of a key? MySQL and SQL Server refuse an unbounded text column in a primary
|
|
19
|
+
* key or an index, so the dialect needs to know.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isKeyed(table: TableDef, column: ColumnDef): boolean;
|
|
22
|
+
/** camelCase → snake_case + plural */
|
|
23
|
+
export declare function toTableName(name: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Every entity an app hosts, as FK-aware tables — the shared middle step behind `generateSQL` (a
|
|
26
|
+
* from-scratch create pass) and `desiredTables` (the diff's target state).
|
|
27
|
+
*/
|
|
28
|
+
export declare function toTables(app: AppLike, resolve: (name: string) => string): TableDef[];
|
|
29
|
+
//# sourceMappingURL=TableDef.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableDef.d.ts","sourceRoot":"","sources":["../../src/table/TableDef.ts"],"names":[],"mappings":"AACA,OAAO,EAAkC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAIlF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,0EAA0E;IAC1E,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,+EAA+E;IAC/E,YAAY,EAAE,MAAM,EAAE,EAAE,CAAC;CAC1B;AAED,6BAA6B;AAC7B,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE/C;AA8FD,sEAAsE;AACtE,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,eAAe,GAAG,QAAQ,CA6BpG;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAKnE;AAID,sCAAsC;AACtC,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AA+BD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,QAAQ,EAAE,CAOpF"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Lifecycle, Role } from '@fougere/schema';
|
|
2
|
-
/** Entity → table description, with no SQL in sight. */
|
|
3
2
|
import { Shapes, lowerFirst } from '@fougere/schema';
|
|
4
|
-
import { boundsOf } from '
|
|
5
|
-
import { sqlEntries } from '
|
|
3
|
+
import { boundsOf } from '../check.js';
|
|
4
|
+
import { sqlEntries } from '../fields/SqlFields.js';
|
|
6
5
|
/** camelCase → snake_case */
|
|
7
6
|
export function toSnakeCase(str) {
|
|
8
7
|
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
@@ -177,4 +176,4 @@ export function toTables(app, resolve) {
|
|
|
177
176
|
return entries.map((entry) => toTable(resolve(entry.name), entry.entityClass, { resolve, tableNameOf, hosted }));
|
|
178
177
|
}
|
|
179
178
|
// ─── Ordering — a referenced table before its referrer ─────────────────────
|
|
180
|
-
//# sourceMappingURL=
|
|
179
|
+
//# sourceMappingURL=TableDef.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableDef.js","sourceRoot":"","sources":["../../src/table/TableDef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAA+B,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAiBpD,6BAA6B;AAC7B,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,OAAO,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;AACvE,CAAC;AAED;;;GAGG;AACH,SAAS,QAAQ,CAAC,KAAY;IAC5B,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,YA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"description": "Entity → SQL tables through Kysely (SQLite, PostgreSQL, MySQL, SQL Server).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fougere",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"import": "./dist/index.js"
|
|
29
29
|
},
|
|
30
30
|
"./sqlite": {
|
|
31
|
-
"types": "./dist/sqlite.d.ts",
|
|
32
|
-
"import": "./dist/sqlite.js"
|
|
31
|
+
"types": "./dist/sqlite/index.d.ts",
|
|
32
|
+
"import": "./dist/sqlite/index.js"
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"better-sqlite3": "^13.0.3",
|
|
41
41
|
"dequal": "^2.0.3",
|
|
42
|
-
"@fougere/core": "0.
|
|
43
|
-
"@fougere/schema": "0.
|
|
42
|
+
"@fougere/core": "0.10.0-alpha.0",
|
|
43
|
+
"@fougere/schema": "0.10.0-alpha.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"kysely": ">=0.28.17"
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@types/better-sqlite3": "^7.6.13",
|
|
50
50
|
"@types/node": "^22.0.0",
|
|
51
51
|
"kysely": "^0.28.17",
|
|
52
|
-
"@fougere/core": "0.
|
|
52
|
+
"@fougere/core": "0.10.0-alpha.0"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
package/src/check.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Shape → CHECK constraints. */
|
|
2
2
|
import { sql, type Expression, type SqlBool } from 'kysely';
|
|
3
|
-
import type { ColumnDef } from './table.js';
|
|
3
|
+
import type { ColumnDef } from './table/ColumnDef.js';
|
|
4
4
|
|
|
5
5
|
/** What a column's shape can be checked for, beyond its type. */
|
|
6
6
|
export interface ShapeBounds {
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { Lifecycle, Role } from '@fougere/schema';
|
|
2
|
-
/** SqlStorage — per-entity storage over Kysely, one implementation for every engine. */
|
|
3
2
|
import { sql, type Kysely } from 'kysely';
|
|
4
3
|
import { applyCreate, applyUpdate, type Fields, type SchemaView } from '@fougere/schema';
|
|
5
|
-
import { toTable, toTableName, type TableDef } from '
|
|
6
|
-
import { resolveDialect, type Dialect
|
|
7
|
-
|
|
8
|
-
// lives there for that reason, and this package must not drag the boot to raise one.
|
|
4
|
+
import { toTable, toTableName, type TableDef } from '../table/TableDef.js';
|
|
5
|
+
import { resolveDialect, type Dialect } from '../dialect/Dialect.js';
|
|
6
|
+
import { type DialectName } from '../dialect/DialectName.js';
|
|
9
7
|
import { comparisonOf, comparisonsIn, ErrorCode, FougereError, type Comparison } from '@fougere/core/contract';
|
|
10
|
-
import { codecsOf, type ValueCodec } from '
|
|
8
|
+
import { codecsOf, type ValueCodec } from '../values.js';
|
|
9
|
+
import type { StorageFactoryOptions } from './StorageFactoryOptions.js';
|
|
11
10
|
|
|
12
11
|
/** ListOptions — duplicated from @fougere/core to avoid a runtime dep. */
|
|
13
12
|
interface ListOptions {
|
|
@@ -81,9 +80,9 @@ export class SqlStorage {
|
|
|
81
80
|
/** field → the value pair a driver needs; only for the shapes a driver can't bind. */
|
|
82
81
|
private codecs: Map<string, ValueCodec>;
|
|
83
82
|
|
|
84
|
-
/** How many keys one statement may carry here — see `Dialect.maxBindings`. */
|
|
85
83
|
/** Kept whole: the engine answers more than one question, and refusals are one of them. */
|
|
86
84
|
private dialect: Dialect;
|
|
85
|
+
/** How many keys one statement may carry here — see `Dialect.maxBindings`. */
|
|
87
86
|
private maxBindings: number;
|
|
88
87
|
/** How this engine spells an upsert, or `false` when it cannot — see `Dialect.upsert`. */
|
|
89
88
|
private upsertClause: 'on conflict' | 'on duplicate key' | false;
|
|
@@ -169,7 +168,7 @@ export class SqlStorage {
|
|
|
169
168
|
// A criterion may name a SET — `where: { id: [a, b, c] }` is `IN`, one query for a
|
|
170
169
|
// whole page. Without it a relation had no batch form at all: the GraphQL `one`
|
|
171
170
|
// resolver read row by row (50 calls for a page of 50, measured), while its `many`
|
|
172
|
-
// dual already went through this same
|
|
171
|
+
// dual already went through this same facade. An empty set matches nothing, said in
|
|
173
172
|
// SQL rather than by returning the whole table.
|
|
174
173
|
private whereAll<Q extends { where(a: any, b: any, c: any): Q }>(query: Q, criteria: Record<string, unknown>): Q {
|
|
175
174
|
return Object.entries(criteria).reduce((q, [key, value]) => {
|
|
@@ -518,12 +517,6 @@ export class SqlStorage {
|
|
|
518
517
|
}
|
|
519
518
|
}
|
|
520
519
|
|
|
521
|
-
|
|
522
|
-
export interface StorageFactoryOptions {
|
|
523
|
-
/** Override table name resolution. Default: camelCase → snake_case + 's'. */
|
|
524
|
-
tableName?: (entityName: string) => string;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
520
|
/** Create a StorageFactory backed by Kysely — same call shape on every engine. */
|
|
528
521
|
export function createStorageFactory(db: Kysely<any>, options?: StorageFactoryOptions, dialect: DialectName = 'sqlite') {
|
|
529
522
|
const resolve = options?.tableName ?? toTableName;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type DialectName } from '../dialect/DialectName.js';
|
|
2
|
+
|
|
3
|
+
export interface GenerateOptions {
|
|
4
|
+
/** Override table name resolution. Default: camelCase → snake_case + 's'. */
|
|
5
|
+
tableName?: (entityName: string) => string;
|
|
6
|
+
/** Target engine. Default: sqlite. */
|
|
7
|
+
dialect?: DialectName;
|
|
8
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** DDL — the table description, rendered as SQL. */
|
|
2
1
|
import {
|
|
3
2
|
Kysely,
|
|
4
3
|
DummyDriver,
|
|
@@ -8,19 +7,14 @@ import {
|
|
|
8
7
|
MysqlAdapter, MysqlQueryCompiler, MysqlIntrospector,
|
|
9
8
|
MssqlAdapter, MssqlQueryCompiler, MssqlIntrospector,
|
|
10
9
|
} from 'kysely';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from './
|
|
19
|
-
import { orderTables } from './order.js';
|
|
20
|
-
import { columnTypeFor, resolveDialect, type DialectName } from './dialect.js';
|
|
21
|
-
import { checkFor } from './check.js';
|
|
22
|
-
|
|
23
|
-
// ─── Compile-only engines ──────────────────────────
|
|
10
|
+
import { type AppLike } from '../table/AppLike.js';
|
|
11
|
+
import { type ColumnDef } from '../table/ColumnDef.js';
|
|
12
|
+
import { isKeyed, toTableName, toTables, type TableDef } from '../table/TableDef.js';
|
|
13
|
+
import { orderTables } from '../order/TableOrder.js';
|
|
14
|
+
import { columnTypeFor, resolveDialect } from '../dialect/Dialect.js';
|
|
15
|
+
import { type DialectName } from '../dialect/DialectName.js';
|
|
16
|
+
import { checkFor } from '../check.js';
|
|
17
|
+
import type { GenerateOptions } from './GenerateOptions.js';
|
|
24
18
|
|
|
25
19
|
const parts = {
|
|
26
20
|
sqlite: [SqliteAdapter, SqliteQueryCompiler, SqliteIntrospector],
|
|
@@ -139,13 +133,6 @@ export function addForeignKeyConstraintSQL(table: TableDef, column: ColumnDef, d
|
|
|
139
133
|
|
|
140
134
|
// ─── App-wide generation ───────────────────────────
|
|
141
135
|
|
|
142
|
-
export interface GenerateOptions {
|
|
143
|
-
/** Override table name resolution. Default: camelCase → snake_case + 's'. */
|
|
144
|
-
tableName?: (entityName: string) => string;
|
|
145
|
-
/** Target engine. Default: sqlite. */
|
|
146
|
-
dialect?: DialectName;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
136
|
/**
|
|
150
137
|
* `CREATE TABLE` for every entity the app hosts — scanned frond entities plus auth runtime
|
|
151
138
|
* entities when present.
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
export type DialectName = 'sqlite' | 'pg' | 'mysql' | 'mssql';
|
|
1
|
+
import type { ColumnDef } from '../table/ColumnDef.js';
|
|
2
|
+
import type { DialectName } from './DialectName.js';
|
|
5
3
|
|
|
6
4
|
export interface Dialect {
|
|
7
5
|
name: DialectName;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type DialectName = 'sqlite' | 'pg' | 'mysql' | 'mssql';
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
/** Diff — what the database is missing, compared to what the entities describe. */
|
|
2
1
|
import { sql, type Kysely } from 'kysely';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from './table.js';
|
|
14
|
-
import { orderTables } from './order.js';
|
|
15
|
-
|
|
16
|
-
/** What the database actually holds: column names per table. */
|
|
17
|
-
export type SchemaState = Map<string, Set<string>>;
|
|
2
|
+
import { type GenerateOptions } from '../ddl/GenerateOptions.js';
|
|
3
|
+
import { addForeignKeyConstraintSQL, compiler, createTableSQL, indexSQL } from '../ddl/SqlSink.js';
|
|
4
|
+
import { checkFor } from '../check.js';
|
|
5
|
+
import { columnTypeFor, resolveDialect } from '../dialect/Dialect.js';
|
|
6
|
+
import { type DialectName } from '../dialect/DialectName.js';
|
|
7
|
+
import { type AppLike } from '../table/AppLike.js';
|
|
8
|
+
import { type ColumnDef } from '../table/ColumnDef.js';
|
|
9
|
+
import { isKeyed, toTableName, toTables, type TableDef } from '../table/TableDef.js';
|
|
10
|
+
import { orderTables } from '../order/TableOrder.js';
|
|
11
|
+
import type { SchemaState } from './SchemaState.js';
|
|
18
12
|
|
|
19
13
|
/** Read the live schema. Only names are needed — an additive pass never inspects types. */
|
|
20
14
|
export async function actualState(db: Kysely<any>): Promise<SchemaState> {
|
|
@@ -149,7 +143,6 @@ export async function planMigration(
|
|
|
149
143
|
}
|
|
150
144
|
|
|
151
145
|
/** Bring the database up to what the entities describe — additively. */
|
|
152
|
-
/** Bring the schema up to date. */
|
|
153
146
|
export async function migrate(
|
|
154
147
|
app: AppLike,
|
|
155
148
|
target: Kysely<any> | { db: Kysely<any> },
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
/** What the database actually holds: column names per table. */
|
|
3
|
+
export type SchemaState = Map<string, Set<string>>;
|
|
4
|
+
|
|
5
|
+
/** Read the live schema. Only names are needed — an additive pass never inspects types. */
|
|
6
|
+
export async function actualState(db: Kysely<any>): Promise<SchemaState> {
|
|
7
|
+
const state: SchemaState = new Map();
|
|
8
|
+
for (const table of await db.introspection.getTables()) {
|
|
9
|
+
if (table.isView) continue;
|
|
10
|
+
state.set(table.name, new Set(table.columns.map((column) => column.name)));
|
|
11
|
+
}
|
|
12
|
+
return state;
|
|
13
|
+
}
|
package/src/drift.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** What a table PROMISES and what it now holds, when the two stopped agreeing. */
|
|
2
2
|
import type { Kysely } from 'kysely';
|
|
3
3
|
|
|
4
|
-
import type { TableDef } from './table.js';
|
|
4
|
+
import type { TableDef } from './table/TableDef.js';
|
|
5
5
|
|
|
6
6
|
/** One column whose declaration moved and whose table did not follow. */
|
|
7
7
|
export interface Drift {
|
|
@@ -58,7 +58,7 @@ export async function drift(db: Kysely<any>, desired: TableDef[]): Promise<Drift
|
|
|
58
58
|
column: column.name,
|
|
59
59
|
declared: 'required',
|
|
60
60
|
held: 'nullable',
|
|
61
|
-
reason: 'the
|
|
61
|
+
reason: 'the facade refuses what the table would still accept',
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -3,24 +3,19 @@
|
|
|
3
3
|
* no engine and no column type, and must not learn one to let this exist.
|
|
4
4
|
*/
|
|
5
5
|
import { AdapterFieldValidator, type Shape } from '@fougere/schema';
|
|
6
|
-
import ENTRY_FORMAT from '
|
|
7
|
-
import type { DialectName } from '
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type Engine = keyof typeof ENTRY_FORMAT.properties.columnType.properties;
|
|
6
|
+
import ENTRY_FORMAT from '../adapter.schema.json' with { type: 'json' };
|
|
7
|
+
import type { DialectName } from '../dialect/DialectName.js';
|
|
8
|
+
import type { SqlField } from './SqlField.js';
|
|
9
|
+
import type { Engine } from './Engine.js';
|
|
11
10
|
|
|
12
11
|
/** What sql holds, addressed by field — the shape every augmentation of the registry takes. */
|
|
13
12
|
export type SqlFields<K extends string> = Readonly<Partial<Record<K, SqlField>>>;
|
|
14
13
|
|
|
15
|
-
export interface SqlField {
|
|
16
|
-
/** The column type to emit, per engine. An engine absent here keeps the shape's own. */
|
|
17
|
-
readonly columnType?: Readonly<Partial<Record<Engine, string>>>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
14
|
/** Judges what an entity states under `adapters.sql`, against the format this adapter ships. */
|
|
21
15
|
export const sqlEntries = AdapterFieldValidator.of(ENTRY_FORMAT as Shape);
|
|
22
16
|
|
|
23
17
|
type Assert<T extends true> = T;
|
|
18
|
+
|
|
24
19
|
/** A fifth dialect does not compile until `adapter.schema.json` names it. */
|
|
25
20
|
type _EnginesMatchDialects = Assert<
|
|
26
21
|
[Exclude<DialectName, Engine>] extends [never] ? true : false
|
package/src/index.ts
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { onQuery } from './query.js';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from './table.js';
|
|
10
|
-
export {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from './
|
|
14
|
-
export
|
|
15
|
-
export type { SqlField, SqlFields } from './fields.js';
|
|
16
|
-
export { SqlStorage, createStorageFactory } from './crud.js';
|
|
1
|
+
export { autoMigrate, compiler, createTableSQL, generateSQL } from './ddl/SqlSink.js';
|
|
2
|
+
export { onQuery } from './query/QuerySink.js';
|
|
3
|
+
export type { QueryEvent } from './query/QueryEvent.js';
|
|
4
|
+
export type { QuerySink } from './query/QuerySink.js';
|
|
5
|
+
export { toSnakeCase, toTable, toTableName, toTables } from './table/TableDef.js';
|
|
6
|
+
export { orderTables } from './order/TableOrder.js';
|
|
7
|
+
export type { AppLike } from './table/AppLike.js';
|
|
8
|
+
export type { EntityEntry } from './table/EntityEntry.js';
|
|
9
|
+
export type { FrondLike } from './table/FrondLike.js';
|
|
10
|
+
export { columnTypeFor, dialects } from './dialect/Dialect.js';
|
|
11
|
+
export type { Dialect } from './dialect/Dialect.js';
|
|
12
|
+
export type { SqlField } from './fields/SqlField.js';
|
|
13
|
+
export type { SqlFields } from './fields/SqlFields.js';
|
|
14
|
+
export { SqlStorage, createStorageFactory } from './crud/SqlStorage.js';
|
|
17
15
|
export { codecsOf } from './values.js';
|
|
18
16
|
// The driver this package owns is NOT here: `better-sqlite3` is native and `node:fs` is a
|
|
19
17
|
// builtin, and an index that re-exported them made the whole adapter unreachable from a
|
|
20
18
|
// runtime that has neither. It lives at `@fougere/adapter-sql/sqlite`.
|
|
21
|
-
export { createKyselySource } from './source.js';
|
|
22
|
-
export type { SqlSource } from './source.js';
|
|
19
|
+
export { createKyselySource } from './source/SqlSource.js';
|
|
20
|
+
export type { SqlSource } from './source/SqlSource.js';
|
|
23
21
|
export { drift } from './drift.js';
|
|
24
22
|
export type { Drift } from './drift.js';
|
|
25
|
-
export { actualState
|
|
26
|
-
export
|
|
23
|
+
export { actualState } from './diff/SchemaState.js';
|
|
24
|
+
export { changeSQL, delta, desiredTables, migrate } from './diff/Change.js';
|
|
25
|
+
export type { Change } from './diff/Change.js';
|
|
26
|
+
export type { SchemaState } from './diff/SchemaState.js';
|
|
27
27
|
// The non-additive half — realised only from a step a human wrote down.
|
|
28
|
-
export {
|
|
29
|
-
export type { Plan
|
|
28
|
+
export { applyStep, collapseChain, planStep } from './step/Plan.js';
|
|
29
|
+
export type { Plan } from './step/Plan.js';
|
|
30
|
+
export type { StepChange } from './step/StepChange.js';
|