@sidekickdb/core 2.0.0 → 3.0.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/README.md +1 -1
- package/__example__/standalone.esm.html +1 -1
- package/__example__/standalone.umd.html +2 -2
- package/__tests__/src/Reactor.test.ts +70 -25
- package/__tests__/src/batchedFrames.test.ts +110 -0
- package/__tests__/src/createRouteHandler.test.ts +30 -0
- package/__tests__/src/data/zeneca/triples.json +6 -6
- package/__tests__/src/dataForQueryMemo.test.ts +4 -4
- package/__tests__/src/datalog.test.ts +2 -2
- package/__tests__/src/devtool.test.ts +2 -2
- package/__tests__/src/endpoints.test.ts +2 -2
- package/__tests__/src/infiniteQuery.test.ts +142 -0
- package/__tests__/src/notifyScope.test.ts +6 -6
- package/__tests__/src/queryValidation.test.ts +3 -3
- package/__tests__/src/schema.test.ts +6 -6
- package/__tests__/src/serializeSchema.test.ts +2 -2
- package/__tests__/src/{instaml.test.ts → sideml.test.ts} +106 -112
- package/__tests__/src/{instaql.bench.ts → sideql.bench.ts} +1 -1
- package/__tests__/src/{instaql.test.ts → sideql.test.ts} +25 -34
- package/__tests__/src/{instaqlInference.test.ts → sideqlInference.test.ts} +1 -1
- package/__tests__/src/store.test.ts +32 -32
- package/__tests__/src/transactionValidation.test.ts +4 -4
- package/__tests__/src/utils/e2e.ts +8 -8
- package/dist/commonjs/Connection.d.ts +1 -0
- package/dist/commonjs/Connection.d.ts.map +1 -1
- package/dist/commonjs/Connection.js +19 -3
- package/dist/commonjs/Connection.js.map +1 -1
- package/dist/commonjs/IndexedDBStorage.d.ts.map +1 -1
- package/dist/commonjs/IndexedDBStorage.js +3 -160
- package/dist/commonjs/IndexedDBStorage.js.map +1 -1
- package/dist/commonjs/Reactor.d.ts +7 -7
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +37 -38
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/{InstantError.d.ts → SidekickError.d.ts} +2 -2
- package/dist/commonjs/SidekickError.d.ts.map +1 -0
- package/dist/commonjs/{InstantError.js → SidekickError.js} +7 -7
- package/dist/commonjs/SidekickError.js.map +1 -0
- package/dist/commonjs/Stream.d.ts +5 -5
- package/dist/commonjs/Stream.d.ts.map +1 -1
- package/dist/commonjs/Stream.js +14 -14
- package/dist/commonjs/Stream.js.map +1 -1
- package/dist/commonjs/SyncTable.d.ts +3 -3
- package/dist/commonjs/SyncTable.d.ts.map +1 -1
- package/dist/commonjs/SyncTable.js +7 -7
- package/dist/commonjs/SyncTable.js.map +1 -1
- package/dist/commonjs/attrTypes.d.ts +11 -11
- package/dist/commonjs/attrTypes.d.ts.map +1 -1
- package/dist/commonjs/attrTypes.js.map +1 -1
- package/dist/commonjs/coreTypes.d.ts +4 -4
- package/dist/commonjs/coreTypes.d.ts.map +1 -1
- package/dist/commonjs/coreTypes.js.map +1 -1
- package/dist/commonjs/createRouteHandler.d.ts +1 -1
- package/dist/commonjs/createRouteHandler.d.ts.map +1 -1
- package/dist/commonjs/createRouteHandler.js +5 -5
- package/dist/commonjs/createRouteHandler.js.map +1 -1
- package/dist/commonjs/devtool.js +13 -6
- package/dist/commonjs/devtool.js.map +1 -1
- package/dist/commonjs/endpoints.d.ts +2 -2
- package/dist/commonjs/endpoints.d.ts.map +1 -1
- package/dist/commonjs/endpoints.js +3 -3
- package/dist/commonjs/endpoints.js.map +1 -1
- package/dist/commonjs/framework.d.ts +4 -4
- package/dist/commonjs/framework.d.ts.map +1 -1
- package/dist/commonjs/framework.js +5 -5
- package/dist/commonjs/framework.js.map +1 -1
- package/dist/commonjs/helperTypes.d.ts +24 -24
- package/dist/commonjs/helperTypes.d.ts.map +1 -1
- package/dist/commonjs/helperTypes.js.map +1 -1
- package/dist/commonjs/index.d.ts +36 -36
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +36 -36
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/infiniteQuery.d.ts +7 -7
- package/dist/commonjs/infiniteQuery.d.ts.map +1 -1
- package/dist/commonjs/infiniteQuery.js +16 -3
- package/dist/commonjs/infiniteQuery.js.map +1 -1
- package/dist/commonjs/model/{instaqlResult.d.ts → sideqlResult.d.ts} +2 -2
- package/dist/commonjs/model/sideqlResult.d.ts.map +1 -0
- package/dist/commonjs/model/{instaqlResult.js → sideqlResult.js} +2 -2
- package/dist/commonjs/model/sideqlResult.js.map +1 -0
- package/dist/commonjs/notifyScope.js +3 -3
- package/dist/commonjs/notifyScope.js.map +1 -1
- package/dist/commonjs/parseSchemaFromJSON.d.ts +2 -2
- package/dist/commonjs/parseSchemaFromJSON.d.ts.map +1 -1
- package/dist/commonjs/parseSchemaFromJSON.js.map +1 -1
- package/dist/commonjs/queryTypes.d.ts +32 -32
- package/dist/commonjs/queryTypes.d.ts.map +1 -1
- package/dist/commonjs/queryTypes.js.map +1 -1
- package/dist/commonjs/routeHandlerProtocol.d.ts +7 -7
- package/dist/commonjs/routeHandlerProtocol.d.ts.map +1 -1
- package/dist/commonjs/routeHandlerProtocol.js.map +1 -1
- package/dist/commonjs/rulesTypes.d.ts +20 -20
- package/dist/commonjs/rulesTypes.d.ts.map +1 -1
- package/dist/commonjs/rulesTypes.js.map +1 -1
- package/dist/commonjs/sanityCheckQueries.d.ts +3 -3
- package/dist/commonjs/sanityCheckQueries.d.ts.map +1 -1
- package/dist/commonjs/sanityCheckQueries.js.map +1 -1
- package/dist/commonjs/schema.d.ts +3 -3
- package/dist/commonjs/schema.d.ts.map +1 -1
- package/dist/commonjs/schema.js +2 -2
- package/dist/commonjs/schema.js.map +1 -1
- package/dist/commonjs/schemaTypes.d.ts +8 -8
- package/dist/commonjs/schemaTypes.d.ts.map +1 -1
- package/dist/commonjs/schemaTypes.js +9 -9
- package/dist/commonjs/schemaTypes.js.map +1 -1
- package/dist/commonjs/{instaml.d.ts → sideml.d.ts} +1 -1
- package/dist/commonjs/sideml.d.ts.map +1 -0
- package/dist/commonjs/{instaml.js → sideml.js} +10 -7
- package/dist/commonjs/sideml.js.map +1 -0
- package/dist/commonjs/{instaql.d.ts → sideql.d.ts} +1 -1
- package/dist/commonjs/sideql.d.ts.map +1 -0
- package/dist/commonjs/{instaql.js → sideql.js} +1 -1
- package/dist/commonjs/sideql.js.map +1 -0
- package/dist/commonjs/{instatx.d.ts → sidetx.d.ts} +1 -1
- package/dist/commonjs/sidetx.d.ts.map +1 -0
- package/dist/commonjs/{instatx.js → sidetx.js} +1 -1
- package/dist/commonjs/sidetx.js.map +1 -0
- package/dist/commonjs/store.d.ts +22 -22
- package/dist/commonjs/store.d.ts.map +1 -1
- package/dist/commonjs/store.js +0 -2
- package/dist/commonjs/store.js.map +1 -1
- package/dist/commonjs/transactionValidation.d.ts +1 -1
- package/dist/commonjs/transactionValidation.d.ts.map +1 -1
- package/dist/commonjs/transactionValidation.js +2 -2
- package/dist/commonjs/transactionValidation.js.map +1 -1
- package/dist/commonjs/utils/dates.js +31 -31
- package/dist/commonjs/utils/dates.js.map +1 -1
- package/dist/commonjs/utils/fetch.d.ts +7 -7
- package/dist/commonjs/utils/fetch.d.ts.map +1 -1
- package/dist/commonjs/utils/fetch.js +8 -8
- package/dist/commonjs/utils/fetch.js.map +1 -1
- package/dist/commonjs/utils/flags.d.ts +2 -2
- package/dist/commonjs/utils/flags.d.ts.map +1 -1
- package/dist/commonjs/utils/flags.js +4 -4
- package/dist/commonjs/utils/flags.js.map +1 -1
- package/dist/commonjs/utils/linkIndex.d.ts +2 -2
- package/dist/commonjs/utils/linkIndex.d.ts.map +1 -1
- package/dist/commonjs/utils/linkIndex.js.map +1 -1
- package/dist/commonjs/warningToggle.d.ts +1 -1
- package/dist/commonjs/warningToggle.d.ts.map +1 -1
- package/dist/commonjs/warningToggle.js +3 -3
- package/dist/commonjs/warningToggle.js.map +1 -1
- package/dist/esm/Connection.d.ts +1 -0
- package/dist/esm/Connection.d.ts.map +1 -1
- package/dist/esm/Connection.js +18 -3
- package/dist/esm/Connection.js.map +1 -1
- package/dist/esm/IndexedDBStorage.d.ts.map +1 -1
- package/dist/esm/IndexedDBStorage.js +4 -161
- package/dist/esm/IndexedDBStorage.js.map +1 -1
- package/dist/esm/Reactor.d.ts +7 -7
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +38 -39
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/{InstantError.d.ts → SidekickError.d.ts} +2 -2
- package/dist/esm/SidekickError.d.ts.map +1 -0
- package/dist/esm/{InstantError.js → SidekickError.js} +5 -5
- package/dist/esm/SidekickError.js.map +1 -0
- package/dist/esm/Stream.d.ts +5 -5
- package/dist/esm/Stream.d.ts.map +1 -1
- package/dist/esm/Stream.js +12 -12
- package/dist/esm/Stream.js.map +1 -1
- package/dist/esm/SyncTable.d.ts +3 -3
- package/dist/esm/SyncTable.d.ts.map +1 -1
- package/dist/esm/SyncTable.js +3 -3
- package/dist/esm/SyncTable.js.map +1 -1
- package/dist/esm/attrTypes.d.ts +11 -11
- package/dist/esm/attrTypes.d.ts.map +1 -1
- package/dist/esm/attrTypes.js.map +1 -1
- package/dist/esm/coreTypes.d.ts +4 -4
- package/dist/esm/coreTypes.d.ts.map +1 -1
- package/dist/esm/coreTypes.js.map +1 -1
- package/dist/esm/createRouteHandler.d.ts +1 -1
- package/dist/esm/createRouteHandler.d.ts.map +1 -1
- package/dist/esm/createRouteHandler.js +3 -3
- package/dist/esm/createRouteHandler.js.map +1 -1
- package/dist/esm/devtool.js +13 -6
- package/dist/esm/devtool.js.map +1 -1
- package/dist/esm/endpoints.d.ts +2 -2
- package/dist/esm/endpoints.d.ts.map +1 -1
- package/dist/esm/endpoints.js +3 -3
- package/dist/esm/endpoints.js.map +1 -1
- package/dist/esm/framework.d.ts +4 -4
- package/dist/esm/framework.d.ts.map +1 -1
- package/dist/esm/framework.js +6 -6
- package/dist/esm/framework.js.map +1 -1
- package/dist/esm/helperTypes.d.ts +24 -24
- package/dist/esm/helperTypes.d.ts.map +1 -1
- package/dist/esm/helperTypes.js.map +1 -1
- package/dist/esm/index.d.ts +36 -36
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +33 -33
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/infiniteQuery.d.ts +7 -7
- package/dist/esm/infiniteQuery.d.ts.map +1 -1
- package/dist/esm/infiniteQuery.js +16 -3
- package/dist/esm/infiniteQuery.js.map +1 -1
- package/dist/esm/model/{instaqlResult.d.ts → sideqlResult.d.ts} +2 -2
- package/dist/esm/model/sideqlResult.d.ts.map +1 -0
- package/dist/esm/model/{instaqlResult.js → sideqlResult.js} +2 -2
- package/dist/esm/model/sideqlResult.js.map +1 -0
- package/dist/esm/notifyScope.js +3 -3
- package/dist/esm/notifyScope.js.map +1 -1
- package/dist/esm/parseSchemaFromJSON.d.ts +2 -2
- package/dist/esm/parseSchemaFromJSON.d.ts.map +1 -1
- package/dist/esm/parseSchemaFromJSON.js.map +1 -1
- package/dist/esm/queryTypes.d.ts +32 -32
- package/dist/esm/queryTypes.d.ts.map +1 -1
- package/dist/esm/queryTypes.js.map +1 -1
- package/dist/esm/routeHandlerProtocol.d.ts +7 -7
- package/dist/esm/routeHandlerProtocol.d.ts.map +1 -1
- package/dist/esm/routeHandlerProtocol.js.map +1 -1
- package/dist/esm/rulesTypes.d.ts +20 -20
- package/dist/esm/rulesTypes.d.ts.map +1 -1
- package/dist/esm/rulesTypes.js.map +1 -1
- package/dist/esm/sanityCheckQueries.d.ts +3 -3
- package/dist/esm/sanityCheckQueries.d.ts.map +1 -1
- package/dist/esm/sanityCheckQueries.js.map +1 -1
- package/dist/esm/schema.d.ts +3 -3
- package/dist/esm/schema.d.ts.map +1 -1
- package/dist/esm/schema.js +3 -3
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/schemaTypes.d.ts +8 -8
- package/dist/esm/schemaTypes.d.ts.map +1 -1
- package/dist/esm/schemaTypes.js +5 -5
- package/dist/esm/schemaTypes.js.map +1 -1
- package/dist/esm/{instaml.d.ts → sideml.d.ts} +1 -1
- package/dist/esm/sideml.d.ts.map +1 -0
- package/dist/esm/{instaml.js → sideml.js} +6 -3
- package/dist/esm/sideml.js.map +1 -0
- package/dist/esm/{instaql.d.ts → sideql.d.ts} +1 -1
- package/dist/esm/sideql.d.ts.map +1 -0
- package/dist/esm/{instaql.js → sideql.js} +1 -1
- package/dist/esm/sideql.js.map +1 -0
- package/dist/esm/{instatx.d.ts → sidetx.d.ts} +1 -1
- package/dist/esm/sidetx.d.ts.map +1 -0
- package/dist/esm/{instatx.js → sidetx.js} +1 -1
- package/dist/esm/sidetx.js.map +1 -0
- package/dist/esm/store.d.ts +22 -22
- package/dist/esm/store.d.ts.map +1 -1
- package/dist/esm/store.js +0 -2
- package/dist/esm/store.js.map +1 -1
- package/dist/esm/transactionValidation.d.ts +1 -1
- package/dist/esm/transactionValidation.d.ts.map +1 -1
- package/dist/esm/transactionValidation.js +1 -1
- package/dist/esm/transactionValidation.js.map +1 -1
- package/dist/esm/utils/dates.js +31 -31
- package/dist/esm/utils/dates.js.map +1 -1
- package/dist/esm/utils/fetch.d.ts +7 -7
- package/dist/esm/utils/fetch.d.ts.map +1 -1
- package/dist/esm/utils/fetch.js +6 -6
- package/dist/esm/utils/fetch.js.map +1 -1
- package/dist/esm/utils/flags.d.ts +2 -2
- package/dist/esm/utils/flags.d.ts.map +1 -1
- package/dist/esm/utils/flags.js +3 -3
- package/dist/esm/utils/flags.js.map +1 -1
- package/dist/esm/utils/linkIndex.d.ts +2 -2
- package/dist/esm/utils/linkIndex.d.ts.map +1 -1
- package/dist/esm/utils/linkIndex.js.map +1 -1
- package/dist/esm/warningToggle.d.ts +1 -1
- package/dist/esm/warningToggle.d.ts.map +1 -1
- package/dist/esm/warningToggle.js +1 -1
- package/dist/esm/warningToggle.js.map +1 -1
- package/dist/standalone/index.js +2705 -2791
- package/dist/standalone/index.umd.cjs +9 -6
- package/package.json +3 -3
- package/src/Connection.ts +18 -3
- package/src/IndexedDBStorage.ts +3 -181
- package/src/Reactor.js +40 -39
- package/src/{InstantError.ts → SidekickError.ts} +4 -4
- package/src/Stream.ts +35 -32
- package/src/SyncTable.ts +6 -6
- package/src/attrTypes.ts +15 -11
- package/src/coreTypes.ts +5 -5
- package/src/createRouteHandler.ts +9 -7
- package/src/devtool.ts +13 -6
- package/src/endpoints.ts +4 -4
- package/src/framework.ts +13 -13
- package/src/helperTypes.ts +37 -37
- package/src/index.ts +123 -123
- package/src/infiniteQuery.ts +39 -22
- package/src/model/{instaqlResult.js → sideqlResult.js} +1 -1
- package/src/notifyScope.ts +3 -3
- package/src/parseSchemaFromJSON.ts +2 -2
- package/src/queryTypes.ts +55 -55
- package/src/routeHandlerProtocol.ts +8 -8
- package/src/rulesTypes.ts +23 -23
- package/src/sanityCheckQueries.ts +9 -9
- package/src/schema.ts +3 -3
- package/src/schemaTypes.ts +11 -9
- package/src/{instaml.ts → sideml.ts} +17 -14
- package/src/{instaql.ts → sideql.ts} +5 -5
- package/src/store.ts +35 -36
- package/src/transactionValidation.ts +1 -1
- package/src/utils/dates.ts +31 -31
- package/src/utils/fetch.ts +13 -13
- package/src/utils/flags.ts +3 -3
- package/src/utils/linkIndex.ts +2 -2
- package/src/warningToggle.ts +1 -1
- package/vite.config.ts +1 -1
- package/dist/commonjs/InstantError.d.ts.map +0 -1
- package/dist/commonjs/InstantError.js.map +0 -1
- package/dist/commonjs/instaml.d.ts.map +0 -1
- package/dist/commonjs/instaml.js.map +0 -1
- package/dist/commonjs/instaql.d.ts.map +0 -1
- package/dist/commonjs/instaql.js.map +0 -1
- package/dist/commonjs/instatx.d.ts.map +0 -1
- package/dist/commonjs/instatx.js.map +0 -1
- package/dist/commonjs/model/instaqlResult.d.ts.map +0 -1
- package/dist/commonjs/model/instaqlResult.js.map +0 -1
- package/dist/esm/InstantError.d.ts.map +0 -1
- package/dist/esm/InstantError.js.map +0 -1
- package/dist/esm/instaml.d.ts.map +0 -1
- package/dist/esm/instaml.js.map +0 -1
- package/dist/esm/instaql.d.ts.map +0 -1
- package/dist/esm/instaql.js.map +0 -1
- package/dist/esm/instatx.d.ts.map +0 -1
- package/dist/esm/instatx.js.map +0 -1
- package/dist/esm/model/instaqlResult.d.ts.map +0 -1
- package/dist/esm/model/instaqlResult.js.map +0 -1
- /package/src/{instatx.ts → sidetx.ts} +0 -0
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
import type {
|
|
5
5
|
Cursor,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
SidekickObject,
|
|
7
|
+
SideQLParams,
|
|
8
|
+
SideQLResponse,
|
|
9
9
|
ValidQuery,
|
|
10
10
|
} from './queryTypes.ts';
|
|
11
|
-
import {
|
|
11
|
+
import { SidekickUnknownSchema } from './schemaTypes.ts';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* The purpose of these sanity checks:
|
|
@@ -20,9 +20,9 @@ import { InstantUnknownSchema } from './schemaTypes.ts';
|
|
|
20
20
|
* * the api is more vebose than this
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
export function dummyQuery<Q extends ValidQuery<Q,
|
|
23
|
+
export function dummyQuery<Q extends ValidQuery<Q, SidekickUnknownSchema>>(
|
|
24
24
|
_query: Q,
|
|
25
|
-
):
|
|
25
|
+
): SideQLResponse<SidekickUnknownSchema, Q> {
|
|
26
26
|
return 1 as any;
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -172,12 +172,12 @@ const sanityCheckQueries = () => {
|
|
|
172
172
|
};
|
|
173
173
|
const sanityCheckSchemalessResponses = () => {
|
|
174
174
|
// Simple Response
|
|
175
|
-
const r1: { users:
|
|
175
|
+
const r1: { users: SidekickObject[] } = dummyQuery({ users: {} });
|
|
176
176
|
// Nested Response
|
|
177
|
-
const r2: { users: ({ posts:
|
|
177
|
+
const r2: { users: ({ posts: SidekickObject[] } & SidekickObject)[] } =
|
|
178
178
|
dummyQuery({ users: { posts: {} } });
|
|
179
179
|
// $ are ignored
|
|
180
|
-
const r3: { users: ({ posts:
|
|
180
|
+
const r3: { users: ({ posts: SidekickObject[] } & SidekickObject)[] } =
|
|
181
181
|
dummyQuery({
|
|
182
182
|
users: {
|
|
183
183
|
$: { where: { foo: 1 } },
|
package/src/schema.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EntityDef,
|
|
3
3
|
DataAttrDef,
|
|
4
|
-
|
|
4
|
+
SidekickSchemaDef,
|
|
5
5
|
type EntitiesDef,
|
|
6
6
|
type AttrsDefs,
|
|
7
7
|
type EntitiesWithLinks,
|
|
@@ -31,7 +31,7 @@ function graph<
|
|
|
31
31
|
EntitiesWithoutLinks extends EntitiesDef,
|
|
32
32
|
const Links extends LinksDef<EntitiesWithoutLinks>,
|
|
33
33
|
>(entities: EntitiesWithoutLinks, links: Links) {
|
|
34
|
-
return new
|
|
34
|
+
return new SidekickSchemaDef(
|
|
35
35
|
enrichEntitiesWithLinks<EntitiesWithoutLinks, Links>(entities, links),
|
|
36
36
|
// (XXX): LinksDef<any> stems from TypeScript’s inability to reconcile the
|
|
37
37
|
// type EntitiesWithLinks<EntitiesWithoutLinks, Links> with
|
|
@@ -167,7 +167,7 @@ function schema<
|
|
|
167
167
|
}) {
|
|
168
168
|
const linksDef = (links ?? {}) as Links;
|
|
169
169
|
const roomsDef = (rooms ?? {}) as Rooms;
|
|
170
|
-
return new
|
|
170
|
+
return new SidekickSchemaDef(
|
|
171
171
|
enrichEntitiesWithLinks<EntitiesWithoutLinks, Links>(entities, linksDef),
|
|
172
172
|
// (XXX): LinksDef<any> stems from TypeScript's inability to reconcile the
|
|
173
173
|
// type EntitiesWithLinks<EntitiesWithoutLinks, Links> with
|
package/src/schemaTypes.ts
CHANGED
|
@@ -368,7 +368,9 @@ export type RoomsFromDef<RDef extends RoomsDef> = {
|
|
|
368
368
|
};
|
|
369
369
|
|
|
370
370
|
export type RoomsOf<S> =
|
|
371
|
-
S extends
|
|
371
|
+
S extends SidekickSchemaDef<any, any, infer RDef>
|
|
372
|
+
? RoomsFromDef<RDef>
|
|
373
|
+
: never;
|
|
372
374
|
|
|
373
375
|
export type PresenceOf<
|
|
374
376
|
S,
|
|
@@ -397,7 +399,7 @@ export interface RoomsDef {
|
|
|
397
399
|
[RoomType: string]: RoomDef;
|
|
398
400
|
}
|
|
399
401
|
|
|
400
|
-
export class
|
|
402
|
+
export class SidekickSchemaDef<
|
|
401
403
|
Entities extends EntitiesDef,
|
|
402
404
|
Links extends LinksDef<Entities>,
|
|
403
405
|
Rooms extends RoomsDef,
|
|
@@ -430,7 +432,7 @@ export class InstantSchemaDef<
|
|
|
430
432
|
*/
|
|
431
433
|
withRoomSchema<_RoomSchema extends RoomSchemaShape>() {
|
|
432
434
|
type RDef = RoomDefFromShape<_RoomSchema>;
|
|
433
|
-
return new
|
|
435
|
+
return new SidekickSchemaDef<Entities, Links, RDef>(
|
|
434
436
|
this.entities,
|
|
435
437
|
this.links,
|
|
436
438
|
{} as RDef,
|
|
@@ -444,7 +446,7 @@ export class InstantSchemaDef<
|
|
|
444
446
|
*
|
|
445
447
|
* @see https://sidekickdb.co/docs/modeling-data
|
|
446
448
|
*/
|
|
447
|
-
export class
|
|
449
|
+
export class SidekickGraph<
|
|
448
450
|
Entities extends EntitiesDef,
|
|
449
451
|
Links extends LinksDef<Entities>,
|
|
450
452
|
RoomSchema extends RoomSchemaShape = {},
|
|
@@ -456,7 +458,7 @@ export class InstantGraph<
|
|
|
456
458
|
) {}
|
|
457
459
|
|
|
458
460
|
withRoomSchema<_RoomSchema extends RoomSchemaShape>() {
|
|
459
|
-
return new
|
|
461
|
+
return new SidekickGraph<Entities, Links, _RoomSchema>(
|
|
460
462
|
this.entities,
|
|
461
463
|
this.links,
|
|
462
464
|
);
|
|
@@ -521,14 +523,14 @@ type EntityDefFromShape<Shape, K extends keyof Shape> = EntityDef<
|
|
|
521
523
|
export type BackwardsCompatibleSchema<
|
|
522
524
|
Shape extends { [k: string]: any },
|
|
523
525
|
RoomSchema extends RoomSchemaShape = {},
|
|
524
|
-
> =
|
|
526
|
+
> = SidekickSchemaDef<
|
|
525
527
|
{ [K in keyof Shape]: EntityDefFromShape<Shape, K> },
|
|
526
528
|
UnknownLinks<EntitiesDef>,
|
|
527
529
|
RoomDefFromShape<RoomSchema>
|
|
528
530
|
>;
|
|
529
531
|
|
|
530
532
|
// ----------
|
|
531
|
-
//
|
|
533
|
+
// SidekickUnknownSchema
|
|
532
534
|
|
|
533
535
|
export type UnknownEntity = EntityDef<
|
|
534
536
|
{
|
|
@@ -564,13 +566,13 @@ export interface UnknownRooms {
|
|
|
564
566
|
};
|
|
565
567
|
}
|
|
566
568
|
|
|
567
|
-
export class
|
|
569
|
+
export class SidekickUnknownSchemaDef extends SidekickSchemaDef<
|
|
568
570
|
UnknownEntities,
|
|
569
571
|
UnknownLinks<UnknownEntities>,
|
|
570
572
|
UnknownRooms
|
|
571
573
|
> {}
|
|
572
574
|
|
|
573
|
-
export type
|
|
575
|
+
export type SidekickUnknownSchema = SidekickUnknownSchemaDef;
|
|
574
576
|
|
|
575
577
|
export type CreateParams<
|
|
576
578
|
Schema extends IContainEntitiesAndLinks<any, any>,
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
getAttrByReverseIdentName,
|
|
7
7
|
Store,
|
|
8
8
|
} from './store.ts';
|
|
9
|
-
import { getOps, isLookup, parseLookup } from './
|
|
9
|
+
import { getOps, isLookup, parseLookup } from './sidetx.ts';
|
|
10
10
|
import { immutableRemoveUndefined } from './utils/object.js';
|
|
11
11
|
import { coerceToDate } from './utils/dates.ts';
|
|
12
12
|
import uuid from './utils/id.ts';
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
IContainEntitiesAndLinks,
|
|
16
16
|
LinkDef,
|
|
17
17
|
} from './schemaTypes.ts';
|
|
18
|
-
import {
|
|
18
|
+
import { SidekickDBAttr, SidekickDBIdent } from './attrTypes.ts';
|
|
19
19
|
|
|
20
20
|
export type AttrMapping = {
|
|
21
21
|
attrIdMap: Record<string, string>;
|
|
@@ -466,14 +466,14 @@ function createRefAttr(
|
|
|
466
466
|
schema: Schema | undefined,
|
|
467
467
|
etype: string,
|
|
468
468
|
label: string,
|
|
469
|
-
props?: Partial<
|
|
470
|
-
):
|
|
469
|
+
props?: Partial<SidekickDBAttr> | undefined,
|
|
470
|
+
): SidekickDBAttr {
|
|
471
471
|
const schemaRefProps = schema
|
|
472
472
|
? refPropsFromSchema(schema, etype, label)
|
|
473
473
|
: null;
|
|
474
474
|
const attrId = uuid();
|
|
475
|
-
const fwdIdent:
|
|
476
|
-
const revIdent:
|
|
475
|
+
const fwdIdent: SidekickDBIdent = [uuid(), etype, label];
|
|
476
|
+
const revIdent: SidekickDBIdent = [uuid(), label, etype];
|
|
477
477
|
return {
|
|
478
478
|
id: attrId,
|
|
479
479
|
// @ts-ignore: ts thinks it's any[]
|
|
@@ -505,8 +505,11 @@ const SUPPORTS_LOOKUP_ACTIONS = new Set([
|
|
|
505
505
|
'ruleParams',
|
|
506
506
|
]);
|
|
507
507
|
|
|
508
|
-
const lookupProps: Partial<
|
|
509
|
-
|
|
508
|
+
const lookupProps: Partial<SidekickDBAttr> = {
|
|
509
|
+
'unique?': true,
|
|
510
|
+
'index?': true,
|
|
511
|
+
};
|
|
512
|
+
const refLookupProps: Partial<SidekickDBAttr> = {
|
|
510
513
|
...lookupProps,
|
|
511
514
|
cardinality: 'one',
|
|
512
515
|
};
|
|
@@ -545,10 +548,10 @@ function createMissingAttrs(
|
|
|
545
548
|
ops,
|
|
546
549
|
): [AttrsStore, TXStep[]] {
|
|
547
550
|
const addedIds = new Set();
|
|
548
|
-
const localAttrs:
|
|
551
|
+
const localAttrs: SidekickDBAttr[] = [];
|
|
549
552
|
const addOps: TXStep[] = [];
|
|
550
553
|
|
|
551
|
-
function attrByFwdIdent(etype, label):
|
|
554
|
+
function attrByFwdIdent(etype, label): SidekickDBAttr | undefined {
|
|
552
555
|
return (
|
|
553
556
|
getAttrByFwdIdentName(attrsStore, etype, label) ||
|
|
554
557
|
localAttrs.find(
|
|
@@ -559,7 +562,7 @@ function createMissingAttrs(
|
|
|
559
562
|
);
|
|
560
563
|
}
|
|
561
564
|
|
|
562
|
-
function attrByRevIdent(etype, label):
|
|
565
|
+
function attrByRevIdent(etype, label): SidekickDBAttr | undefined {
|
|
563
566
|
return (
|
|
564
567
|
getAttrByReverseIdentName(attrsStore, etype, label) ||
|
|
565
568
|
localAttrs.find(
|
|
@@ -570,15 +573,15 @@ function createMissingAttrs(
|
|
|
570
573
|
);
|
|
571
574
|
}
|
|
572
575
|
|
|
573
|
-
function addAttr(attr:
|
|
576
|
+
function addAttr(attr: SidekickDBAttr) {
|
|
574
577
|
localAttrs.push(attr);
|
|
575
578
|
addOps.push(['add-attr', attr]);
|
|
576
579
|
addedIds.add(attr.id);
|
|
577
580
|
}
|
|
578
581
|
function addUnsynced(
|
|
579
582
|
attr:
|
|
580
|
-
| (
|
|
581
|
-
|
|
|
583
|
+
| (SidekickDBAttr & { isUnsynced?: boolean })
|
|
584
|
+
| SidekickDBAttr
|
|
582
585
|
| undefined,
|
|
583
586
|
) {
|
|
584
587
|
if (
|
|
@@ -2,7 +2,7 @@ import { query as datalogQuery } from './datalog.js';
|
|
|
2
2
|
import { uuidCompare } from './utils/id.ts';
|
|
3
3
|
import { stringCompare } from './utils/strings.ts';
|
|
4
4
|
import * as s from './store.ts';
|
|
5
|
-
import {
|
|
5
|
+
import { SidekickDBAttr } from './attrTypes.ts';
|
|
6
6
|
import { Cursor } from './queryTypes.ts';
|
|
7
7
|
import { warningEnabled } from './warningToggle.ts';
|
|
8
8
|
|
|
@@ -48,7 +48,7 @@ class AttrNotFoundError extends Error {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
function idAttr(attrsStore: s.AttrsStore, ns: string):
|
|
51
|
+
function idAttr(attrsStore: s.AttrsStore, ns: string): SidekickDBAttr {
|
|
52
52
|
const attr = s.getPrimaryKeyAttr(attrsStore, ns);
|
|
53
53
|
|
|
54
54
|
if (!attr) {
|
|
@@ -90,7 +90,7 @@ function refAttrPat(
|
|
|
90
90
|
etype: string,
|
|
91
91
|
level: number,
|
|
92
92
|
label: string,
|
|
93
|
-
): [string, number, Pat,
|
|
93
|
+
): [string, number, Pat, SidekickDBAttr, boolean] {
|
|
94
94
|
const fwdAttr = s.getAttrByFwdIdentName(attrsStore, etype, label);
|
|
95
95
|
const revAttr = s.getAttrByReverseIdentName(attrsStore, etype, label);
|
|
96
96
|
const attr = fwdAttr || revAttr;
|
|
@@ -149,7 +149,7 @@ function makeLikeMatcher(caseSensitive: boolean, pattern: string) {
|
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
function parseValue(attr:
|
|
152
|
+
function parseValue(attr: SidekickDBAttr, v: any) {
|
|
153
153
|
if (
|
|
154
154
|
typeof v !== 'object' ||
|
|
155
155
|
v.hasOwnProperty('$in') ||
|
|
@@ -675,7 +675,7 @@ function objectAttrs(
|
|
|
675
675
|
attrsStore: s.AttrsStore,
|
|
676
676
|
etype,
|
|
677
677
|
dq,
|
|
678
|
-
): Map<string,
|
|
678
|
+
): Map<string, SidekickDBAttr> | undefined {
|
|
679
679
|
if (!Array.isArray(dq.fields)) {
|
|
680
680
|
return s.getBlobAttrs(attrsStore, etype);
|
|
681
681
|
}
|
package/src/store.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { create } from 'mutative';
|
|
2
2
|
import { immutableDeepMerge } from './utils/object.js';
|
|
3
3
|
import { coerceToDate } from './utils/dates.ts';
|
|
4
|
-
import {
|
|
4
|
+
import { SidekickDBAttr } from './attrTypes.ts';
|
|
5
5
|
import { LinkIndex } from './utils/linkIndex.ts';
|
|
6
6
|
|
|
7
7
|
type Triple = [string, string, any, number];
|
|
8
|
-
type Attrs = Record<string,
|
|
8
|
+
type Attrs = Record<string, SidekickDBAttr>;
|
|
9
9
|
|
|
10
10
|
interface AttrIndexes {
|
|
11
|
-
blobAttrs: Map<string, Map<string,
|
|
12
|
-
primaryKeys: Map<string,
|
|
13
|
-
forwardIdents: Map<string, Map<string,
|
|
14
|
-
revIdents: Map<string, Map<string,
|
|
11
|
+
blobAttrs: Map<string, Map<string, SidekickDBAttr>>;
|
|
12
|
+
primaryKeys: Map<string, SidekickDBAttr>;
|
|
13
|
+
forwardIdents: Map<string, Map<string, SidekickDBAttr>>;
|
|
14
|
+
revIdents: Map<string, Map<string, SidekickDBAttr>>;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export type Store = {
|
|
@@ -49,24 +49,25 @@ export interface AttrsStore {
|
|
|
49
49
|
attrs: Attrs;
|
|
50
50
|
linkIndex: LinkIndex | null;
|
|
51
51
|
resetAttrIndexes(): void;
|
|
52
|
-
addAttr(attr:
|
|
52
|
+
addAttr(attr: SidekickDBAttr): void;
|
|
53
53
|
deleteAttr(attrId: string): void;
|
|
54
|
-
updateAttr(partialAttr: Partial<
|
|
55
|
-
getAttr(id: string):
|
|
56
|
-
blobAttrs: Map<string, Map<string,
|
|
57
|
-
primaryKeys: Map<string,
|
|
58
|
-
forwardIdents: Map<string, Map<string,
|
|
59
|
-
revIdents: Map<string, Map<string,
|
|
54
|
+
updateAttr(partialAttr: Partial<SidekickDBAttr> & { id: string }): void;
|
|
55
|
+
getAttr(id: string): SidekickDBAttr | undefined;
|
|
56
|
+
blobAttrs: Map<string, Map<string, SidekickDBAttr>>;
|
|
57
|
+
primaryKeys: Map<string, SidekickDBAttr>;
|
|
58
|
+
forwardIdents: Map<string, Map<string, SidekickDBAttr>>;
|
|
59
|
+
revIdents: Map<string, Map<string, SidekickDBAttr>>;
|
|
60
60
|
toJSON(): AttrsStoreJson;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export class AttrsStoreClass implements AttrsStore {
|
|
64
64
|
public attrs: Attrs;
|
|
65
65
|
public linkIndex: LinkIndex | null;
|
|
66
|
-
private _blobAttrs: Map<string, Map<string,
|
|
67
|
-
private _primaryKeys: Map<string,
|
|
68
|
-
private _forwardIdents: Map<string, Map<string,
|
|
69
|
-
|
|
66
|
+
private _blobAttrs: Map<string, Map<string, SidekickDBAttr>> | null = null;
|
|
67
|
+
private _primaryKeys: Map<string, SidekickDBAttr> | null = null;
|
|
68
|
+
private _forwardIdents: Map<string, Map<string, SidekickDBAttr>> | null =
|
|
69
|
+
null;
|
|
70
|
+
private _revIdents: Map<string, Map<string, SidekickDBAttr>> | null = null;
|
|
70
71
|
constructor(attrs: Attrs, linkIndex: LinkIndex | null) {
|
|
71
72
|
this.attrs = attrs;
|
|
72
73
|
this.linkIndex = linkIndex;
|
|
@@ -79,7 +80,7 @@ export class AttrsStoreClass implements AttrsStore {
|
|
|
79
80
|
this._revIdents = null;
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
public addAttr(attr:
|
|
83
|
+
public addAttr(attr: SidekickDBAttr) {
|
|
83
84
|
this.attrs[attr.id] = attr;
|
|
84
85
|
this.resetAttrIndexes();
|
|
85
86
|
}
|
|
@@ -89,18 +90,18 @@ export class AttrsStoreClass implements AttrsStore {
|
|
|
89
90
|
this.resetAttrIndexes();
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
public updateAttr(partialAttr: Partial<
|
|
93
|
+
public updateAttr(partialAttr: Partial<SidekickDBAttr> & { id: string }) {
|
|
93
94
|
const attr = this.attrs[partialAttr.id];
|
|
94
95
|
if (!attr) return;
|
|
95
96
|
this.attrs[partialAttr.id] = { ...attr, ...partialAttr };
|
|
96
97
|
this.resetAttrIndexes();
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
public getAttr(id: string):
|
|
100
|
+
public getAttr(id: string): SidekickDBAttr | undefined {
|
|
100
101
|
return this.attrs[id];
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
get blobAttrs(): Map<string, Map<string,
|
|
104
|
+
get blobAttrs(): Map<string, Map<string, SidekickDBAttr>> {
|
|
104
105
|
if (this._blobAttrs) {
|
|
105
106
|
return this._blobAttrs;
|
|
106
107
|
}
|
|
@@ -114,7 +115,7 @@ export class AttrsStoreClass implements AttrsStore {
|
|
|
114
115
|
return this._blobAttrs;
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
get primaryKeys(): Map<string,
|
|
118
|
+
get primaryKeys(): Map<string, SidekickDBAttr> {
|
|
118
119
|
if (this._primaryKeys) {
|
|
119
120
|
return this._primaryKeys;
|
|
120
121
|
}
|
|
@@ -129,7 +130,7 @@ export class AttrsStoreClass implements AttrsStore {
|
|
|
129
130
|
return this._primaryKeys;
|
|
130
131
|
}
|
|
131
132
|
|
|
132
|
-
get forwardIdents(): Map<string, Map<string,
|
|
133
|
+
get forwardIdents(): Map<string, Map<string, SidekickDBAttr>> {
|
|
133
134
|
if (this._forwardIdents) {
|
|
134
135
|
return this._forwardIdents;
|
|
135
136
|
}
|
|
@@ -143,7 +144,7 @@ export class AttrsStoreClass implements AttrsStore {
|
|
|
143
144
|
return this._forwardIdents;
|
|
144
145
|
}
|
|
145
146
|
|
|
146
|
-
get revIdents(): Map<string, Map<string,
|
|
147
|
+
get revIdents(): Map<string, Map<string, SidekickDBAttr>> {
|
|
147
148
|
if (this._revIdents) {
|
|
148
149
|
return this._revIdents;
|
|
149
150
|
}
|
|
@@ -164,19 +165,19 @@ export class AttrsStoreClass implements AttrsStore {
|
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
167
|
|
|
167
|
-
function hasEA(attr:
|
|
168
|
+
function hasEA(attr: SidekickDBAttr) {
|
|
168
169
|
return attr['cardinality'] === 'one';
|
|
169
170
|
}
|
|
170
171
|
|
|
171
|
-
function isRef(attr:
|
|
172
|
+
function isRef(attr: SidekickDBAttr) {
|
|
172
173
|
return attr['value-type'] === 'ref';
|
|
173
174
|
}
|
|
174
175
|
|
|
175
|
-
export function isBlob(attr:
|
|
176
|
+
export function isBlob(attr: SidekickDBAttr) {
|
|
176
177
|
return attr['value-type'] === 'blob';
|
|
177
178
|
}
|
|
178
179
|
|
|
179
|
-
function getAttr(attrs: Attrs, attrId: string):
|
|
180
|
+
function getAttr(attrs: Attrs, attrId: string): SidekickDBAttr | undefined {
|
|
180
181
|
return attrs[attrId];
|
|
181
182
|
}
|
|
182
183
|
|
|
@@ -213,7 +214,7 @@ function setInMap(m: Map<any, any>, path: any[], value: any) {
|
|
|
213
214
|
}
|
|
214
215
|
}
|
|
215
216
|
|
|
216
|
-
function isDateAttr(attr:
|
|
217
|
+
function isDateAttr(attr: SidekickDBAttr) {
|
|
217
218
|
return attr['checked-data-type'] === 'date';
|
|
218
219
|
}
|
|
219
220
|
|
|
@@ -248,7 +249,7 @@ function createTripleIndexes(
|
|
|
248
249
|
return { eav, aev, vae };
|
|
249
250
|
}
|
|
250
251
|
|
|
251
|
-
function createAttrIndexes(attrs: Record<string,
|
|
252
|
+
function createAttrIndexes(attrs: Record<string, SidekickDBAttr>): AttrIndexes {
|
|
252
253
|
const blobAttrs = new Map();
|
|
253
254
|
const primaryKeys = new Map();
|
|
254
255
|
const forwardIdents = new Map();
|
|
@@ -410,7 +411,7 @@ export function retractTriple(
|
|
|
410
411
|
let _seed = 0;
|
|
411
412
|
function getCreatedAt(
|
|
412
413
|
store: Store,
|
|
413
|
-
attr:
|
|
414
|
+
attr: SidekickDBAttr,
|
|
414
415
|
triple: Triple,
|
|
415
416
|
): Number {
|
|
416
417
|
const [eid, aid, v] = triple;
|
|
@@ -459,7 +460,6 @@ export function addTriple(
|
|
|
459
460
|
if (!attr) {
|
|
460
461
|
// (XXX): Due to the way we're handling attrs, it's
|
|
461
462
|
// possible to enter a state where we receive a triple without an attr.
|
|
462
|
-
// See: https://github.com/jsventures/instant-local/pull/132 for details.
|
|
463
463
|
// For now, if we receive a command without an attr, we no-op.
|
|
464
464
|
return;
|
|
465
465
|
}
|
|
@@ -609,7 +609,7 @@ function resetIndexMap(store: Store, attrsStore, newTriples: Triple[]) {
|
|
|
609
609
|
});
|
|
610
610
|
}
|
|
611
611
|
|
|
612
|
-
function addAttr(attrsStore: AttrsStore, [attr]: [
|
|
612
|
+
function addAttr(attrsStore: AttrsStore, [attr]: [SidekickDBAttr]) {
|
|
613
613
|
attrsStore.addAttr(attr);
|
|
614
614
|
}
|
|
615
615
|
|
|
@@ -627,7 +627,7 @@ function deleteAttr(store: Store, attrsStore: AttrsStore, [id]: [string]) {
|
|
|
627
627
|
function updateAttr(
|
|
628
628
|
store: Store,
|
|
629
629
|
attrsStore: AttrsStore,
|
|
630
|
-
[partialAttr]: [Partial<
|
|
630
|
+
[partialAttr]: [Partial<SidekickDBAttr> & { id: string }],
|
|
631
631
|
) {
|
|
632
632
|
const attr = attrsStore.getAttr(partialAttr.id);
|
|
633
633
|
if (!attr) return;
|
|
@@ -817,7 +817,7 @@ export function getTriples(store, [e, a, v]) {
|
|
|
817
817
|
|
|
818
818
|
export function getAsObject(
|
|
819
819
|
store: Store,
|
|
820
|
-
attrs: Map<string,
|
|
820
|
+
attrs: Map<string, SidekickDBAttr> | undefined,
|
|
821
821
|
e: string,
|
|
822
822
|
) {
|
|
823
823
|
const obj = {};
|
|
@@ -880,7 +880,6 @@ function findTriple(
|
|
|
880
880
|
if (!attr) {
|
|
881
881
|
// (XXX): Due to the way we're handling attrs, it's
|
|
882
882
|
// possible to enter a state where we receive a triple without an attr.
|
|
883
|
-
// See: https://github.com/jsventures/instant-local/pull/132 for details.
|
|
884
883
|
// For now, if we receive a command without an attr, we no-op.
|
|
885
884
|
return;
|
|
886
885
|
}
|
package/src/utils/dates.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { pgTimezoneMatch, pgTimezoneAbbrevs } from './pgtime.ts';
|
|
2
2
|
|
|
3
3
|
// Date parsing functions
|
|
4
|
-
function
|
|
4
|
+
function zonedDateTimeStrToDate(s) {
|
|
5
5
|
return new Date(s);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
function
|
|
8
|
+
function localDateTimeStrToDate(s) {
|
|
9
9
|
// Parse as UTC since there's no timezone info
|
|
10
10
|
return new Date(s + 'Z');
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const localDateStrRe = /^(\d+)[\./-](\d+)[\./-](\d+)$/;
|
|
14
14
|
|
|
15
|
-
function
|
|
15
|
+
function localDateStrToDate(s) {
|
|
16
16
|
const match = s.match(localDateStrRe);
|
|
17
17
|
if (!match) {
|
|
18
18
|
return null;
|
|
@@ -31,14 +31,14 @@ function localDateStrToInstant(s) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// Custom date formatters
|
|
34
|
-
function
|
|
34
|
+
function offioDateStrToDate(s) {
|
|
35
35
|
// Format: "yyyy-MM-dd HH:mm:ss"
|
|
36
36
|
// Treat as UTC
|
|
37
37
|
const [datePart, timePart] = s.split(' ');
|
|
38
38
|
return new Date(datePart + 'T' + timePart + 'Z');
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
function
|
|
41
|
+
function zenecaDateStrToDate(s) {
|
|
42
42
|
// Format: "yyyy-MM-dd HH:mm:ss.n"
|
|
43
43
|
// Treat as UTC
|
|
44
44
|
const [datePart, timeWithNanos] = s.split(' ');
|
|
@@ -46,12 +46,12 @@ function zenecaDateStrToInstant(s) {
|
|
|
46
46
|
return new Date(datePart + 'T' + timeWithNanos + 'Z');
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
function
|
|
49
|
+
function rfc1123ToDate(s) {
|
|
50
50
|
// RFC 1123 format is natively supported by Date constructor
|
|
51
51
|
return new Date(s);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
function
|
|
54
|
+
function dowMonDayYearStrToDate(s) {
|
|
55
55
|
// Format: "EEE MMM dd yyyy" (e.g., "Wed Jan 15 2025")
|
|
56
56
|
|
|
57
57
|
//Only parse if the string is in the correct format
|
|
@@ -76,7 +76,7 @@ function dowMonDayYearStrToInstant(s) {
|
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
function
|
|
79
|
+
function iso8601IncompleteOffsetToDate(s) {
|
|
80
80
|
// Format: "2025-01-02T00:00:00-08" (missing minutes in timezone offset)
|
|
81
81
|
// Convert to proper ISO 8601 format by adding ":00" to the timezone offset
|
|
82
82
|
const regex = /^(.+T.+)([+-])(\d{2})$/;
|
|
@@ -91,7 +91,7 @@ function iso8601IncompleteOffsetToInstant(s) {
|
|
|
91
91
|
return null;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
function
|
|
94
|
+
function iso8601SingleDigitToDate(s) {
|
|
95
95
|
// Format: "2025-11-2T00:00:00.000Z" or "2025-1-2T00:00:00Z" (single-digit month/day)
|
|
96
96
|
// Also handles space separator: "2025-1-2 00:00:00"
|
|
97
97
|
// Also handles single-digit hours/minutes/seconds: "2026-04-28T04:7:00.000Z"
|
|
@@ -119,7 +119,7 @@ function iso8601SingleDigitToInstant(s) {
|
|
|
119
119
|
return null;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
function
|
|
122
|
+
function usDateTimeStrToDate(s) {
|
|
123
123
|
// Format: "M/d/yyyy, h:mm:ss a" (e.g., "8/4/2025, 11:02:31 PM")
|
|
124
124
|
const [datePart, timePart] = s.split(', ');
|
|
125
125
|
const [month, day, year] = datePart.split('/').map(Number);
|
|
@@ -147,7 +147,7 @@ function usDateTimeStrToInstant(s) {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
// https://www.postgresql.org/docs/17/datatype-datetime.html#DATATYPE-DATETIME-SPECIAL-VALUES
|
|
150
|
-
function
|
|
150
|
+
function specialStrToDate(s: string) {
|
|
151
151
|
switch (s) {
|
|
152
152
|
case 'epoch':
|
|
153
153
|
return new Date(0);
|
|
@@ -162,7 +162,7 @@ function specialStrToInstant(s: string) {
|
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
function
|
|
165
|
+
function pgTimezoneStrToDate(s: string) {
|
|
166
166
|
const match = s.match(pgTimezoneMatch);
|
|
167
167
|
if (!match) {
|
|
168
168
|
return null;
|
|
@@ -178,18 +178,18 @@ function pgTimezoneStrToInstant(s: string) {
|
|
|
178
178
|
|
|
179
179
|
// Array of parsers
|
|
180
180
|
const dateParsers = [
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
181
|
+
localDateStrToDate,
|
|
182
|
+
zenecaDateStrToDate,
|
|
183
|
+
dowMonDayYearStrToDate,
|
|
184
|
+
usDateTimeStrToDate,
|
|
185
|
+
localDateTimeStrToDate,
|
|
186
|
+
iso8601IncompleteOffsetToDate,
|
|
187
|
+
offioDateStrToDate,
|
|
188
|
+
zonedDateTimeStrToDate,
|
|
189
|
+
specialStrToDate,
|
|
190
|
+
pgTimezoneStrToDate,
|
|
191
|
+
iso8601SingleDigitToDate,
|
|
192
|
+
rfc1123ToDate,
|
|
193
193
|
];
|
|
194
194
|
|
|
195
195
|
// Try to parse with a specific parser
|
|
@@ -207,22 +207,22 @@ function tryParseDateString(parser, s: string) {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
// Try all parsers until one succeeds
|
|
210
|
-
function
|
|
210
|
+
function dateStrToDate(s) {
|
|
211
211
|
for (const parser of dateParsers) {
|
|
212
|
-
const
|
|
213
|
-
if (
|
|
214
|
-
return
|
|
212
|
+
const date = tryParseDateString(parser, s);
|
|
213
|
+
if (date) {
|
|
214
|
+
return date;
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
return null;
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
// Parse JSON string and then try date parsing
|
|
221
|
-
function
|
|
221
|
+
function jsonStrToDate(maybeJson: string) {
|
|
222
222
|
try {
|
|
223
223
|
const s = JSON.parse(maybeJson);
|
|
224
224
|
if (typeof s === 'string') {
|
|
225
|
-
return
|
|
225
|
+
return dateStrToDate(s);
|
|
226
226
|
}
|
|
227
227
|
return null;
|
|
228
228
|
} catch (e) {
|
|
@@ -244,7 +244,7 @@ export function coerceToDate(x: unknown): Date | null | undefined {
|
|
|
244
244
|
}
|
|
245
245
|
if (typeof x === 'string') {
|
|
246
246
|
const result =
|
|
247
|
-
|
|
247
|
+
dateStrToDate(x) || jsonStrToDate(x) || dateStrToDate(x.trim());
|
|
248
248
|
if (!result) {
|
|
249
249
|
throw new Error(`Unable to parse \`${x}\` as a date.`);
|
|
250
250
|
}
|