@trust0/ridb-core 1.7.19 → 1.7.21

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.
@@ -234,10 +234,14 @@ type ExtractType<T extends string> =
234
234
  T extends "boolean" ? boolean :
235
235
  T extends "object" ? object :
236
236
  T extends "array" ? any[] :
237
- never;
237
+ undefined;
238
238
 
239
- type IsOptional<T> = T extends { required: false } ? true :
240
- T extends { default: any } ? true : false;
239
+ type IsOptional<T> =
240
+ T extends { required: true }
241
+ ? T extends { default: any }
242
+ ? true
243
+ : false
244
+ : true;
241
245
 
242
246
  /**
243
247
  * Doc is a utility type that transforms a schema type into a document type where each property is mapped to its extracted type.
@@ -248,16 +252,34 @@ type IsOptional<T> = T extends { required: false } ? true :
248
252
  */
249
253
  type Doc<T extends SchemaType> = {
250
254
  [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? K : never]?:
251
- ExtractType<T["properties"][K]["type"]>
255
+ ExtractType<T['properties'][K]['type']>
252
256
  } & {
253
- [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends false ? K : never]:
254
- ExtractType<T["properties"][K]["type"]>
257
+ [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? never : K]:
258
+ ExtractType<T['properties'][K]['type']>
255
259
  } & {
256
260
  __version?: number;
257
261
  createdAt?: number;
258
262
  updatedAt?: number;
259
263
  };
260
264
 
265
+ /**
266
+ * CreateDoc is a utility type for document creation that properly handles required vs optional fields
267
+ * during the creation process. Fields with default values or required: false become optional.
268
+ *
269
+ * @template T - A schema type with a 'properties' field where each property's type is represented as a string.
270
+ */
271
+ type CreateDoc<T extends SchemaType> = {
272
+ [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? K : never]?:
273
+ ExtractType<T['properties'][K]['type']>
274
+ } & {
275
+ [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? never : K]:
276
+ ExtractType<T['properties'][K]['type']>
277
+ } & {
278
+ __version?: number;
279
+ createdAt?: number;
280
+ updatedAt?: number;
281
+ };
282
+
261
283
  type QueryOptions = {
262
284
  limit?: number;
263
285
  offset?: number;
@@ -301,7 +323,7 @@ declare class Collection<T extends SchemaType> {
301
323
  * @param document - The document to create.
302
324
  * @returns A promise that resolves to the created document.
303
325
  */
304
- create(document: Doc<T>): Promise<Doc<T>>;
326
+ create(document: CreateDoc<T>): Promise<Doc<T>>;
305
327
  /**
306
328
  * Deletes a document in the collection by its ID.
307
329
  *
@@ -1003,4 +1025,4 @@ declare function initSync(module: SyncInitInput): InitOutput;
1003
1025
  */
1004
1026
  declare function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
1005
1027
 
1006
- export { type AnyVersionGreaterThan1, BasePlugin, BaseStorage, type BaseStorageOptions, Collection, CoreStorage, type CreateStorage, Database, type Doc, type EnumerateFrom1To, type EnumerateUpTo, Errors, type ExtractType, InMemory, type InOperator, IndexDB, type InitInput, type InitOutput, type InternalsRecord, type IsOptional, type IsVersionGreaterThan0, type LogicalOperators, type MigrationFunction, type MigrationPathsForSchema, type MigrationPathsForSchemas, type MigrationsParameter, type NInOperator, OpType, type Operation, type OperatorOrType, type Operators, Property, Query, type QueryOptions, type QueryType, RIDBError, type RIDBModule, Schema, type SchemaType, type SchemaTypeRecord, StorageInternal, type SyncInitInput, WasmBindgenTestContext, __wbgtest_console_debug, __wbgtest_console_error, __wbgtest_console_info, __wbgtest_console_log, __wbgtest_console_warn, __wbg_init as default, initSync, is_debug_mode, main_js };
1028
+ export { type AnyVersionGreaterThan1, BasePlugin, BaseStorage, type BaseStorageOptions, Collection, CoreStorage, type CreateDoc, type CreateStorage, Database, type Doc, type EnumerateFrom1To, type EnumerateUpTo, Errors, type ExtractType, InMemory, type InOperator, IndexDB, type InitInput, type InitOutput, type InternalsRecord, type IsOptional, type IsVersionGreaterThan0, type LogicalOperators, type MigrationFunction, type MigrationPathsForSchema, type MigrationPathsForSchemas, type MigrationsParameter, type NInOperator, OpType, type Operation, type OperatorOrType, type Operators, Property, Query, type QueryOptions, type QueryType, RIDBError, type RIDBModule, Schema, type SchemaType, type SchemaTypeRecord, StorageInternal, type SyncInitInput, WasmBindgenTestContext, __wbgtest_console_debug, __wbgtest_console_error, __wbgtest_console_info, __wbgtest_console_log, __wbgtest_console_warn, __wbg_init as default, initSync, is_debug_mode, main_js };