@livestore/common 0.3.2-dev.1 → 0.3.2-dev.6
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/.tsbuildinfo +1 -1
- package/dist/devtools/devtools-messages-client-session.d.ts +21 -21
- package/dist/devtools/devtools-messages-common.d.ts +6 -6
- package/dist/devtools/devtools-messages-leader.d.ts +24 -24
- package/dist/schema/EventDef.d.ts +178 -132
- package/dist/schema/EventDef.d.ts.map +1 -1
- package/dist/schema/EventDef.js +0 -15
- package/dist/schema/EventDef.js.map +1 -1
- package/dist/schema/schema.d.ts +1 -5
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/schema.js +0 -2
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.d.ts +12 -0
- package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.js +12 -0
- package/dist/schema/state/sqlite/client-document-def.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/dsl/mod.d.ts +165 -65
- package/dist/schema/state/sqlite/mod.d.ts +1 -1
- package/dist/schema/state/sqlite/mod.d.ts.map +1 -1
- package/dist/schema/state/sqlite/mod.js +0 -2
- package/dist/schema/state/sqlite/mod.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/api.d.ts +560 -307
- package/dist/schema/state/sqlite/table-def.d.ts +152 -70
- package/dist/sql-queries/types.d.ts +133 -37
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +10 -49
- package/src/schema/EventDef.ts +1 -21
- package/src/schema/schema.ts +3 -6
- package/src/schema/state/sqlite/client-document-def.ts +12 -0
- package/src/schema/state/sqlite/mod.ts +1 -3
- package/src/version.ts +1 -1
@@ -1,40 +1,79 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
3
|
-
import
|
4
|
-
import type
|
5
|
-
|
6
|
-
export * from
|
1
|
+
import type { Option, Schema, Types } from "@livestore/utils/effect";
|
2
|
+
import type { Nullable } from "../../../../../../../utils/dist/mod.ts";
|
3
|
+
import type * as SqliteAst from "../ast/sqlite.ts";
|
4
|
+
import type { ColumnDefinition } from "./field-defs.ts";
|
5
|
+
|
6
|
+
export * from "./field-defs.ts";
|
7
7
|
export type DbSchema = {
|
8
|
-
|
8
|
+
[key: string]: TableDefinition<string, Columns>;
|
9
9
|
};
|
10
10
|
/** Note when using the object-notation, the object keys are ignored and not used as table names */
|
11
|
-
export type DbSchemaInput =
|
11
|
+
export type DbSchemaInput =
|
12
|
+
| Record<string, TableDefinition<any, any>>
|
13
|
+
| ReadonlyArray<TableDefinition<any, any>>;
|
12
14
|
/**
|
13
15
|
* In case of ...
|
14
16
|
* - array: we use the table name of each array item (= table definition) as the object key
|
15
17
|
* - object: we discard the keys of the input object and use the table name of each object value (= table definition) as the new object key
|
16
18
|
*/
|
17
|
-
export type DbSchemaFromInputSchema<TSchemaInput extends DbSchemaInput> =
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
export
|
28
|
-
|
29
|
-
|
19
|
+
export type DbSchemaFromInputSchema<TSchemaInput extends DbSchemaInput> =
|
20
|
+
TSchemaInput extends ReadonlyArray<TableDefinition<any, any>>
|
21
|
+
? {
|
22
|
+
[K in TSchemaInput[number] as K["name"]]: K;
|
23
|
+
}
|
24
|
+
: TSchemaInput extends Record<string, TableDefinition<any, any>>
|
25
|
+
? {
|
26
|
+
[K in keyof TSchemaInput as TSchemaInput[K]["name"]]: TSchemaInput[K];
|
27
|
+
}
|
28
|
+
: never;
|
29
|
+
export declare const makeDbSchema: <TDbSchemaInput extends DbSchemaInput>(
|
30
|
+
schema: TDbSchemaInput,
|
31
|
+
) => DbSchemaFromInputSchema<TDbSchemaInput>;
|
32
|
+
export declare const table: <
|
33
|
+
TTableName extends string,
|
34
|
+
TColumns extends Columns,
|
35
|
+
TIndexes extends Index[],
|
36
|
+
>(
|
37
|
+
name: TTableName,
|
38
|
+
columns: TColumns,
|
39
|
+
indexes?: TIndexes,
|
40
|
+
) => TableDefinition<TTableName, TColumns>;
|
41
|
+
export type AnyIfConstained<In, Out> = "__constrained" extends keyof In
|
42
|
+
? any
|
43
|
+
: Out;
|
44
|
+
export type EmptyObjIfConstained<In> = "__constrained" extends keyof In
|
45
|
+
? {}
|
46
|
+
: In;
|
47
|
+
export type StructSchemaForColumns<TCols extends ConstraintColumns> =
|
48
|
+
Schema.Schema<
|
49
|
+
AnyIfConstained<TCols, FromColumns.RowDecoded<TCols>>,
|
50
|
+
AnyIfConstained<TCols, FromColumns.RowEncoded<TCols>>
|
51
|
+
>;
|
52
|
+
export type InsertStructSchemaForColumns<TCols extends ConstraintColumns> =
|
53
|
+
Schema.Schema<
|
54
|
+
AnyIfConstained<TCols, FromColumns.InsertRowDecoded<TCols>>,
|
55
|
+
AnyIfConstained<TCols, FromColumns.InsertRowEncoded<TCols>>
|
56
|
+
>;
|
57
|
+
export declare const structSchemaForTable: <
|
58
|
+
TTableDefinition extends TableDefinition<any, any>,
|
59
|
+
>(
|
60
|
+
tableDef: TTableDefinition,
|
61
|
+
) => StructSchemaForColumns<TTableDefinition["columns"]>;
|
62
|
+
export declare const insertStructSchemaForTable: <
|
63
|
+
TTableDefinition extends TableDefinition<any, any>,
|
64
|
+
>(
|
65
|
+
tableDef: TTableDefinition,
|
66
|
+
) => InsertStructSchemaForColumns<TTableDefinition["columns"]>;
|
30
67
|
export type TableDefinition<TName extends string, TColumns extends Columns> = {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
68
|
+
name: TName;
|
69
|
+
columns: TColumns;
|
70
|
+
indexes?: ReadonlyArray<Index>;
|
71
|
+
ast: SqliteAst.Table;
|
35
72
|
};
|
36
73
|
export type Columns = Record<string, ColumnDefinition<any, any>>;
|
37
|
-
export type IsSingleColumn<
|
74
|
+
export type IsSingleColumn<
|
75
|
+
TColumns extends Columns | ColumnDefinition<any, any>,
|
76
|
+
> = TColumns extends ColumnDefinition<any, any> ? true : false;
|
38
77
|
/**
|
39
78
|
* NOTE this is only needed to avoid a TS limitation where `StructSchemaForColumns` in the default case
|
40
79
|
* results in `Record<string, any>` instead of `any`. (Thanks to Andarist for the workaround)
|
@@ -42,49 +81,110 @@ export type IsSingleColumn<TColumns extends Columns | ColumnDefinition<any, any>
|
|
42
81
|
* Hopefully this can be removed in the future
|
43
82
|
*/
|
44
83
|
export type ConstraintColumns = Record<string, ColumnDefinition<any, any>> & {
|
45
|
-
|
84
|
+
__constrained?: never;
|
46
85
|
};
|
47
86
|
export type Index = {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
87
|
+
name: string;
|
88
|
+
columns: ReadonlyArray<string>;
|
89
|
+
/** @default false */
|
90
|
+
isUnique?: boolean;
|
52
91
|
};
|
53
92
|
export declare namespace FromTable {
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
93
|
+
type RowDecoded<TTableDefinition extends TableDefinition<any, any>> =
|
94
|
+
Types.Simplify<
|
95
|
+
Nullable<
|
96
|
+
Pick<
|
97
|
+
RowDecodedAll<TTableDefinition>,
|
98
|
+
NullableColumnNames<TTableDefinition>
|
99
|
+
>
|
100
|
+
> &
|
101
|
+
Omit<
|
102
|
+
RowDecodedAll<TTableDefinition>,
|
103
|
+
NullableColumnNames<TTableDefinition>
|
104
|
+
>
|
105
|
+
>;
|
106
|
+
type NullableColumnNames<TTableDefinition extends TableDefinition<any, any>> =
|
107
|
+
FromColumns.NullableColumnNames<TTableDefinition["columns"]>;
|
108
|
+
type Columns<TTableDefinition extends TableDefinition<any, any>> = {
|
109
|
+
[K in keyof TTableDefinition["columns"]]: TTableDefinition["columns"][K]["columnType"];
|
110
|
+
};
|
111
|
+
type RowEncodeNonNullable<
|
112
|
+
TTableDefinition extends TableDefinition<any, any>,
|
113
|
+
> = {
|
114
|
+
[K in keyof TTableDefinition["columns"]]: Schema.Schema.Encoded<
|
115
|
+
TTableDefinition["columns"][K]["schema"]
|
116
|
+
>;
|
117
|
+
};
|
118
|
+
type RowEncoded<TTableDefinition extends TableDefinition<any, any>> =
|
119
|
+
Types.Simplify<
|
120
|
+
Nullable<
|
121
|
+
Pick<
|
122
|
+
RowEncodeNonNullable<TTableDefinition>,
|
123
|
+
NullableColumnNames<TTableDefinition>
|
124
|
+
>
|
125
|
+
> &
|
126
|
+
Omit<
|
127
|
+
RowEncodeNonNullable<TTableDefinition>,
|
128
|
+
NullableColumnNames<TTableDefinition>
|
129
|
+
>
|
130
|
+
>;
|
131
|
+
type RowDecodedAll<TTableDefinition extends TableDefinition<any, any>> = {
|
132
|
+
[K in keyof TTableDefinition["columns"]]: Schema.Schema.Type<
|
133
|
+
TTableDefinition["columns"][K]["schema"]
|
134
|
+
>;
|
135
|
+
};
|
66
136
|
}
|
67
137
|
export declare namespace FromColumns {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
138
|
+
type RowDecoded<TColumns extends Columns> = Types.Simplify<
|
139
|
+
Nullable<Pick<RowDecodedAll<TColumns>, NullableColumnNames<TColumns>>> &
|
140
|
+
Omit<RowDecodedAll<TColumns>, NullableColumnNames<TColumns>>
|
141
|
+
>;
|
142
|
+
type RowDecodedAll<TColumns extends Columns> = {
|
143
|
+
readonly [K in keyof TColumns]: Schema.Schema.Type<TColumns[K]["schema"]>;
|
144
|
+
};
|
145
|
+
type RowEncodedAll<TColumns extends Columns> = {
|
146
|
+
readonly [K in keyof TColumns]: Schema.Schema.Encoded<
|
147
|
+
TColumns[K]["schema"]
|
148
|
+
>;
|
149
|
+
};
|
150
|
+
type RowEncoded<TColumns extends Columns> = Types.Simplify<
|
151
|
+
Nullable<
|
152
|
+
Pick<RowEncodeNonNullable<TColumns>, NullableColumnNames<TColumns>>
|
153
|
+
> &
|
154
|
+
Omit<RowEncodeNonNullable<TColumns>, NullableColumnNames<TColumns>>
|
155
|
+
>;
|
156
|
+
type RowEncodeNonNullable<TColumns extends Columns> = {
|
157
|
+
readonly [K in keyof TColumns]: Schema.Schema.Encoded<
|
158
|
+
TColumns[K]["schema"]
|
159
|
+
>;
|
160
|
+
};
|
161
|
+
type NullableColumnNames<TColumns extends Columns> = keyof {
|
162
|
+
[K in keyof TColumns as TColumns[K] extends ColumnDefinition<any, true>
|
163
|
+
? K
|
164
|
+
: never]: {};
|
165
|
+
};
|
166
|
+
type RequiredInsertColumns<TColumns extends Columns> = {
|
167
|
+
[K in keyof TColumns as TColumns[K]["nullable"] extends true
|
168
|
+
? never
|
169
|
+
: TColumns[K]["default"] extends Option.Some<any>
|
170
|
+
? never
|
171
|
+
: K]: {};
|
172
|
+
};
|
173
|
+
type RequiredInsertColumnNames<TColumns extends Columns> =
|
174
|
+
keyof RequiredInsertColumns<TColumns>;
|
175
|
+
type RequiresInsertValues<TColumns extends Columns> =
|
176
|
+
RequiredInsertColumnNames<TColumns> extends never ? false : true;
|
177
|
+
type InsertRowDecoded<TColumns extends Columns> = Types.Simplify<
|
178
|
+
Pick<RowDecodedAll<TColumns>, RequiredInsertColumnNames<TColumns>> &
|
179
|
+
Partial<
|
180
|
+
Omit<RowDecodedAll<TColumns>, RequiredInsertColumnNames<TColumns>>
|
181
|
+
>
|
182
|
+
>;
|
183
|
+
type InsertRowEncoded<TColumns extends Columns> = Types.Simplify<
|
184
|
+
Pick<RowEncodedAll<TColumns>, RequiredInsertColumnNames<TColumns>> &
|
185
|
+
Partial<
|
186
|
+
Omit<RowEncodedAll<TColumns>, RequiredInsertColumnNames<TColumns>>
|
187
|
+
>
|
188
|
+
>;
|
89
189
|
}
|
90
|
-
//# sourceMappingURL=mod.d.ts.map
|
190
|
+
//# sourceMappingURL=mod.d.ts.map
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { MigrationOptions } from '../../../adapter-types.ts';
|
2
|
-
import {
|
2
|
+
import type { Materializer } from '../../EventDef.ts';
|
3
3
|
import type { InternalState } from '../../schema.ts';
|
4
4
|
import type { TableDefBase } from './table-def.ts';
|
5
5
|
export * from '../../EventDef.ts';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/schema/state/sqlite/mod.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/schema/state/sqlite/mod.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAIpD,OAAO,KAAK,EAAY,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE5D,cAAc,mBAAmB,CAAA;AACjC,OAAO,EACL,KAAK,sBAAsB,EAC3B,4BAA4B,EAC5B,KAAK,0BAA0B,EAC/B,cAAc,EACd,0BAA0B,GAC3B,MAAM,0BAA0B,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAE9B,eAAO,MAAM,SAAS,GAAI,WAAW,SAAS,UAAU,EAAE,aAAa,WAAW,KAAG,aAyCpF,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,aAAa,CAAC,YAAY,CAAC,CAAA;IAC3E,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;IACzD;;OAEG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAA;CACvC,CAAA"}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import { shouldNeverHappen } from '@livestore/utils';
|
2
|
-
import { rawSqlEvent, rawSqlMaterializer } from "../../EventDef.js";
|
3
2
|
import { ClientDocumentTableDefSymbol, tableIsClientDocumentTable } from "./client-document-def.js";
|
4
3
|
import { SqliteAst } from "./db-schema/mod.js";
|
5
4
|
import { stateSystemTables } from "./system-tables.js";
|
@@ -26,7 +25,6 @@ export const makeState = (inputSchema) => {
|
|
26
25
|
for (const [name, materializer] of Object.entries(inputSchema.materializers)) {
|
27
26
|
materializers.set(name, materializer);
|
28
27
|
}
|
29
|
-
materializers.set(rawSqlEvent.name, rawSqlMaterializer);
|
30
28
|
for (const tableDef of inputTables) {
|
31
29
|
if (tableIsClientDocumentTable(tableDef)) {
|
32
30
|
materializers.set(tableDef[ClientDocumentTableDefSymbol].derived.setEventDef.name, tableDef[ClientDocumentTableDefSymbol].derived.setMaterializer);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../../src/schema/state/sqlite/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../../src/schema/state/sqlite/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAKpD,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAA;AACnG,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAGtD,cAAc,mBAAmB,CAAA;AACjC,OAAO,EAEL,4BAA4B,EAE5B,cAAc,EACd,0BAA0B,GAC3B,M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