@trust0/ridb-core 1.7.20 → 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
239
  type IsOptional<T> =
240
- T extends { required: false } | { required: true, default: never } ? true : false;
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,13 +252,29 @@ type IsOptional<T> =
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']> extends undefined ? `${T['properties'][K]['type']}` : ExtractType<T['properties'][K]['type']>
252
-
255
+ ExtractType<T['properties'][K]['type']>
256
+ } & {
257
+ [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? never : K]:
258
+ ExtractType<T['properties'][K]['type']>
253
259
  } & {
254
- [K in keyof T["properties"]]:
255
- ExtractType<T['properties'][K]['type']> extends undefined ? `${T['properties'][K]['type']}` : ExtractType<T['properties'][K]['type']>
260
+ __version?: number;
261
+ createdAt?: number;
262
+ updatedAt?: number;
263
+ };
256
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']>
257
274
  } & {
275
+ [K in keyof T["properties"] as IsOptional<T["properties"][K]> extends true ? never : K]:
276
+ ExtractType<T['properties'][K]['type']>
277
+ } & {
258
278
  __version?: number;
259
279
  createdAt?: number;
260
280
  updatedAt?: number;
@@ -303,7 +323,7 @@ declare class Collection<T extends SchemaType> {
303
323
  * @param document - The document to create.
304
324
  * @returns A promise that resolves to the created document.
305
325
  */
306
- create(document: Partial<Doc<T>>): Promise<Doc<T>>;
326
+ create(document: CreateDoc<T>): Promise<Doc<T>>;
307
327
  /**
308
328
  * Deletes a document in the collection by its ID.
309
329
  *
@@ -1005,4 +1025,4 @@ declare function initSync(module: SyncInitInput): InitOutput;
1005
1025
  */
1006
1026
  declare function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
1007
1027
 
1008
- 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 };