@instantdb/core 0.22.72 → 0.22.73-experimental.fix-use-dates.19693183377.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instantdb/core",
3
- "version": "0.22.72",
3
+ "version": "0.22.73-experimental.fix-use-dates.19693183377.1",
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.72"
56
+ "@instantdb/version": "0.22.73-experimental.fix-use-dates.19693183377.1"
57
57
  },
58
58
  "scripts": {
59
59
  "test": "vitest",
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 | undefined,
312
+ UseDates extends boolean,
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 | undefined,
322
+ UseDates extends boolean,
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 | undefined,
335
+ UseDates extends boolean,
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 | undefined,
344
+ UseDates extends boolean,
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 | undefined,
353
+ UseDates extends boolean,
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 | undefined,
361
+ UseDates extends boolean,
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 | undefined,
376
+ UseDates extends boolean,
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 | undefined,
384
+ UseDates extends boolean,
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 | undefined,
393
+ UseDates extends boolean,
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 | undefined,
404
+ UseDates extends boolean,
405
405
  > = (event: CallbackEvent<Schema, Q, UseDates>) => void;
406
406
 
407
407
  export class SyncTable {
package/src/index.ts CHANGED
@@ -142,13 +142,13 @@ export type Config = {
142
142
  devtool?: boolean | DevtoolConfig;
143
143
  verbose?: boolean;
144
144
  queryCacheLimit?: number;
145
- useDateObjects?: boolean;
145
+ useDateObjects: boolean;
146
146
  disableValidation?: boolean;
147
147
  };
148
148
 
149
149
  export type InstantConfig<
150
150
  S extends InstantSchemaDef<any, any, any>,
151
- UseDates extends boolean | undefined = false,
151
+ UseDates extends boolean = false,
152
152
  > = {
153
153
  appId: string;
154
154
  schema?: S;
@@ -157,7 +157,7 @@ export type InstantConfig<
157
157
  devtool?: boolean | DevtoolConfig;
158
158
  verbose?: boolean;
159
159
  queryCacheLimit?: number;
160
- useDateObjects?: UseDates;
160
+ useDateObjects: UseDates;
161
161
  disableValidation?: boolean;
162
162
  };
163
163
 
@@ -212,11 +212,7 @@ type SubscriptionState<Q, Schema, WithCardinalityInference extends boolean> =
212
212
  pageInfo: PageInfoResponse<Q>;
213
213
  };
214
214
 
215
- type InstaQLSubscriptionState<
216
- Schema,
217
- Q,
218
- UseDates extends boolean | undefined,
219
- > =
215
+ type InstaQLSubscriptionState<Schema, Q, UseDates extends boolean> =
220
216
  | { error: { message: string }; data: undefined; pageInfo: undefined }
221
217
  | {
222
218
  error: undefined;
@@ -235,7 +231,7 @@ type LifecycleSubscriptionState<
235
231
  type InstaQLLifecycleState<
236
232
  Schema,
237
233
  Q,
238
- UseDates extends boolean | undefined = false,
234
+ UseDates extends boolean = false,
239
235
  > = InstaQLSubscriptionState<Schema, Q, UseDates> & {
240
236
  isLoading: boolean;
241
237
  };
@@ -261,7 +257,7 @@ function initGlobalInstantCoreStore(): Record<string, any> {
261
257
  return globalThis.__instantDbStore;
262
258
  }
263
259
 
264
- function reactorKey(config: InstantConfig<any, boolean | undefined>): string {
260
+ function reactorKey(config: InstantConfig<any, boolean>): string {
265
261
  // @ts-expect-error
266
262
  const adminToken = config.__adminToken;
267
263
  return (
@@ -523,7 +519,7 @@ function coerceQuery(o: any) {
523
519
 
524
520
  class InstantCoreDatabase<
525
521
  Schema extends InstantSchemaDef<any, any, any>,
526
- UseDates extends boolean | undefined = false,
522
+ UseDates extends boolean = false,
527
523
  > implements IInstantDatabase<Schema>
528
524
  {
529
525
  public _reactor: Reactor<RoomsOf<Schema>>;
@@ -597,7 +593,7 @@ class InstantCoreDatabase<
597
593
  */
598
594
  subscribeQuery<
599
595
  Q extends ValidQuery<Q, Schema>,
600
- UseDatesLocal extends boolean | undefined = UseDates,
596
+ UseDatesLocal extends boolean = UseDates,
601
597
  >(
602
598
  query: Q,
603
599
  cb: (resp: InstaQLSubscriptionState<Schema, Q, UseDatesLocal>) => void,
@@ -800,21 +796,27 @@ function schemaChanged(
800
796
  */
801
797
  function init<
802
798
  Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema,
803
- UseDates extends boolean | undefined = false,
799
+ UseDates extends boolean = false,
804
800
  >(
805
- config: InstantConfig<Schema, UseDates>,
801
+ config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {
802
+ useDateObjects?: UseDates;
803
+ },
806
804
  Storage?: any,
807
805
  NetworkListener?: any,
808
806
  versions?: { [key: string]: string },
809
807
  EventSourceImpl?: any,
810
808
  ): InstantCoreDatabase<Schema, UseDates> {
809
+ const configStrict = {
810
+ ...config,
811
+ useDateObjects: (config.useDateObjects ?? false) as UseDates,
812
+ };
811
813
  const existingClient = globalInstantCoreStore[
812
- reactorKey(config)
814
+ reactorKey(configStrict)
813
815
  ] as InstantCoreDatabase<any, Config['useDateObjects']>;
814
816
 
815
817
  if (existingClient) {
816
- if (schemaChanged(existingClient, config.schema)) {
817
- existingClient._reactor.updateSchema(config.schema);
818
+ if (schemaChanged(existingClient, configStrict.schema)) {
819
+ existingClient._reactor.updateSchema(configStrict.schema);
818
820
  }
819
821
  return existingClient;
820
822
  }
@@ -822,8 +824,8 @@ function init<
822
824
  const reactor = new Reactor<RoomsOf<Schema>>(
823
825
  {
824
826
  ...defaultConfig,
825
- ...config,
826
- cardinalityInference: config.schema ? true : false,
827
+ ...configStrict,
828
+ cardinalityInference: configStrict.schema ? true : false,
827
829
  },
828
830
  Storage || IndexedDBStorage,
829
831
  NetworkListener || WindowNetworkListener,
@@ -834,9 +836,9 @@ function init<
834
836
  const client = new InstantCoreDatabase<any, Config['useDateObjects']>(
835
837
  reactor,
836
838
  );
837
- globalInstantCoreStore[reactorKey(config)] = client;
839
+ globalInstantCoreStore[reactorKey(configStrict)] = client;
838
840
 
839
- handleDevtool(config.appId, config.devtool);
841
+ handleDevtool(configStrict.appId, configStrict.devtool);
840
842
 
841
843
  return client;
842
844
  }
package/src/queryTypes.ts CHANGED
@@ -198,7 +198,7 @@ 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 | undefined = false> =
201
+ type InstaQLResponse<Schema, Q, UseDates extends boolean = false> =
202
202
  Schema extends IContainEntitiesAndLinks<any, any>
203
203
  ? Q extends InstaQLParams<Schema> | undefined
204
204
  ? InstaQLResult<Schema, Q, UseDates>
@@ -261,7 +261,7 @@ type InstaQLEntitySubqueryResult<
261
261
  Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
262
262
  EntityName extends keyof Schema['entities'],
263
263
  Query extends InstaQLEntitySubquery<Schema, EntityName> | undefined = {},
264
- UseDates extends boolean | undefined = false,
264
+ UseDates extends boolean = false,
265
265
  > = {
266
266
  [QueryPropName in keyof Query]: Schema['entities'][EntityName]['links'][QueryPropName] extends LinkAttrDef<
267
267
  infer Cardinality,
@@ -354,7 +354,7 @@ type InstaQLEntity<
354
354
  EntityName extends keyof Schema['entities'],
355
355
  Subquery extends InstaQLEntitySubquery<Schema, EntityName> | undefined = {},
356
356
  Fields extends InstaQLFields<Schema, EntityName> | undefined = undefined,
357
- UseDates extends boolean | undefined = false,
357
+ UseDates extends boolean = false,
358
358
  > = Expand<
359
359
  { id: string } & ComputeAttrs<
360
360
  ResolveEntityAttrs<Schema['entities'][EntityName], UseDates>,
@@ -400,7 +400,7 @@ type InstaQLQueryResult<
400
400
  type InstaQLResult<
401
401
  Schema extends IContainEntitiesAndLinks<EntitiesDef, any>,
402
402
  Query extends InstaQLParams<Schema> | undefined,
403
- UseDates extends boolean | undefined = false,
403
+ UseDates extends boolean = false,
404
404
  > = Expand<{
405
405
  [QueryPropName in keyof Query]: QueryPropName extends keyof Schema['entities']
406
406
  ? InstaQLEntity<
@@ -304,7 +304,7 @@ type OptionalKeys<Attrs extends AttrsDefs> = {
304
304
  */
305
305
  type MappedAttrs<
306
306
  Attrs extends AttrsDefs,
307
- UseDates extends boolean | undefined,
307
+ UseDates extends boolean,
308
308
  > = {
309
309
  [K in RequiredKeys<Attrs>]: Attrs[K] extends DataAttrDef<infer V, any, any>
310
310
  ? V extends Date
@@ -325,7 +325,7 @@ type MappedAttrs<
325
325
 
326
326
  export type ResolveEntityAttrs<
327
327
  EDef extends EntityDef<any, any, any>,
328
- UseDates extends boolean | undefined = false,
328
+ UseDates extends boolean = false,
329
329
  ResolvedAttrs = MappedAttrs<EDef['attrs'], UseDates>,
330
330
  > =
331
331
  EDef extends EntityDef<any, any, infer AsType>