@sidekickdb/core 2.0.1 → 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/__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 +2 -2
- 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
package/src/infiniteQuery.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
coerceQuery,
|
|
3
3
|
QueryValidationError,
|
|
4
|
-
type
|
|
4
|
+
type SidekickCoreDatabase,
|
|
5
5
|
type ValidQuery,
|
|
6
6
|
} from './index.ts';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
InstaQLOptions,
|
|
10
|
-
Cursor,
|
|
11
|
-
Order,
|
|
12
|
-
} from './queryTypes.ts';
|
|
13
|
-
import { InstantSchemaDef } from './schemaTypes.ts';
|
|
7
|
+
import { SideQLResponse, SideQLOptions, Cursor, Order } from './queryTypes.ts';
|
|
8
|
+
import { SidekickSchemaDef } from './schemaTypes.ts';
|
|
14
9
|
import { assert } from './utils/error.ts';
|
|
15
10
|
|
|
16
11
|
// Example for {order: {value: "asc"}}
|
|
@@ -111,7 +106,7 @@ const readCanLoadNextPage = (forwardChunks: Map<string, Chunk>) => {
|
|
|
111
106
|
};
|
|
112
107
|
|
|
113
108
|
const reverseOrder = <
|
|
114
|
-
Schema extends
|
|
109
|
+
Schema extends SidekickSchemaDef<any, any, any>,
|
|
115
110
|
Entity extends keyof Schema['entities'],
|
|
116
111
|
>(
|
|
117
112
|
order?: Order<Schema, Entity>,
|
|
@@ -133,7 +128,7 @@ const reverseOrder = <
|
|
|
133
128
|
};
|
|
134
129
|
|
|
135
130
|
const resolveOrder = <
|
|
136
|
-
Schema extends
|
|
131
|
+
Schema extends SidekickSchemaDef<any, any, any>,
|
|
137
132
|
Entity extends keyof Schema['entities'],
|
|
138
133
|
>(
|
|
139
134
|
order?: Order<Schema, Entity>,
|
|
@@ -169,7 +164,7 @@ const normalizeChunks = (
|
|
|
169
164
|
const PRE_BOOTSTRAP_CURSOR: Cursor = ['bootstrap', 'bootstrap', 'bootstrap', 1];
|
|
170
165
|
|
|
171
166
|
export type InfiniteQueryCallbackResponse<
|
|
172
|
-
Schema extends
|
|
167
|
+
Schema extends SidekickSchemaDef<any, any, any>,
|
|
173
168
|
Query extends Record<string, any>,
|
|
174
169
|
UseDatesLocal extends boolean,
|
|
175
170
|
> =
|
|
@@ -180,19 +175,19 @@ export type InfiniteQueryCallbackResponse<
|
|
|
180
175
|
}
|
|
181
176
|
| {
|
|
182
177
|
error: undefined;
|
|
183
|
-
data:
|
|
178
|
+
data: SideQLResponse<Schema, Query, UseDatesLocal>;
|
|
184
179
|
canLoadNextPage: boolean;
|
|
185
180
|
};
|
|
186
181
|
|
|
187
182
|
export const subscribeInfiniteQuery = <
|
|
188
|
-
Schema extends
|
|
183
|
+
Schema extends SidekickSchemaDef<any, any, any>,
|
|
189
184
|
Q extends ValidQuery<Q, Schema>,
|
|
190
185
|
UseDates extends boolean,
|
|
191
186
|
>(
|
|
192
|
-
db:
|
|
187
|
+
db: SidekickCoreDatabase<Schema, UseDates>,
|
|
193
188
|
fullQuery: Q,
|
|
194
189
|
cb: (resp: InfiniteQueryCallbackResponse<Schema, Q, UseDates>) => void,
|
|
195
|
-
opts?:
|
|
190
|
+
opts?: SideQLOptions,
|
|
196
191
|
): InfiniteQuerySubscription => {
|
|
197
192
|
const { entityName, entityQuery: query } = splitAndValidateQuery(fullQuery);
|
|
198
193
|
|
|
@@ -209,6 +204,9 @@ export const subscribeInfiniteQuery = <
|
|
|
209
204
|
let isActive = true;
|
|
210
205
|
let lastReverseAdvancedChunkKey: string | null = null;
|
|
211
206
|
let starterUnsub: (() => void) | null = null;
|
|
207
|
+
// SidekickDB: id of the first row of a full page shown from optimistic data,
|
|
208
|
+
// before the server gave a start cursor.
|
|
209
|
+
let optimisticPageFirstId: string | null = null;
|
|
212
210
|
|
|
213
211
|
const sendError = (err: { message: string }) => {
|
|
214
212
|
cb({ error: err, data: undefined, canLoadNextPage: false });
|
|
@@ -219,7 +217,7 @@ export const subscribeInfiniteQuery = <
|
|
|
219
217
|
|
|
220
218
|
const { chunks, data } = normalizeChunks(forwardChunks, reverseChunks);
|
|
221
219
|
cb({
|
|
222
|
-
data: { [entity]: data } as
|
|
220
|
+
data: { [entity]: data } as SideQLResponse<
|
|
223
221
|
Schema,
|
|
224
222
|
typeof query,
|
|
225
223
|
UseDates
|
|
@@ -321,13 +319,17 @@ export const subscribeInfiniteQuery = <
|
|
|
321
319
|
allUnsubs.set(chunkSubKey('reverse', startCursor), querySub);
|
|
322
320
|
};
|
|
323
321
|
|
|
324
|
-
const pushNewForward = (
|
|
322
|
+
const pushNewForward = (
|
|
323
|
+
startCursor: Cursor,
|
|
324
|
+
afterInclusive = false,
|
|
325
|
+
limit = pageSize,
|
|
326
|
+
) => {
|
|
325
327
|
const querySub = db.subscribeQuery(
|
|
326
328
|
{
|
|
327
329
|
[entity]: {
|
|
328
330
|
...query,
|
|
329
331
|
$: {
|
|
330
|
-
limit
|
|
332
|
+
limit,
|
|
331
333
|
after: startCursor,
|
|
332
334
|
afterInclusive,
|
|
333
335
|
where: query.$?.where,
|
|
@@ -492,6 +494,7 @@ export const subscribeInfiniteQuery = <
|
|
|
492
494
|
// state.
|
|
493
495
|
const initialForwardCursor = pageInfo.startCursor;
|
|
494
496
|
if (!initialForwardCursor) {
|
|
497
|
+
optimisticPageFirstId ??= rows[0]?.id ?? null;
|
|
495
498
|
setForwardChunk(PRE_BOOTSTRAP_CURSOR, {
|
|
496
499
|
data: rows,
|
|
497
500
|
status: 'pre-bootstrap',
|
|
@@ -501,7 +504,21 @@ export const subscribeInfiniteQuery = <
|
|
|
501
504
|
|
|
502
505
|
forwardChunks.delete(makeChunkKey(PRE_BOOTSTRAP_CURSOR));
|
|
503
506
|
|
|
504
|
-
|
|
507
|
+
// SidekickDB: rows added before an optimistic full page while the
|
|
508
|
+
// server had not yet answered with a start cursor would otherwise push
|
|
509
|
+
// that page's last rows out of the first chunk. The first chunk keeps
|
|
510
|
+
// them by growing by that many rows.
|
|
511
|
+
const shownStart = rows.findIndex(
|
|
512
|
+
(row: any) => row.id === optimisticPageFirstId,
|
|
513
|
+
);
|
|
514
|
+
const serverStart = rows.findIndex(
|
|
515
|
+
(row: any) => row.id === initialForwardCursor[0],
|
|
516
|
+
);
|
|
517
|
+
const addedBefore =
|
|
518
|
+
serverStart >= 0 && shownStart > serverStart
|
|
519
|
+
? shownStart - serverStart
|
|
520
|
+
: 0;
|
|
521
|
+
pushNewForward(initialForwardCursor, true, pageSize + addedBefore);
|
|
505
522
|
pushNewReverse(pageInfo.startCursor);
|
|
506
523
|
hasKickstarted = true;
|
|
507
524
|
},
|
|
@@ -526,13 +543,13 @@ export const subscribeInfiniteQuery = <
|
|
|
526
543
|
};
|
|
527
544
|
|
|
528
545
|
export const getInfiniteQueryInitialSnapshot = <
|
|
529
|
-
Schema extends
|
|
546
|
+
Schema extends SidekickSchemaDef<any, any, any>,
|
|
530
547
|
Q extends ValidQuery<Q, Schema>,
|
|
531
548
|
UseDates extends boolean,
|
|
532
549
|
>(
|
|
533
|
-
db:
|
|
550
|
+
db: SidekickCoreDatabase<Schema, UseDates>,
|
|
534
551
|
fullQuery: Q | null,
|
|
535
|
-
opts?:
|
|
552
|
+
opts?: SideQLOptions,
|
|
536
553
|
):
|
|
537
554
|
| InfiniteQueryCallbackResponse<Schema, Q, UseDates>
|
|
538
555
|
| {
|
|
@@ -13,7 +13,7 @@ function _extractTriplesHelper(idNodes, acc = []) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* Marshall
|
|
16
|
+
* Marshall sideql-result into list of triples. Sideql-result may have
|
|
17
17
|
* multiple datalog-results, each datalog-result may have multiple join-rows
|
|
18
18
|
* and each join-row may have triples.The union of these triples may have
|
|
19
19
|
* duplicates, so we dedup them.
|
package/src/notifyScope.ts
CHANGED
|
@@ -128,7 +128,7 @@ export function mutationFootprint(
|
|
|
128
128
|
return fp;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
// The `where` operators
|
|
131
|
+
// The `where` operators sideql understands. Anything else is unknown.
|
|
132
132
|
const WHERE_OPS = new Set([
|
|
133
133
|
'$in',
|
|
134
134
|
'in',
|
|
@@ -183,7 +183,7 @@ function readWhere(
|
|
|
183
183
|
}
|
|
184
184
|
continue;
|
|
185
185
|
}
|
|
186
|
-
//
|
|
186
|
+
// sideql ignores it.
|
|
187
187
|
if (k === '$entityIdStartsWith') continue;
|
|
188
188
|
if (!isKnownWhereValue(v)) return false;
|
|
189
189
|
|
|
@@ -250,7 +250,7 @@ function readLevel(
|
|
|
250
250
|
if (typeof f !== 'string') return false;
|
|
251
251
|
fp.keys.add(`a|${etype}|${f}`);
|
|
252
252
|
}
|
|
253
|
-
//
|
|
253
|
+
// sideql always returns the id.
|
|
254
254
|
fp.keys.add(`a|${etype}|id`);
|
|
255
255
|
}
|
|
256
256
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { i } from './schema.ts';
|
|
2
|
-
import { DataAttrDef,
|
|
2
|
+
import { DataAttrDef, SidekickSchemaDef } from './schemaTypes.ts';
|
|
3
3
|
|
|
4
4
|
export const parseSchemaFromJSON = (
|
|
5
5
|
s: any,
|
|
6
|
-
):
|
|
6
|
+
): SidekickSchemaDef<any, any, any> => {
|
|
7
7
|
// Parse entities
|
|
8
8
|
const entities: Record<string, any> = {};
|
|
9
9
|
|
package/src/queryTypes.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type {
|
|
5
5
|
EntitiesDef,
|
|
6
6
|
IContainEntitiesAndLinks,
|
|
7
|
-
|
|
7
|
+
SidekickGraph,
|
|
8
8
|
LinkAttrDef,
|
|
9
9
|
RuleParams,
|
|
10
10
|
ResolveAttrs,
|
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
DataAttrDef,
|
|
13
13
|
AttrsDefs,
|
|
14
14
|
EntityDefFromSchema,
|
|
15
|
-
|
|
15
|
+
SidekickUnknownSchemaDef,
|
|
16
16
|
} from './schemaTypes.ts';
|
|
17
17
|
|
|
18
18
|
type BuiltIn = Date | Function | Error | RegExp;
|
|
@@ -164,7 +164,7 @@ type $Option<
|
|
|
164
164
|
afterInclusive?: boolean;
|
|
165
165
|
before?: Cursor;
|
|
166
166
|
beforeInclusive?: boolean;
|
|
167
|
-
fields?:
|
|
167
|
+
fields?: SideQLFields<S, K>;
|
|
168
168
|
};
|
|
169
169
|
};
|
|
170
170
|
|
|
@@ -178,14 +178,14 @@ interface Query {
|
|
|
178
178
|
[namespace: string]: NamespaceVal;
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
type
|
|
181
|
+
type SidekickObject = {
|
|
182
182
|
id: string;
|
|
183
183
|
[prop: string]: any;
|
|
184
184
|
};
|
|
185
185
|
|
|
186
186
|
type ResponseObject<K, Schema> = K extends keyof Schema
|
|
187
187
|
? { id: string } & Schema[K]
|
|
188
|
-
:
|
|
188
|
+
: SidekickObject;
|
|
189
189
|
|
|
190
190
|
type IsEmptyObject<T> = T extends Record<string, never> ? true : false;
|
|
191
191
|
|
|
@@ -209,14 +209,14 @@ type QueryResponse<
|
|
|
209
209
|
WithCardinalityInference extends boolean = false,
|
|
210
210
|
UseDates extends boolean = false,
|
|
211
211
|
> =
|
|
212
|
-
Schema extends
|
|
213
|
-
?
|
|
212
|
+
Schema extends SidekickGraph<infer E, any>
|
|
213
|
+
? SideQLQueryResult<E, Q, WithCardinalityInference, UseDates>
|
|
214
214
|
: ResponseOf<{ [K in keyof Q]: Remove$<Q[K]> }, Schema>;
|
|
215
215
|
|
|
216
|
-
type
|
|
216
|
+
type SideQLResponse<Schema, Q, UseDates extends boolean = false> =
|
|
217
217
|
Schema extends IContainEntitiesAndLinks<any, any>
|
|
218
|
-
? Q extends
|
|
219
|
-
?
|
|
218
|
+
? Q extends SideQLParams<Schema> | undefined
|
|
219
|
+
? SideQLResult<Schema, Q, UseDates>
|
|
220
220
|
: never
|
|
221
221
|
: never;
|
|
222
222
|
|
|
@@ -270,12 +270,12 @@ type SafeLookup<T, K extends readonly PropertyKey[]> = K extends [
|
|
|
270
270
|
: T;
|
|
271
271
|
|
|
272
272
|
// ==========
|
|
273
|
-
//
|
|
273
|
+
// SideQL helpers
|
|
274
274
|
|
|
275
|
-
type
|
|
275
|
+
type SideQLEntitySubqueryResult<
|
|
276
276
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
277
277
|
EntityName extends keyof Schema['entities'],
|
|
278
|
-
Query extends
|
|
278
|
+
Query extends SideQLEntitySubquery<Schema, EntityName> | undefined = {},
|
|
279
279
|
UseDates extends boolean = false,
|
|
280
280
|
> = {
|
|
281
281
|
[QueryPropName in keyof Query]: Schema['entities'][EntityName]['links'][QueryPropName] extends LinkAttrDef<
|
|
@@ -285,7 +285,7 @@ type InstaQLEntitySubqueryResult<
|
|
|
285
285
|
? LinkedEntityName extends keyof Schema['entities']
|
|
286
286
|
? Cardinality extends 'one'
|
|
287
287
|
?
|
|
288
|
-
|
|
|
288
|
+
| SideQLEntity<
|
|
289
289
|
Schema,
|
|
290
290
|
LinkedEntityName,
|
|
291
291
|
Remove$NonRecursive<SafeLookup<Query, [QueryPropName]>>,
|
|
@@ -293,7 +293,7 @@ type InstaQLEntitySubqueryResult<
|
|
|
293
293
|
UseDates
|
|
294
294
|
>
|
|
295
295
|
| undefined
|
|
296
|
-
:
|
|
296
|
+
: SideQLEntity<
|
|
297
297
|
Schema,
|
|
298
298
|
LinkedEntityName,
|
|
299
299
|
Remove$NonRecursive<SafeLookup<Query, [QueryPropName]>>,
|
|
@@ -304,7 +304,7 @@ type InstaQLEntitySubqueryResult<
|
|
|
304
304
|
: never;
|
|
305
305
|
};
|
|
306
306
|
|
|
307
|
-
type
|
|
307
|
+
type SideQLQueryEntityLinksResult<
|
|
308
308
|
Entities extends EntitiesDef,
|
|
309
309
|
EntityName extends keyof Entities,
|
|
310
310
|
Query extends {
|
|
@@ -321,7 +321,7 @@ type InstaQLQueryEntityLinksResult<
|
|
|
321
321
|
? WithCardinalityInference extends true
|
|
322
322
|
? Cardinality extends 'one'
|
|
323
323
|
?
|
|
324
|
-
|
|
|
324
|
+
| SideQLQueryEntityResult<
|
|
325
325
|
Entities,
|
|
326
326
|
LinkedEntityName,
|
|
327
327
|
Query[QueryPropName],
|
|
@@ -329,14 +329,14 @@ type InstaQLQueryEntityLinksResult<
|
|
|
329
329
|
UseDates
|
|
330
330
|
>
|
|
331
331
|
| undefined
|
|
332
|
-
:
|
|
332
|
+
: SideQLQueryEntityResult<
|
|
333
333
|
Entities,
|
|
334
334
|
LinkedEntityName,
|
|
335
335
|
Query[QueryPropName],
|
|
336
336
|
WithCardinalityInference,
|
|
337
337
|
UseDates
|
|
338
338
|
>[]
|
|
339
|
-
:
|
|
339
|
+
: SideQLQueryEntityResult<
|
|
340
340
|
Entities,
|
|
341
341
|
LinkedEntityName,
|
|
342
342
|
Query[QueryPropName],
|
|
@@ -352,7 +352,7 @@ type DistributePick<T, K extends string> = T extends any
|
|
|
352
352
|
? { [P in K]: P extends keyof T ? T[P] : never }
|
|
353
353
|
: never;
|
|
354
354
|
|
|
355
|
-
type
|
|
355
|
+
type SideQLFields<
|
|
356
356
|
S extends IContainEntitiesAndLinks<any, any>,
|
|
357
357
|
K extends keyof S['entities'],
|
|
358
358
|
> = (Extract<keyof ResolveEntityAttrs<S['entities'][K]>, string> | 'id')[];
|
|
@@ -364,21 +364,21 @@ type ComputeAttrs<
|
|
|
364
364
|
? DistributePick<AllAttrs, Exclude<Fields[number], 'id'>>
|
|
365
365
|
: AllAttrs;
|
|
366
366
|
|
|
367
|
-
type
|
|
367
|
+
type SideQLEntity<
|
|
368
368
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
369
369
|
EntityName extends keyof Schema['entities'],
|
|
370
|
-
Subquery extends
|
|
371
|
-
Fields extends
|
|
370
|
+
Subquery extends SideQLEntitySubquery<Schema, EntityName> | undefined = {},
|
|
371
|
+
Fields extends SideQLFields<Schema, EntityName> | undefined = undefined,
|
|
372
372
|
UseDates extends boolean = false,
|
|
373
373
|
> = Expand<
|
|
374
374
|
{ id: string } & ComputeAttrs<
|
|
375
375
|
ResolveEntityAttrs<Schema['entities'][EntityName], UseDates>,
|
|
376
376
|
Fields
|
|
377
377
|
> &
|
|
378
|
-
|
|
378
|
+
SideQLEntitySubqueryResult<Schema, EntityName, Subquery, UseDates>
|
|
379
379
|
>;
|
|
380
380
|
|
|
381
|
-
export type
|
|
381
|
+
export type SideQLQueryEntityResult<
|
|
382
382
|
Entities extends EntitiesDef,
|
|
383
383
|
EntityName extends keyof Entities,
|
|
384
384
|
Query extends {
|
|
@@ -387,7 +387,7 @@ export type InstaQLQueryEntityResult<
|
|
|
387
387
|
WithCardinalityInference extends boolean,
|
|
388
388
|
UseDates extends boolean,
|
|
389
389
|
> = { id: string } & ResolveAttrs<Entities, EntityName, UseDates> &
|
|
390
|
-
|
|
390
|
+
SideQLQueryEntityLinksResult<
|
|
391
391
|
Entities,
|
|
392
392
|
EntityName,
|
|
393
393
|
Query,
|
|
@@ -395,14 +395,14 @@ export type InstaQLQueryEntityResult<
|
|
|
395
395
|
UseDates
|
|
396
396
|
>;
|
|
397
397
|
|
|
398
|
-
type
|
|
398
|
+
type SideQLQueryResult<
|
|
399
399
|
Entities extends EntitiesDef,
|
|
400
400
|
Query,
|
|
401
401
|
WithCardinalityInference extends boolean,
|
|
402
402
|
UseDates extends boolean,
|
|
403
403
|
> = {
|
|
404
404
|
[QueryPropName in keyof Query]: QueryPropName extends keyof Entities
|
|
405
|
-
?
|
|
405
|
+
? SideQLQueryEntityResult<
|
|
406
406
|
Entities,
|
|
407
407
|
QueryPropName,
|
|
408
408
|
Query[QueryPropName],
|
|
@@ -412,13 +412,13 @@ type InstaQLQueryResult<
|
|
|
412
412
|
: never;
|
|
413
413
|
};
|
|
414
414
|
|
|
415
|
-
type
|
|
415
|
+
type SideQLResult<
|
|
416
416
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
417
|
-
Query extends
|
|
417
|
+
Query extends SideQLParams<Schema> | undefined,
|
|
418
418
|
UseDates extends boolean = false,
|
|
419
419
|
> = Expand<{
|
|
420
420
|
[QueryPropName in keyof Query]: QueryPropName extends keyof Schema['entities']
|
|
421
|
-
?
|
|
421
|
+
? SideQLEntity<
|
|
422
422
|
Schema,
|
|
423
423
|
QueryPropName,
|
|
424
424
|
Remove$NonRecursive<SafeLookup<Query, [QueryPropName]>>,
|
|
@@ -428,52 +428,52 @@ type InstaQLResult<
|
|
|
428
428
|
: never;
|
|
429
429
|
}>;
|
|
430
430
|
|
|
431
|
-
type
|
|
431
|
+
type SideQLEntitySubquery<
|
|
432
432
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
433
433
|
EntityName extends keyof Schema['entities'],
|
|
434
434
|
> = {
|
|
435
435
|
[QueryPropName in keyof Schema['entities'][EntityName]['links']]?:
|
|
436
436
|
| $Option<Schema, EntityName>
|
|
437
437
|
| ($Option<Schema, EntityName> &
|
|
438
|
-
|
|
438
|
+
SideQLEntitySubquery<
|
|
439
439
|
Schema,
|
|
440
440
|
Schema['entities'][EntityName]['links'][QueryPropName]['entityName']
|
|
441
441
|
>);
|
|
442
442
|
};
|
|
443
443
|
|
|
444
|
-
type
|
|
444
|
+
type SideQLQuerySubqueryParams<
|
|
445
445
|
S extends IContainEntitiesAndLinks<any, any>,
|
|
446
446
|
E extends keyof S['entities'],
|
|
447
447
|
> = {
|
|
448
448
|
[K in keyof S['entities'][E]['links']]?:
|
|
449
449
|
| $Option<S, S['entities'][E]['links'][K]['entityName']>
|
|
450
450
|
| ($Option<S, S['entities'][E]['links'][K]['entityName']> &
|
|
451
|
-
|
|
451
|
+
SideQLQuerySubqueryParams<
|
|
452
452
|
S,
|
|
453
453
|
S['entities'][E]['links'][K]['entityName']
|
|
454
454
|
>);
|
|
455
455
|
};
|
|
456
456
|
|
|
457
|
-
type
|
|
457
|
+
type SideQLParams<S extends IContainEntitiesAndLinks<any, any>> = {
|
|
458
458
|
[K in keyof S['entities']]?:
|
|
459
459
|
| $Option<S, K>
|
|
460
|
-
| ($Option<S, K> &
|
|
460
|
+
| ($Option<S, K> & SideQLQuerySubqueryParams<S, K>);
|
|
461
461
|
};
|
|
462
462
|
|
|
463
463
|
/**
|
|
464
464
|
* @deprecated
|
|
465
|
-
* `
|
|
465
|
+
* `SideQLQueryParams` is deprecated. Use `SideQLParams` instead.
|
|
466
466
|
*
|
|
467
467
|
* @example
|
|
468
468
|
* // Before
|
|
469
|
-
* const myQuery = {...} satisfies
|
|
469
|
+
* const myQuery = {...} satisfies SideQLQueryParams<Schema>
|
|
470
470
|
* // After
|
|
471
|
-
* const myQuery = {...} satisfies
|
|
471
|
+
* const myQuery = {...} satisfies SideQLParams<Schema>
|
|
472
472
|
*/
|
|
473
|
-
type
|
|
474
|
-
|
|
473
|
+
type SideQLQueryParams<S extends IContainEntitiesAndLinks<any, any>> =
|
|
474
|
+
SideQLParams<S>;
|
|
475
475
|
|
|
476
|
-
type
|
|
476
|
+
type SideQLOptions = {
|
|
477
477
|
ruleParams: RuleParams;
|
|
478
478
|
};
|
|
479
479
|
|
|
@@ -692,8 +692,8 @@ type ExtractAttrFromDotPath<
|
|
|
692
692
|
type ValidQuery<
|
|
693
693
|
Q extends Record<string, any>,
|
|
694
694
|
S extends IContainEntitiesAndLinks<any, any>,
|
|
695
|
-
> = S extends
|
|
696
|
-
?
|
|
695
|
+
> = S extends SidekickUnknownSchemaDef
|
|
696
|
+
? SideQLParams<S>
|
|
697
697
|
: keyof Q extends keyof S['entities']
|
|
698
698
|
? {
|
|
699
699
|
[K in keyof S['entities']]?: ValidQueryObject<Q[K], S, K, true>;
|
|
@@ -703,19 +703,19 @@ type ValidQuery<
|
|
|
703
703
|
export {
|
|
704
704
|
Query,
|
|
705
705
|
QueryResponse,
|
|
706
|
-
|
|
706
|
+
SideQLResponse,
|
|
707
707
|
PageInfoResponse,
|
|
708
|
-
|
|
708
|
+
SidekickObject,
|
|
709
709
|
Exactly,
|
|
710
710
|
Remove$,
|
|
711
711
|
ValidQuery,
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
712
|
+
SideQLQueryResult,
|
|
713
|
+
SideQLParams,
|
|
714
|
+
SideQLOptions,
|
|
715
|
+
SideQLEntitySubquery,
|
|
716
|
+
SideQLEntity,
|
|
717
|
+
SideQLResult,
|
|
718
|
+
SideQLFields,
|
|
719
719
|
Cursor,
|
|
720
|
-
|
|
720
|
+
SideQLQueryParams,
|
|
721
721
|
};
|
|
@@ -2,23 +2,23 @@ import type { User } from './clientTypes.ts';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Known payloads sent to `firstPartyPath` and handled by
|
|
5
|
-
* `
|
|
5
|
+
* `createSidekickRouteHandler`.
|
|
6
6
|
*/
|
|
7
|
-
export type
|
|
7
|
+
export type SidekickRouteHandlerPayloadByType = {
|
|
8
8
|
'sync-user': {
|
|
9
9
|
appId: string;
|
|
10
10
|
user: User | null;
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
/** Known `type` values for
|
|
15
|
-
export type
|
|
14
|
+
/** Known `type` values for SidekickDB route handler request bodies. */
|
|
15
|
+
export type SidekickRouteHandlerType = keyof SidekickRouteHandlerPayloadByType;
|
|
16
16
|
|
|
17
|
-
/** A valid request body for
|
|
18
|
-
export type
|
|
19
|
-
Type extends
|
|
17
|
+
/** A valid request body for SidekickDB's first-party route handler protocol. */
|
|
18
|
+
export type SidekickRouteHandlerBody<
|
|
19
|
+
Type extends SidekickRouteHandlerType = SidekickRouteHandlerType,
|
|
20
20
|
> = {
|
|
21
21
|
[KnownType in Type]: {
|
|
22
22
|
type: KnownType;
|
|
23
|
-
} &
|
|
23
|
+
} & SidekickRouteHandlerPayloadByType[KnownType];
|
|
24
24
|
}[Type];
|
package/src/rulesTypes.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SidekickSchemaDef, SidekickUnknownSchema } from './schemaTypes.ts';
|
|
2
2
|
|
|
3
|
-
type
|
|
3
|
+
type SidekickRulesAttrsAllowBlock = {
|
|
4
4
|
$default?: string | null | undefined;
|
|
5
5
|
view?: string | null | undefined;
|
|
6
6
|
create?: string | null | undefined;
|
|
@@ -8,7 +8,7 @@ type InstantRulesAttrsAllowBlock = {
|
|
|
8
8
|
delete?: string | null | undefined;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export type
|
|
11
|
+
export type SidekickRulesAllowBlock = SidekickRulesAttrsAllowBlock & {
|
|
12
12
|
link?: { [key: string]: string } | null | undefined;
|
|
13
13
|
unlink?: { [key: string]: string } | null | undefined;
|
|
14
14
|
};
|
|
@@ -18,13 +18,13 @@ export type InstantRulesAllowBlock = InstantRulesAttrsAllowBlock & {
|
|
|
18
18
|
* - `'greedy'`: tokens trickle in continuously over the period.
|
|
19
19
|
* - `'interval'`: all tokens are added at once when the period elapses.
|
|
20
20
|
*/
|
|
21
|
-
export type
|
|
21
|
+
export type SidekickRulesRateLimitRefillType = 'interval' | 'greedy';
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Configuration for how a rate limit bucket refills.
|
|
25
25
|
* All fields are optional and have sensible defaults.
|
|
26
26
|
*/
|
|
27
|
-
export type
|
|
27
|
+
export type SidekickRulesRateLimitRefill = {
|
|
28
28
|
/** Number of tokens added per refill. Defaults to the bucket's capacity. */
|
|
29
29
|
amount?: number | null | undefined;
|
|
30
30
|
/**
|
|
@@ -33,41 +33,41 @@ export type InstantRulesRateLimitRefill = {
|
|
|
33
33
|
*/
|
|
34
34
|
period?: string | null | undefined;
|
|
35
35
|
/** Refill strategy. Defaults to `"greedy"`. */
|
|
36
|
-
type?:
|
|
36
|
+
type?: SidekickRulesRateLimitRefillType | null | undefined;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* A single rate limit within a bucket. Each limit represents one token bucket
|
|
41
41
|
* constraint. You can combine multiple limits (e.g. a burst limit and a sustained limit).
|
|
42
42
|
*/
|
|
43
|
-
export type
|
|
43
|
+
export type SidekickRulesRateLimitLimit = {
|
|
44
44
|
/** Maximum number of tokens in the bucket. */
|
|
45
45
|
capacity: number;
|
|
46
46
|
/** Refill configuration. Defaults to greedy refill of the full capacity every hour. */
|
|
47
|
-
refill?:
|
|
47
|
+
refill?: SidekickRulesRateLimitRefill | null | undefined;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* A named rate limit bucket configuration. Use in permission rules via
|
|
52
52
|
* `rateLimit.bucketName.limit(key)`.
|
|
53
53
|
*/
|
|
54
|
-
export type
|
|
54
|
+
export type SidekickRulesRateLimit = {
|
|
55
55
|
/** One or more token bucket limits to apply. */
|
|
56
|
-
limits: Array<
|
|
56
|
+
limits: Array<SidekickRulesRateLimitLimit>;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Map of rate limit names to their configurations.
|
|
61
61
|
* Defined under the `$rateLimits` key in your permission rules.
|
|
62
62
|
*/
|
|
63
|
-
export type
|
|
63
|
+
export type SidekickRulesRateLimits = Record<string, SidekickRulesRateLimit>;
|
|
64
64
|
|
|
65
|
-
type
|
|
66
|
-
Schema extends
|
|
65
|
+
type SidekickRulesEntityBlock<
|
|
66
|
+
Schema extends SidekickSchemaDef<any, any, any>,
|
|
67
67
|
EntityName extends keyof Schema['entities'],
|
|
68
68
|
> = {
|
|
69
69
|
bind?: string[] | Record<string, string>;
|
|
70
|
-
allow:
|
|
70
|
+
allow: SidekickRulesAllowBlock;
|
|
71
71
|
fields?: {
|
|
72
72
|
[AttrName in Exclude<
|
|
73
73
|
keyof Schema['entities'][EntityName]['attrs'],
|
|
@@ -83,21 +83,21 @@ type InstantRulesEntityBlock<
|
|
|
83
83
|
// 2. If you do pass a schema, then we can handle each special key separately
|
|
84
84
|
// without it collapsing into string.
|
|
85
85
|
|
|
86
|
-
export type
|
|
87
|
-
Schema extends
|
|
86
|
+
export type SidekickRules<
|
|
87
|
+
Schema extends SidekickSchemaDef<any, any, any> = SidekickUnknownSchema,
|
|
88
88
|
> = {
|
|
89
89
|
[K in 'attrs' | '$default' | '$rateLimits']?: K extends 'attrs'
|
|
90
90
|
? {
|
|
91
91
|
bind?: string[] | Record<string, string>;
|
|
92
|
-
allow:
|
|
92
|
+
allow: SidekickRulesAttrsAllowBlock;
|
|
93
93
|
}
|
|
94
94
|
: K extends '$default'
|
|
95
95
|
? {
|
|
96
96
|
bind?: string[] | Record<string, string>;
|
|
97
|
-
allow:
|
|
97
|
+
allow: SidekickRulesAllowBlock;
|
|
98
98
|
}
|
|
99
99
|
: K extends '$rateLimits'
|
|
100
|
-
?
|
|
100
|
+
? SidekickRulesRateLimits
|
|
101
101
|
: never;
|
|
102
102
|
} & {
|
|
103
103
|
[K in
|
|
@@ -107,16 +107,16 @@ export type InstantRules<
|
|
|
107
107
|
| '$rateLimits']?: K extends 'attrs'
|
|
108
108
|
? {
|
|
109
109
|
bind?: string[] | Record<string, string>;
|
|
110
|
-
allow:
|
|
110
|
+
allow: SidekickRulesAttrsAllowBlock;
|
|
111
111
|
}
|
|
112
112
|
: K extends '$default'
|
|
113
113
|
? {
|
|
114
114
|
bind?: string[] | Record<string, string>;
|
|
115
|
-
allow:
|
|
115
|
+
allow: SidekickRulesAllowBlock;
|
|
116
116
|
}
|
|
117
117
|
: K extends '$rateLimits'
|
|
118
|
-
?
|
|
118
|
+
? SidekickRulesRateLimits
|
|
119
119
|
: K extends keyof Schema['entities']
|
|
120
|
-
?
|
|
120
|
+
? SidekickRulesEntityBlock<Schema, K>
|
|
121
121
|
: never;
|
|
122
122
|
};
|