@instantdb/core 0.22.69 → 0.22.70
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/__tests__/src/fieldsTypeTest.ts +111 -0
- package/__tests__/src/typeUtils.ts +39 -0
- package/__tests__/src/useDatesTypeTest.ts +67 -0
- package/__tests__/src/utils/PersistedObject.test.ts +8 -0
- package/dist/commonjs/Connection.d.ts.map +1 -1
- package/dist/commonjs/Connection.js +5 -4
- package/dist/commonjs/Connection.js.map +1 -1
- package/dist/commonjs/Reactor.d.ts +21 -10
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/SyncTable.d.ts +10 -10
- package/dist/commonjs/SyncTable.d.ts.map +1 -1
- package/dist/commonjs/SyncTable.js.map +1 -1
- package/dist/commonjs/devtool.js.map +1 -1
- package/dist/commonjs/helperTypes.d.ts +1 -1
- package/dist/commonjs/helperTypes.d.ts.map +1 -1
- package/dist/commonjs/helperTypes.js.map +1 -1
- package/dist/commonjs/index.d.ts +7 -7
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +3 -2
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/queryTypes.d.ts +20 -11
- package/dist/commonjs/queryTypes.d.ts.map +1 -1
- package/dist/commonjs/queryTypes.js.map +1 -1
- package/dist/commonjs/queryValidation.js.map +1 -1
- package/dist/commonjs/schemaTypes.d.ts +2 -2
- package/dist/commonjs/schemaTypes.d.ts.map +1 -1
- package/dist/commonjs/schemaTypes.js.map +1 -1
- package/dist/commonjs/utils/PersistedObject.d.ts +2 -2
- package/dist/esm/Connection.d.ts.map +1 -1
- package/dist/esm/Connection.js +5 -4
- package/dist/esm/Connection.js.map +1 -1
- package/dist/esm/Reactor.d.ts +21 -10
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/SyncTable.d.ts +10 -10
- package/dist/esm/SyncTable.d.ts.map +1 -1
- package/dist/esm/SyncTable.js.map +1 -1
- package/dist/esm/devtool.js.map +1 -1
- package/dist/esm/helperTypes.d.ts +1 -1
- package/dist/esm/helperTypes.d.ts.map +1 -1
- package/dist/esm/helperTypes.js.map +1 -1
- package/dist/esm/index.d.ts +7 -7
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/queryTypes.d.ts +20 -11
- package/dist/esm/queryTypes.d.ts.map +1 -1
- package/dist/esm/queryTypes.js.map +1 -1
- package/dist/esm/queryValidation.js.map +1 -1
- package/dist/esm/schemaTypes.d.ts +2 -2
- package/dist/esm/schemaTypes.d.ts.map +1 -1
- package/dist/esm/schemaTypes.js.map +1 -1
- package/dist/esm/utils/PersistedObject.d.ts +2 -2
- package/dist/standalone/index.js +216 -214
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/Connection.ts +4 -4
- package/src/SyncTable.ts +10 -10
- package/src/devtool.ts +2 -2
- package/src/helperTypes.ts +3 -1
- package/src/index.ts +19 -11
- package/src/queryTypes.ts +52 -24
- package/src/queryValidation.ts +2 -2
- package/src/schemaTypes.ts +5 -2
- package/tsconfig.json +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instantdb/core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.70",
|
|
4
4
|
"description": "Instant's core local abstraction",
|
|
5
5
|
"homepage": "https://github.com/instantdb/instant/tree/main/client/packages/core",
|
|
6
6
|
"repository": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"mutative": "^1.0.10",
|
|
55
55
|
"uuid": "^11.1.0",
|
|
56
|
-
"@instantdb/version": "0.22.
|
|
56
|
+
"@instantdb/version": "0.22.70"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"test": "vitest",
|
package/src/Connection.ts
CHANGED
|
@@ -128,7 +128,7 @@ export class SSEConnection implements Connection<EventSourceType> {
|
|
|
128
128
|
private sendQueue: any[] = [];
|
|
129
129
|
private sendPromise: Promise<void> | null;
|
|
130
130
|
private closeFired: boolean = false;
|
|
131
|
-
private sseInitTimeout:
|
|
131
|
+
private sseInitTimeout: ReturnType<typeof setTimeout> | undefined = undefined;
|
|
132
132
|
private ES: EventSourceConstructor;
|
|
133
133
|
conn: EventSourceType;
|
|
134
134
|
url: string;
|
|
@@ -203,9 +203,9 @@ export class SSEConnection implements Connection<EventSourceType> {
|
|
|
203
203
|
method: 'POST',
|
|
204
204
|
headers: { 'Content-Type': 'application/json' },
|
|
205
205
|
body: JSON.stringify({
|
|
206
|
-
machine_id: this.initParams
|
|
207
|
-
session_id: this.initParams
|
|
208
|
-
sse_token: this.initParams
|
|
206
|
+
machine_id: this.initParams?.machineId,
|
|
207
|
+
session_id: this.initParams?.sessionId,
|
|
208
|
+
sse_token: this.initParams?.sseToken,
|
|
209
209
|
messages,
|
|
210
210
|
}),
|
|
211
211
|
});
|
package/src/SyncTable.ts
CHANGED
|
@@ -309,7 +309,7 @@ export enum CallbackEventType {
|
|
|
309
309
|
type QueryEntities<
|
|
310
310
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
311
311
|
Q extends ValidQuery<Q, Schema>,
|
|
312
|
-
UseDates extends boolean,
|
|
312
|
+
UseDates extends boolean | undefined,
|
|
313
313
|
> = InstaQLResponse<Schema, Q, UseDates>[keyof InstaQLResponse<
|
|
314
314
|
Schema,
|
|
315
315
|
Q,
|
|
@@ -319,7 +319,7 @@ type QueryEntities<
|
|
|
319
319
|
type QueryEntity<
|
|
320
320
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
321
321
|
Q extends ValidQuery<Q, Schema>,
|
|
322
|
-
UseDates extends boolean,
|
|
322
|
+
UseDates extends boolean | undefined,
|
|
323
323
|
> = QueryEntities<Schema, Q, UseDates> extends (infer E)[] ? E : never;
|
|
324
324
|
|
|
325
325
|
type ChangedFields<Entity> = {
|
|
@@ -332,7 +332,7 @@ type ChangedFields<Entity> = {
|
|
|
332
332
|
export interface BaseCallbackEvent<
|
|
333
333
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
334
334
|
Q extends ValidQuery<Q, Schema>,
|
|
335
|
-
UseDates extends boolean,
|
|
335
|
+
UseDates extends boolean | undefined,
|
|
336
336
|
> {
|
|
337
337
|
type: CallbackEventType;
|
|
338
338
|
data: InstaQLResponse<Schema, Q, UseDates>;
|
|
@@ -341,7 +341,7 @@ export interface BaseCallbackEvent<
|
|
|
341
341
|
export interface InitialSyncBatch<
|
|
342
342
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
343
343
|
Q extends ValidQuery<Q, Schema>,
|
|
344
|
-
UseDates extends boolean,
|
|
344
|
+
UseDates extends boolean | undefined,
|
|
345
345
|
> extends BaseCallbackEvent<Schema, Q, UseDates> {
|
|
346
346
|
type: CallbackEventType.InitialSyncBatch;
|
|
347
347
|
batch: QueryEntities<Schema, Q, UseDates>;
|
|
@@ -350,7 +350,7 @@ export interface InitialSyncBatch<
|
|
|
350
350
|
export interface InitialSyncComplete<
|
|
351
351
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
352
352
|
Q extends ValidQuery<Q, Schema>,
|
|
353
|
-
UseDates extends boolean,
|
|
353
|
+
UseDates extends boolean | undefined,
|
|
354
354
|
> extends BaseCallbackEvent<Schema, Q, UseDates> {
|
|
355
355
|
type: CallbackEventType.InitialSyncComplete;
|
|
356
356
|
}
|
|
@@ -358,7 +358,7 @@ export interface InitialSyncComplete<
|
|
|
358
358
|
export interface SyncTransaction<
|
|
359
359
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
360
360
|
Q extends ValidQuery<Q, Schema>,
|
|
361
|
-
UseDates extends boolean,
|
|
361
|
+
UseDates extends boolean | undefined,
|
|
362
362
|
> extends BaseCallbackEvent<Schema, Q, UseDates> {
|
|
363
363
|
type: CallbackEventType.SyncTransaction;
|
|
364
364
|
added: QueryEntities<Schema, Q, UseDates>;
|
|
@@ -373,7 +373,7 @@ export interface SyncTransaction<
|
|
|
373
373
|
export interface LoadFromStorage<
|
|
374
374
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
375
375
|
Q extends ValidQuery<Q, Schema>,
|
|
376
|
-
UseDates extends boolean,
|
|
376
|
+
UseDates extends boolean | undefined,
|
|
377
377
|
> extends BaseCallbackEvent<Schema, Q, UseDates> {
|
|
378
378
|
type: CallbackEventType.LoadFromStorage;
|
|
379
379
|
}
|
|
@@ -381,7 +381,7 @@ export interface LoadFromStorage<
|
|
|
381
381
|
export interface SetupError<
|
|
382
382
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
383
383
|
Q extends ValidQuery<Q, Schema>,
|
|
384
|
-
UseDates extends boolean,
|
|
384
|
+
UseDates extends boolean | undefined,
|
|
385
385
|
> extends BaseCallbackEvent<Schema, Q, UseDates> {
|
|
386
386
|
type: CallbackEventType.Error;
|
|
387
387
|
error: { message: string; hint?: any; type: string; status: number };
|
|
@@ -390,7 +390,7 @@ export interface SetupError<
|
|
|
390
390
|
export type CallbackEvent<
|
|
391
391
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
392
392
|
Q extends ValidQuery<Q, Schema>,
|
|
393
|
-
UseDates extends boolean,
|
|
393
|
+
UseDates extends boolean | undefined,
|
|
394
394
|
> =
|
|
395
395
|
| InitialSyncBatch<Schema, Q, UseDates>
|
|
396
396
|
| InitialSyncComplete<Schema, Q, UseDates>
|
|
@@ -401,7 +401,7 @@ export type CallbackEvent<
|
|
|
401
401
|
export type SyncTableCallback<
|
|
402
402
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
403
403
|
Q extends ValidQuery<Q, Schema>,
|
|
404
|
-
UseDates extends boolean,
|
|
404
|
+
UseDates extends boolean | undefined,
|
|
405
405
|
> = (event: CallbackEvent<Schema, Q, UseDates>) => void;
|
|
406
406
|
|
|
407
407
|
export class SyncTable {
|
package/src/devtool.ts
CHANGED
|
@@ -91,7 +91,7 @@ function createIframe(src: string) {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
function createToggler(
|
|
94
|
-
config:
|
|
94
|
+
config: StrictDevtoolConfig,
|
|
95
95
|
onClick: (this: HTMLButtonElement, ev: MouseEvent) => any,
|
|
96
96
|
) {
|
|
97
97
|
const logoSVG = `
|
|
@@ -150,7 +150,7 @@ function cssPositionForIframeContainer(position: DevtoolPosition) {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
function createIframeContainer(config:
|
|
153
|
+
function createIframeContainer(config: StrictDevtoolConfig) {
|
|
154
154
|
const element = document.createElement('div');
|
|
155
155
|
Object.assign(element.style, {
|
|
156
156
|
position: 'fixed',
|
package/src/helperTypes.ts
CHANGED
|
@@ -43,7 +43,9 @@ export type InstantQuery<DB extends IInstantDatabase<any>> =
|
|
|
43
43
|
*/
|
|
44
44
|
export type InstantQueryResult<DB extends IInstantDatabase<any>, Q> =
|
|
45
45
|
DB extends IInstantDatabase<infer Schema>
|
|
46
|
-
?
|
|
46
|
+
? Q extends InstaQLParams<Schema> | undefined
|
|
47
|
+
? InstaQLResult<Schema, Remove$<Q>>
|
|
48
|
+
: never
|
|
47
49
|
: never;
|
|
48
50
|
/**
|
|
49
51
|
* @deprecated
|
package/src/index.ts
CHANGED
|
@@ -148,7 +148,7 @@ export type Config = {
|
|
|
148
148
|
|
|
149
149
|
export type InstantConfig<
|
|
150
150
|
S extends InstantSchemaDef<any, any, any>,
|
|
151
|
-
UseDates extends boolean = false,
|
|
151
|
+
UseDates extends boolean | undefined = false,
|
|
152
152
|
> = {
|
|
153
153
|
appId: string;
|
|
154
154
|
schema?: S;
|
|
@@ -184,7 +184,7 @@ export type SubscribeTopic<PresenceShape, TopicsByKey> = <
|
|
|
184
184
|
|
|
185
185
|
export type GetPresence<PresenceShape> = <Keys extends keyof PresenceShape>(
|
|
186
186
|
opts: PresenceOpts<PresenceShape, Keys>,
|
|
187
|
-
) => PresenceResponse<PresenceShape, Keys
|
|
187
|
+
) => PresenceResponse<PresenceShape, Keys> | null;
|
|
188
188
|
|
|
189
189
|
export type SubscribePresence<PresenceShape> = <
|
|
190
190
|
Keys extends keyof PresenceShape,
|
|
@@ -212,7 +212,11 @@ type SubscriptionState<Q, Schema, WithCardinalityInference extends boolean> =
|
|
|
212
212
|
pageInfo: PageInfoResponse<Q>;
|
|
213
213
|
};
|
|
214
214
|
|
|
215
|
-
type InstaQLSubscriptionState<
|
|
215
|
+
type InstaQLSubscriptionState<
|
|
216
|
+
Schema,
|
|
217
|
+
Q,
|
|
218
|
+
UseDates extends boolean | undefined,
|
|
219
|
+
> =
|
|
216
220
|
| { error: { message: string }; data: undefined; pageInfo: undefined }
|
|
217
221
|
| {
|
|
218
222
|
error: undefined;
|
|
@@ -231,7 +235,7 @@ type LifecycleSubscriptionState<
|
|
|
231
235
|
type InstaQLLifecycleState<
|
|
232
236
|
Schema,
|
|
233
237
|
Q,
|
|
234
|
-
UseDates extends boolean = false,
|
|
238
|
+
UseDates extends boolean | undefined = false,
|
|
235
239
|
> = InstaQLSubscriptionState<Schema, Q, UseDates> & {
|
|
236
240
|
isLoading: boolean;
|
|
237
241
|
};
|
|
@@ -257,7 +261,7 @@ function initGlobalInstantCoreStore(): Record<string, any> {
|
|
|
257
261
|
return globalThis.__instantDbStore;
|
|
258
262
|
}
|
|
259
263
|
|
|
260
|
-
function reactorKey(config: InstantConfig<any, boolean>): string {
|
|
264
|
+
function reactorKey(config: InstantConfig<any, boolean | undefined>): string {
|
|
261
265
|
// @ts-expect-error
|
|
262
266
|
const adminToken = config.__adminToken;
|
|
263
267
|
return (
|
|
@@ -519,7 +523,7 @@ function coerceQuery(o: any) {
|
|
|
519
523
|
|
|
520
524
|
class InstantCoreDatabase<
|
|
521
525
|
Schema extends InstantSchemaDef<any, any, any>,
|
|
522
|
-
UseDates extends boolean = false,
|
|
526
|
+
UseDates extends boolean | undefined = false,
|
|
523
527
|
> implements IInstantDatabase<Schema>
|
|
524
528
|
{
|
|
525
529
|
public _reactor: Reactor<RoomsOf<Schema>>;
|
|
@@ -593,7 +597,7 @@ class InstantCoreDatabase<
|
|
|
593
597
|
*/
|
|
594
598
|
subscribeQuery<
|
|
595
599
|
Q extends ValidQuery<Q, Schema>,
|
|
596
|
-
UseDatesLocal extends boolean = UseDates,
|
|
600
|
+
UseDatesLocal extends boolean | undefined = UseDates,
|
|
597
601
|
>(
|
|
598
602
|
query: Q,
|
|
599
603
|
cb: (resp: InstaQLSubscriptionState<Schema, Q, UseDatesLocal>) => void,
|
|
@@ -756,8 +760,9 @@ function schemaHash(schema?: InstantSchemaDef<any, any, any>): string {
|
|
|
756
760
|
return '0';
|
|
757
761
|
}
|
|
758
762
|
|
|
759
|
-
|
|
760
|
-
|
|
763
|
+
const fromStore = schemaHashStore.get(schema);
|
|
764
|
+
if (fromStore) {
|
|
765
|
+
return fromStore;
|
|
761
766
|
}
|
|
762
767
|
const hash = weakHash(schema);
|
|
763
768
|
schemaHashStore.set(schema, hash);
|
|
@@ -795,7 +800,7 @@ function schemaChanged(
|
|
|
795
800
|
*/
|
|
796
801
|
function init<
|
|
797
802
|
Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema,
|
|
798
|
-
UseDates extends boolean = false,
|
|
803
|
+
UseDates extends boolean | undefined = false,
|
|
799
804
|
>(
|
|
800
805
|
config: InstantConfig<Schema, UseDates>,
|
|
801
806
|
Storage?: any,
|
|
@@ -836,7 +841,10 @@ function init<
|
|
|
836
841
|
return client;
|
|
837
842
|
}
|
|
838
843
|
|
|
839
|
-
function handleDevtool(
|
|
844
|
+
function handleDevtool(
|
|
845
|
+
appId: string,
|
|
846
|
+
devtool: boolean | DevtoolConfig | null | undefined,
|
|
847
|
+
) {
|
|
840
848
|
if (
|
|
841
849
|
typeof window === 'undefined' ||
|
|
842
850
|
typeof window.location === 'undefined' ||
|
package/src/queryTypes.ts
CHANGED
|
@@ -198,9 +198,11 @@ type QueryResponse<
|
|
|
198
198
|
? InstaQLQueryResult<E, Q, WithCardinalityInference, UseDates>
|
|
199
199
|
: ResponseOf<{ [K in keyof Q]: Remove$<Q[K]> }, Schema>;
|
|
200
200
|
|
|
201
|
-
type InstaQLResponse<Schema, Q, UseDates extends boolean = false> =
|
|
201
|
+
type InstaQLResponse<Schema, Q, UseDates extends boolean | undefined = false> =
|
|
202
202
|
Schema extends IContainEntitiesAndLinks<any, any>
|
|
203
|
-
?
|
|
203
|
+
? Q extends InstaQLParams<Schema> | undefined
|
|
204
|
+
? InstaQLResult<Schema, Q, UseDates>
|
|
205
|
+
: never
|
|
204
206
|
: never;
|
|
205
207
|
|
|
206
208
|
type PageInfoResponse<T> = {
|
|
@@ -238,14 +240,28 @@ type Exactly<Parent, Child> = Parent & {
|
|
|
238
240
|
[K in keyof Child]: K extends keyof Parent ? Child[K] : never;
|
|
239
241
|
};
|
|
240
242
|
|
|
243
|
+
// SafeLookup<T, ['A', 'B', number]> is like doing
|
|
244
|
+
// T['A']['B'][number], but it will merge with undefined if any
|
|
245
|
+
// of the intermediates are undefined
|
|
246
|
+
type SafeLookup<T, K extends readonly PropertyKey[]> = K extends [
|
|
247
|
+
infer First,
|
|
248
|
+
...infer Rest extends readonly PropertyKey[],
|
|
249
|
+
]
|
|
250
|
+
? First extends keyof NonNullable<T>
|
|
251
|
+
?
|
|
252
|
+
| SafeLookup<NonNullable<T>[First], Rest>
|
|
253
|
+
| (T extends null | undefined ? undefined : never)
|
|
254
|
+
: undefined
|
|
255
|
+
: T;
|
|
256
|
+
|
|
241
257
|
// ==========
|
|
242
258
|
// InstaQL helpers
|
|
243
259
|
|
|
244
260
|
type InstaQLEntitySubqueryResult<
|
|
245
261
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
246
262
|
EntityName extends keyof Schema['entities'],
|
|
247
|
-
Query extends InstaQLEntitySubquery<Schema, EntityName> = {},
|
|
248
|
-
UseDates extends boolean = false,
|
|
263
|
+
Query extends InstaQLEntitySubquery<Schema, EntityName> | undefined = {},
|
|
264
|
+
UseDates extends boolean | undefined = false,
|
|
249
265
|
> = {
|
|
250
266
|
[QueryPropName in keyof Query]: Schema['entities'][EntityName]['links'][QueryPropName] extends LinkAttrDef<
|
|
251
267
|
infer Cardinality,
|
|
@@ -257,16 +273,16 @@ type InstaQLEntitySubqueryResult<
|
|
|
257
273
|
| InstaQLEntity<
|
|
258
274
|
Schema,
|
|
259
275
|
LinkedEntityName,
|
|
260
|
-
Remove$NonRecursive<Query[QueryPropName]
|
|
261
|
-
Query[QueryPropName
|
|
276
|
+
Remove$NonRecursive<SafeLookup<Query, [QueryPropName]>>,
|
|
277
|
+
SafeLookup<Query, [QueryPropName, '$', 'fields']>,
|
|
262
278
|
UseDates
|
|
263
279
|
>
|
|
264
280
|
| undefined
|
|
265
281
|
: InstaQLEntity<
|
|
266
282
|
Schema,
|
|
267
283
|
LinkedEntityName,
|
|
268
|
-
Remove$NonRecursive<Query[QueryPropName]
|
|
269
|
-
Query[QueryPropName
|
|
284
|
+
Remove$NonRecursive<SafeLookup<Query, [QueryPropName]>>,
|
|
285
|
+
SafeLookup<Query, [QueryPropName, '$', 'fields']>,
|
|
270
286
|
UseDates
|
|
271
287
|
>[]
|
|
272
288
|
: never
|
|
@@ -326,19 +342,24 @@ type InstaQLFields<
|
|
|
326
342
|
K extends keyof S['entities'],
|
|
327
343
|
> = (Extract<keyof ResolveEntityAttrs<S['entities'][K]>, string> | 'id')[];
|
|
328
344
|
|
|
345
|
+
type ComputeAttrs<
|
|
346
|
+
AllAttrs,
|
|
347
|
+
Fields extends readonly string[] | undefined,
|
|
348
|
+
> = Fields extends readonly string[]
|
|
349
|
+
? DistributePick<AllAttrs, Exclude<Fields[number], 'id'>>
|
|
350
|
+
: AllAttrs;
|
|
351
|
+
|
|
329
352
|
type InstaQLEntity<
|
|
330
353
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
331
354
|
EntityName extends keyof Schema['entities'],
|
|
332
|
-
Subquery extends InstaQLEntitySubquery<Schema, EntityName> = {},
|
|
355
|
+
Subquery extends InstaQLEntitySubquery<Schema, EntityName> | undefined = {},
|
|
333
356
|
Fields extends InstaQLFields<Schema, EntityName> | undefined = undefined,
|
|
334
|
-
UseDates extends boolean = false,
|
|
357
|
+
UseDates extends boolean | undefined = false,
|
|
335
358
|
> = Expand<
|
|
336
|
-
{ id: string } &
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
Exclude<Fields[number], 'id'>
|
|
341
|
-
>) &
|
|
359
|
+
{ id: string } & ComputeAttrs<
|
|
360
|
+
ResolveEntityAttrs<Schema['entities'][EntityName], UseDates>,
|
|
361
|
+
Fields
|
|
362
|
+
> &
|
|
342
363
|
InstaQLEntitySubqueryResult<Schema, EntityName, Subquery, UseDates>
|
|
343
364
|
>;
|
|
344
365
|
|
|
@@ -378,15 +399,15 @@ type InstaQLQueryResult<
|
|
|
378
399
|
|
|
379
400
|
type InstaQLResult<
|
|
380
401
|
Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
|
|
381
|
-
Query extends InstaQLParams<Schema
|
|
382
|
-
UseDates extends boolean = false,
|
|
402
|
+
Query extends InstaQLParams<Schema> | undefined,
|
|
403
|
+
UseDates extends boolean | undefined = false,
|
|
383
404
|
> = Expand<{
|
|
384
405
|
[QueryPropName in keyof Query]: QueryPropName extends keyof Schema['entities']
|
|
385
406
|
? InstaQLEntity<
|
|
386
407
|
Schema,
|
|
387
408
|
QueryPropName,
|
|
388
|
-
Remove$NonRecursive<Query[QueryPropName]
|
|
389
|
-
Query[QueryPropName
|
|
409
|
+
Remove$NonRecursive<SafeLookup<Query, [QueryPropName]>>,
|
|
410
|
+
SafeLookup<Query, [QueryPropName, '$', 'fields']>,
|
|
390
411
|
UseDates
|
|
391
412
|
>[]
|
|
392
413
|
: never;
|
|
@@ -601,15 +622,22 @@ type ValidWhereObject<
|
|
|
601
622
|
Schema['entities'][EntityName]['attrs'][K]
|
|
602
623
|
>;
|
|
603
624
|
} & {
|
|
604
|
-
and?: Input extends {
|
|
625
|
+
and?: Input extends {
|
|
626
|
+
and: Array<infer Item extends { [key: string]: any } | undefined>;
|
|
627
|
+
}
|
|
605
628
|
? ValidWhereObject<NoDistribute<Item>, Schema, EntityName>[]
|
|
606
629
|
: never;
|
|
607
|
-
or?: Input extends {
|
|
630
|
+
or?: Input extends {
|
|
631
|
+
or: Array<infer Item extends { [key: string]: any } | undefined>;
|
|
632
|
+
}
|
|
608
633
|
? ValidWhereObject<NoDistribute<Item>, Schema, EntityName>[]
|
|
609
634
|
: never;
|
|
610
635
|
} & {
|
|
611
636
|
// Special case for id
|
|
612
|
-
id?: ValidWhereValue<
|
|
637
|
+
id?: ValidWhereValue<
|
|
638
|
+
SafeLookup<Input, ['id']>,
|
|
639
|
+
DataAttrDef<string, false, false>
|
|
640
|
+
>;
|
|
613
641
|
}
|
|
614
642
|
: never;
|
|
615
643
|
|
|
@@ -640,7 +668,7 @@ type ExtractAttrFromDotPath<
|
|
|
640
668
|
: never;
|
|
641
669
|
|
|
642
670
|
type ValidQuery<
|
|
643
|
-
Q extends
|
|
671
|
+
Q extends Record<string, any>,
|
|
644
672
|
S extends IContainEntitiesAndLinks<any, any>,
|
|
645
673
|
> = S extends InstantUnknownSchemaDef
|
|
646
674
|
? InstaQLParams<S>
|
package/src/queryValidation.ts
CHANGED
|
@@ -364,7 +364,7 @@ const validateWhereClause = (
|
|
|
364
364
|
const validateDollarObject = (
|
|
365
365
|
dollarObj: Record<string, unknown>,
|
|
366
366
|
entityName: string,
|
|
367
|
-
schema?: IContainEntitiesAndLinks<any, any
|
|
367
|
+
schema?: IContainEntitiesAndLinks<any, any> | null | undefined,
|
|
368
368
|
path?: string,
|
|
369
369
|
depth: number = 0,
|
|
370
370
|
): void => {
|
|
@@ -414,7 +414,7 @@ const validateDollarObject = (
|
|
|
414
414
|
const validateEntityInQuery = (
|
|
415
415
|
queryPart: Record<string, unknown>,
|
|
416
416
|
entityName: string,
|
|
417
|
-
schema: IContainEntitiesAndLinks<any, any
|
|
417
|
+
schema: IContainEntitiesAndLinks<any, any> | null | undefined,
|
|
418
418
|
path: string,
|
|
419
419
|
depth: number = 0,
|
|
420
420
|
): void => {
|
package/src/schemaTypes.ts
CHANGED
|
@@ -302,7 +302,10 @@ type OptionalKeys<Attrs extends AttrsDefs> = {
|
|
|
302
302
|
* - Required keys => `key: ValueType`
|
|
303
303
|
* - Optional keys => `key?: ValueType`
|
|
304
304
|
*/
|
|
305
|
-
type MappedAttrs<
|
|
305
|
+
type MappedAttrs<
|
|
306
|
+
Attrs extends AttrsDefs,
|
|
307
|
+
UseDates extends boolean | undefined,
|
|
308
|
+
> = {
|
|
306
309
|
[K in RequiredKeys<Attrs>]: Attrs[K] extends DataAttrDef<infer V, any, any>
|
|
307
310
|
? V extends Date
|
|
308
311
|
? UseDates extends true
|
|
@@ -322,7 +325,7 @@ type MappedAttrs<Attrs extends AttrsDefs, UseDates extends boolean> = {
|
|
|
322
325
|
|
|
323
326
|
export type ResolveEntityAttrs<
|
|
324
327
|
EDef extends EntityDef<any, any, any>,
|
|
325
|
-
UseDates extends boolean = false,
|
|
328
|
+
UseDates extends boolean | undefined = false,
|
|
326
329
|
ResolvedAttrs = MappedAttrs<EDef['attrs'], UseDates>,
|
|
327
330
|
> =
|
|
328
331
|
EDef extends EntityDef<any, any, infer AsType>
|