@routier/core 0.0.6 → 0.0.7

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.
Files changed (54) hide show
  1. package/dist/capabilities/Capability.d.ts +6 -16
  2. package/dist/capabilities/PerformanceCapability.d.ts +4 -6
  3. package/dist/capabilities/TracingCapability.d.ts +3 -6
  4. package/dist/capabilities/index.js +399 -343
  5. package/dist/capabilities/index.js.map +1 -1
  6. package/dist/capabilities/types.d.ts +10 -19
  7. package/dist/codegen/blocks.d.ts +8 -0
  8. package/dist/codegen/handlers/CompareIdsHandlerBuilder.d.ts +4 -0
  9. package/dist/codegen/handlers/compare/CompareArrayHandler.d.ts +6 -0
  10. package/dist/codegen/handlers/compare/CompareDateHandler.d.ts +6 -0
  11. package/dist/codegen/handlers/compareIds/CompareIdsKeyHandler.d.ts +6 -0
  12. package/dist/codegen/handlers/index.d.ts +1 -0
  13. package/dist/codegen/handlers/serialize/SerializeDateHandler.d.ts +2 -1
  14. package/dist/codegen/handlers/serialize/SerializeFunctionHandler.d.ts +6 -0
  15. package/dist/codegen/index.js +39 -0
  16. package/dist/codegen/index.js.map +1 -1
  17. package/dist/collections/index.js.map +1 -1
  18. package/dist/expressions/index.js +108 -19
  19. package/dist/expressions/index.js.map +1 -1
  20. package/dist/index.js +1105 -496
  21. package/dist/index.js.map +1 -1
  22. package/dist/pipeline/TrampolinePipeline.d.ts +1 -0
  23. package/dist/pipeline/index.js +71 -47
  24. package/dist/pipeline/index.js.map +1 -1
  25. package/dist/plugins/EphemeralDataPlugin.d.ts +2 -2
  26. package/dist/plugins/index.js +251 -61
  27. package/dist/plugins/index.js.map +1 -1
  28. package/dist/plugins/query/types.d.ts +5 -0
  29. package/dist/plugins/replication/OptimisticReplicationDbPlugin.d.ts +2 -1
  30. package/dist/plugins/replication/ReplicationDbPlugin.d.ts +2 -1
  31. package/dist/plugins/translators/DataTranslator.d.ts +3 -1
  32. package/dist/plugins/translators/JsonTranslator.d.ts +1 -0
  33. package/dist/plugins/translators/SqlTranslator.d.ts +1 -0
  34. package/dist/plugins/translators/TranslatedArrayValue.d.ts +6 -0
  35. package/dist/plugins/translators/TranslatedGroupValue.d.ts +6 -0
  36. package/dist/plugins/translators/TranslatedSingleValue.d.ts +6 -0
  37. package/dist/plugins/translators/index.d.ts +4 -0
  38. package/dist/plugins/translators/types.d.ts +10 -0
  39. package/dist/plugins/types.d.ts +2 -1
  40. package/dist/schema/PropertyInfo.d.ts +6 -1
  41. package/dist/schema/SchemaDefinition.d.ts +1 -1
  42. package/dist/schema/communication/broadcast.d.ts +3 -3
  43. package/dist/schema/index.js +504 -73
  44. package/dist/schema/index.js.map +1 -1
  45. package/dist/schema/property/modifiers/SchemaTracked.d.ts +3 -1
  46. package/dist/schema/table/SchemaComputed.d.ts +1 -1
  47. package/dist/schema/testSchemas.test.d.ts +60 -36
  48. package/dist/schema/types.d.ts +16 -1
  49. package/dist/utilities/index.js +145 -2
  50. package/dist/utilities/index.js.map +1 -1
  51. package/dist/utilities/strings.d.ts +34 -0
  52. package/dist/utilities/strings.test.d.ts +1 -0
  53. package/package.json +1 -1
  54. package/readme.md +1 -1
@@ -1,7 +1,9 @@
1
- import { SchemaModifiers } from "../../types";
1
+ import { IdType, SchemaModifiers } from "../../types";
2
2
  import { SchemaBase } from "../base/SchemaBase";
3
+ import { SchemaKey } from "./SchemaKey";
3
4
  export declare class SchemaTracked<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
4
5
  instance: T;
5
6
  private _schemaTracked;
6
7
  constructor(current: SchemaBase<T, TModifiers>);
8
+ key(): T extends IdType ? SchemaKey<T, TModifiers | "key"> : never;
7
9
  }
@@ -6,5 +6,5 @@ export declare class SchemaComputed<T extends any, I, TModifiers extends SchemaM
6
6
  type: SchemaTypes;
7
7
  private _schemaComputed;
8
8
  constructor(fn: T, injected: I, current?: SchemaBase<T, TModifiers>);
9
- tracked(): SchemaTracked<T, TModifiers>;
9
+ tracked(): SchemaTracked<T, Exclude<TModifiers, "unmapped">>;
10
10
  }
@@ -8,11 +8,11 @@ export declare const optionalObjectSchemaFactory: () => import("./types").Compil
8
8
  createdAt: import(".").SchemaDeserialize<Date, "default" | "deserialize">;
9
9
  }>;
10
10
  export declare const usersSchemaOneFactory: () => import("./types").CompiledSchema<{
11
- documentType: import(".").SchemaTracked<string, "unmapped">;
11
+ documentType: import(".").SchemaTracked<string, "computed">;
12
12
  } & {
13
13
  id: import(".").SchemaDefault<string, {
14
14
  uuid: () => string;
15
- }, "default" | "key">;
15
+ }, "key" | "default">;
16
16
  firstName: import(".").SchemaString<string, never>;
17
17
  lastName: import(".").SchemaString<string, never>;
18
18
  age: import(".").SchemaNumber<number, never>;
@@ -25,11 +25,11 @@ export declare const usersSchemaOneFactory: () => import("./types").CompiledSche
25
25
  }, never>;
26
26
  }>;
27
27
  export declare const usersSchemaTwoFactory: () => import("./types").CompiledSchema<{
28
- documentType: import(".").SchemaTracked<string, "unmapped">;
28
+ documentType: import(".").SchemaTracked<string, "computed">;
29
29
  } & {
30
30
  id: import(".").SchemaDefault<string, {
31
31
  uuid: () => string;
32
- }, "default" | "key">;
32
+ }, "key" | "default">;
33
33
  firstName: import(".").SchemaString<string, never>;
34
34
  lastName: import(".").SchemaString<string, never>;
35
35
  age: import(".").SchemaNumber<number, never>;
@@ -46,9 +46,9 @@ export declare const usersSchemaTwoFactory: () => import("./types").CompiledSche
46
46
  }, never>;
47
47
  }>;
48
48
  export declare const oneComputedPropertySchemaFactory: () => import("./types").CompiledSchema<{
49
- documentType: import(".").SchemaTracked<string, "unmapped">;
49
+ documentType: import(".").SchemaTracked<string, "computed">;
50
50
  } & {
51
- id: import(".").SchemaIdentity<string, "identity" | "key">;
51
+ id: import(".").SchemaIdentity<string, "key" | "identity">;
52
52
  title: import(".").SchemaString<string, never>;
53
53
  authorId: import(".").SchemaString<string, never>;
54
54
  content: import(".").SchemaString<string, never>;
@@ -69,7 +69,7 @@ export declare const oneSerializeDeserializeSchemaFactory: () => import("./types
69
69
  createdAt: import(".").SchemaDeserialize<Date, "deserialize">;
70
70
  }>;
71
71
  export declare const oneDefaultWithInjectionSchemaFactory: () => import("./types").CompiledSchema<{
72
- _id: import(".").SchemaIdentity<string, "identity" | "key">;
72
+ _id: import(".").SchemaIdentity<string, "key" | "identity">;
73
73
  _rev: import(".").SchemaIdentity<string, "identity" | "readonly">;
74
74
  name: import(".").SchemaDefault<string, {
75
75
  name: string;
@@ -80,13 +80,37 @@ export declare const oneDefaultWithInjectionSchemaFactory: () => import("./types
80
80
  description: import(".").SchemaOptional<string, "optional">;
81
81
  isOnline: import(".").SchemaBoolean<boolean, never>;
82
82
  }>;
83
+ export declare const remap: () => import("./types").CompiledSchema<{
84
+ id: import(".").SchemaIdentity<string, "key" | "identity" | "readonly">;
85
+ _rev: import(".").SchemaIdentity<string, "identity" | "readonly">;
86
+ name: import(".").SchemaDefault<string, {
87
+ name: string;
88
+ }, "default">;
89
+ location: import(".").SchemaOptional<string, "optional">;
90
+ startTime: import(".").SchemaDeserialize<Date, "deserialize" | "serialize">;
91
+ endTime: import(".").SchemaOptional<Date, "optional">;
92
+ description: import(".").SchemaOptional<string, "optional">;
93
+ isOnline: import(".").SchemaBoolean<boolean, never>;
94
+ }>;
95
+ export declare const computedId: () => import("./types").CompiledSchema<{
96
+ id: import(".").SchemaKey<string, "key" | "computed">;
97
+ } & {
98
+ name: import(".").SchemaDefault<string, {
99
+ name: string;
100
+ }, "default">;
101
+ location: import(".").SchemaOptional<string, "optional">;
102
+ startTime: import(".").SchemaDeserialize<Date, "deserialize" | "serialize">;
103
+ endTime: import(".").SchemaOptional<Date, "optional">;
104
+ description: import(".").SchemaOptional<string, "optional">;
105
+ isOnline: import(".").SchemaBoolean<boolean, never>;
106
+ }>;
83
107
  export declare const computedAndFunctionPropertiesSchemaFactory: () => import("./types").CompiledSchema<{
84
- hasCollectionName: import(".").SchemaTracked<boolean, "unmapped">;
108
+ hasCollectionName: import(".").SchemaTracked<boolean, "computed">;
85
109
  wasRestocked: import("./table").SchemaFunction<boolean, {
86
110
  isNullOrEmpty: (value: unknown) => boolean;
87
111
  }, "unmapped">;
88
112
  } & {
89
- sku: import(".").SchemaIdentity<string, "identity" | "key">;
113
+ sku: import(".").SchemaIdentity<string, "key" | "identity">;
90
114
  name: import(".").SchemaString<string, never>;
91
115
  quantity: import(".").SchemaNumber<number, never>;
92
116
  warehouseLocation: import(".").SchemaOptional<string, "optional">;
@@ -94,11 +118,11 @@ export declare const computedAndFunctionPropertiesSchemaFactory: () => import(".
94
118
  discontinued: import(".").SchemaBoolean<boolean, never>;
95
119
  }>;
96
120
  export declare const deeplyNestedSchemaFactory: () => import("./types").CompiledSchema<{
97
- documentType: import(".").SchemaTracked<string, "unmapped">;
121
+ documentType: import(".").SchemaTracked<string, "computed">;
98
122
  } & {
99
123
  id: import(".").SchemaDefault<string, {
100
124
  uuid: () => string;
101
- }, "default" | "key">;
125
+ }, "key" | "default">;
102
126
  firstName: import(".").SchemaString<string, never>;
103
127
  lastName: import(".").SchemaString<string, never>;
104
128
  age: import(".").SchemaNumber<number, never>;
@@ -115,11 +139,11 @@ export declare const deeplyNestedSchemaFactory: () => import("./types").Compiled
115
139
  }, never>;
116
140
  }>;
117
141
  export declare const complexOneSchemaFactory: () => import("./types").CompiledSchema<{
118
- documentType: import(".").SchemaTracked<string, "unmapped">;
142
+ documentType: import(".").SchemaTracked<string, "computed">;
119
143
  } & {
120
144
  id: import(".").SchemaDefault<string, {
121
145
  uuid: () => string;
122
- }, "default" | "key">;
146
+ }, "key" | "default">;
123
147
  firstName: import(".").SchemaString<string, never>;
124
148
  lastName: import(".").SchemaString<string, never>;
125
149
  age: import(".").SchemaNumber<number, never>;
@@ -132,16 +156,16 @@ export declare const complexOneSchemaFactory: () => import("./types").CompiledSc
132
156
  }, never>;
133
157
  }>;
134
158
  export declare const complexTwoSchemaFactory: () => import("./types").CompiledSchema<{
135
- documentType: import(".").SchemaTracked<string, "unmapped">;
159
+ documentType: import(".").SchemaTracked<string, "computed">;
136
160
  } & {
137
- fullName: import("./table").SchemaComputed<string, never, "unmapped">;
138
- age: import("./table").SchemaComputed<number, never, "unmapped">;
139
- formattedAddress: import("./table").SchemaComputed<string, never, "unmapped">;
140
- isActive: import("./table").SchemaComputed<boolean, never, "unmapped">;
161
+ fullName: import("./table").SchemaComputed<string, never, "unmapped" | "computed">;
162
+ age: import("./table").SchemaComputed<number, never, "unmapped" | "computed">;
163
+ formattedAddress: import("./table").SchemaComputed<string, never, "unmapped" | "computed">;
164
+ isActive: import("./table").SchemaComputed<boolean, never, "unmapped" | "computed">;
141
165
  getDisplayName: import("./table").SchemaFunction<(format: "short" | "full") => string, never, "unmapped">;
142
- documentType: import(".").SchemaTracked<string, "unmapped">;
166
+ documentType: import(".").SchemaTracked<string, "computed">;
143
167
  } & {
144
- _id: import(".").SchemaIdentity<string, "identity" | "key">;
168
+ _id: import(".").SchemaIdentity<string, "key" | "identity">;
145
169
  _rev: import(".").SchemaIdentity<string, "identity" | "readonly">;
146
170
  firstName: import(".").SchemaString<string, never>;
147
171
  lastName: import(".").SchemaString<string, never>;
@@ -163,11 +187,11 @@ export declare const complexTwoSchemaFactory: () => import("./types").CompiledSc
163
187
  createdAt: import(".").SchemaDefault<Date, never, "default">;
164
188
  }>;
165
189
  export declare const factories: ((() => import("./types").CompiledSchema<{
166
- documentType: import(".").SchemaTracked<string, "unmapped">;
190
+ documentType: import(".").SchemaTracked<string, "computed">;
167
191
  } & {
168
192
  id: import(".").SchemaDefault<string, {
169
193
  uuid: () => string;
170
- }, "default" | "key">;
194
+ }, "key" | "default">;
171
195
  firstName: import(".").SchemaString<string, never>;
172
196
  lastName: import(".").SchemaString<string, never>;
173
197
  age: import(".").SchemaNumber<number, never>;
@@ -179,9 +203,9 @@ export declare const factories: ((() => import("./types").CompiledSchema<{
179
203
  zip: import(".").SchemaString<string, never>;
180
204
  }, never>;
181
205
  }>) | (() => import("./types").CompiledSchema<{
182
- documentType: import(".").SchemaTracked<string, "unmapped">;
206
+ documentType: import(".").SchemaTracked<string, "computed">;
183
207
  } & {
184
- id: import(".").SchemaIdentity<string, "identity" | "key">;
208
+ id: import(".").SchemaIdentity<string, "key" | "identity">;
185
209
  title: import(".").SchemaString<string, never>;
186
210
  authorId: import(".").SchemaString<string, never>;
187
211
  content: import(".").SchemaString<string, never>;
@@ -194,7 +218,7 @@ export declare const factories: ((() => import("./types").CompiledSchema<{
194
218
  replies: import(".").SchemaDefault<number, never, "default">;
195
219
  createdAt: import(".").SchemaDeserialize<Date, "default" | "deserialize">;
196
220
  }>) | (() => import("./types").CompiledSchema<{
197
- _id: import(".").SchemaIdentity<string, "identity" | "key">;
221
+ _id: import(".").SchemaIdentity<string, "key" | "identity">;
198
222
  _rev: import(".").SchemaIdentity<string, "identity" | "readonly">;
199
223
  name: import(".").SchemaDefault<string, {
200
224
  name: string;
@@ -205,23 +229,23 @@ export declare const factories: ((() => import("./types").CompiledSchema<{
205
229
  description: import(".").SchemaOptional<string, "optional">;
206
230
  isOnline: import(".").SchemaBoolean<boolean, never>;
207
231
  }>) | (() => import("./types").CompiledSchema<{
208
- hasCollectionName: import(".").SchemaTracked<boolean, "unmapped">;
232
+ hasCollectionName: import(".").SchemaTracked<boolean, "computed">;
209
233
  wasRestocked: import("./table").SchemaFunction<boolean, {
210
234
  isNullOrEmpty: (value: unknown) => boolean;
211
235
  }, "unmapped">;
212
236
  } & {
213
- sku: import(".").SchemaIdentity<string, "identity" | "key">;
237
+ sku: import(".").SchemaIdentity<string, "key" | "identity">;
214
238
  name: import(".").SchemaString<string, never>;
215
239
  quantity: import(".").SchemaNumber<number, never>;
216
240
  warehouseLocation: import(".").SchemaOptional<string, "optional">;
217
241
  restockDate: import(".").SchemaOptional<Date, "optional">;
218
242
  discontinued: import(".").SchemaBoolean<boolean, never>;
219
243
  }>) | (() => import("./types").CompiledSchema<{
220
- documentType: import(".").SchemaTracked<string, "unmapped">;
244
+ documentType: import(".").SchemaTracked<string, "computed">;
221
245
  } & {
222
246
  id: import(".").SchemaDefault<string, {
223
247
  uuid: () => string;
224
- }, "default" | "key">;
248
+ }, "key" | "default">;
225
249
  firstName: import(".").SchemaString<string, never>;
226
250
  lastName: import(".").SchemaString<string, never>;
227
251
  age: import(".").SchemaNumber<number, never>;
@@ -237,16 +261,16 @@ export declare const factories: ((() => import("./types").CompiledSchema<{
237
261
  zip: import(".").SchemaString<string, never>;
238
262
  }, never>;
239
263
  }>) | (() => import("./types").CompiledSchema<{
240
- documentType: import(".").SchemaTracked<string, "unmapped">;
264
+ documentType: import(".").SchemaTracked<string, "computed">;
241
265
  } & {
242
- fullName: import("./table").SchemaComputed<string, never, "unmapped">;
243
- age: import("./table").SchemaComputed<number, never, "unmapped">;
244
- formattedAddress: import("./table").SchemaComputed<string, never, "unmapped">;
245
- isActive: import("./table").SchemaComputed<boolean, never, "unmapped">;
266
+ fullName: import("./table").SchemaComputed<string, never, "unmapped" | "computed">;
267
+ age: import("./table").SchemaComputed<number, never, "unmapped" | "computed">;
268
+ formattedAddress: import("./table").SchemaComputed<string, never, "unmapped" | "computed">;
269
+ isActive: import("./table").SchemaComputed<boolean, never, "unmapped" | "computed">;
246
270
  getDisplayName: import("./table").SchemaFunction<(format: "short" | "full") => string, never, "unmapped">;
247
- documentType: import(".").SchemaTracked<string, "unmapped">;
271
+ documentType: import(".").SchemaTracked<string, "computed">;
248
272
  } & {
249
- _id: import(".").SchemaIdentity<string, "identity" | "key">;
273
+ _id: import(".").SchemaIdentity<string, "key" | "identity">;
250
274
  _rev: import(".").SchemaIdentity<string, "identity" | "readonly">;
251
275
  firstName: import(".").SchemaString<string, never>;
252
276
  lastName: import(".").SchemaString<string, never>;
@@ -86,6 +86,15 @@ type Enrich<TEntity extends {}> = {
86
86
  (entity: InferType<TEntity>, changeTrackingType: ChangeTrackingType): InferType<TEntity>;
87
87
  (entity: InferCreateType<TEntity>, changeTrackingType: ChangeTrackingType): InferCreateType<TEntity>;
88
88
  };
89
+ export type Prepare<TEntity extends {}> = {
90
+ (entity: InferCreateType<TEntity>): InferCreateType<TEntity>;
91
+ (entity: InferType<TEntity>): InferType<TEntity>;
92
+ };
93
+ export type Preprocess<TEntity extends {}> = {
94
+ (entity: InferCreateType<TEntity>): InferType<TEntity>;
95
+ (entity: InferType<TEntity>): InferType<TEntity>;
96
+ };
97
+ export type CompiledSchemaCore<TEntity extends {}> = Omit<CompiledSchema<TEntity>, "createSubscription">;
89
98
  /**
90
99
  * Represents a fully compiled schema with all utilities and metadata for an entity type.
91
100
  */
@@ -101,7 +110,7 @@ export type CompiledSchema<TEntity extends {}> = {
101
110
  /** Removes unmapped or extraneous properties from the entity. */
102
111
  strip: (entity: InferType<TEntity>) => InferType<TEntity>;
103
112
  /** Prepares a new entity for creation, applying defaults and transformations. */
104
- prepare: (entity: InferCreateType<TEntity>) => InferCreateType<TEntity>;
113
+ prepare: Prepare<TEntity>;
105
114
  /** Merges the source entity into the destination entity. */
106
115
  merge: (destination: InferType<TEntity> | InferCreateType<TEntity>, source: InferType<TEntity>) => InferType<TEntity>;
107
116
  /** Indicates if the schema has identity properties. */
@@ -120,6 +129,10 @@ export type CompiledSchema<TEntity extends {}> = {
120
129
  compare: (a: InferType<TEntity>, fromDb: InferType<TEntity>) => boolean;
121
130
  /** Deserializes an entity from storage format. */
122
131
  deserialize: (entity: InferType<TEntity>) => InferType<TEntity>;
132
+ /** Combines serializing and preparing an entity for saving. */
133
+ preprocess: Preprocess<TEntity>;
134
+ /** Combines deserializing and enriching an entity for selection. */
135
+ postprocess: Enrich<TEntity>;
123
136
  /** Serializes an entity to storage format. */
124
137
  serialize: (entity: InferType<TEntity>) => InferType<TEntity>;
125
138
  /** Unique id for the schema. */
@@ -140,6 +153,8 @@ export type CompiledSchema<TEntity extends {}> = {
140
153
  definition: SchemaDefinition<TEntity>;
141
154
  /** Returns all indexes defined for this schema. */
142
155
  getIndexes: () => Index[];
156
+ /** Compares two entities for Id equality. */
157
+ compareIds: (a: InferType<TEntity>, b: InferType<TEntity>) => boolean;
143
158
  };
144
159
  export type PropertySerializer<T extends any> = (value: T) => string | number;
145
160
  export type PropertyDeserializer<T extends any> = (value: string | number) => T;
@@ -374,7 +374,9 @@ const isNodeRuntime = () => typeof process !== 'undefined' &&
374
374
  (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
375
375
  __webpack_require__.r(__webpack_exports__);
376
376
  __webpack_require__.d(__webpack_exports__, {
377
- hash: () => (hash)
377
+ fastHash: () => (fastHash),
378
+ hash: () => (hash),
379
+ stringifyObject: () => (stringifyObject)
378
380
  });
379
381
  const hash = (value, seed = 0) => {
380
382
  // From Stack Overflow
@@ -391,6 +393,143 @@ const hash = (value, seed = 0) => {
391
393
  h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
392
394
  return 4294967296 * (2097151 & h2) + (h1 >>> 0);
393
395
  };
396
+ /**
397
+ * Fast string hash optimized for comparisons.
398
+ * Uses djb2 algorithm - very fast and good distribution for short to medium strings.
399
+ * Same input always produces same output (deterministic).
400
+ *
401
+ * @param value - The string to hash
402
+ * @param seed - Optional seed value (default: 5381)
403
+ * @returns A positive 32-bit integer hash value
404
+ *
405
+ * @example
406
+ * ```ts
407
+ * fastHash("test") === fastHash("test") // true
408
+ * fastHash("test") !== fastHash("test2") // true
409
+ * ```
410
+ */
411
+ const fastHash = (value, seed = 5381) => {
412
+ let hash = seed;
413
+ for (let i = 0; i < value.length; i++) {
414
+ hash = ((hash << 5) + hash) + value.charCodeAt(i);
415
+ }
416
+ return hash >>> 0; // Convert to unsigned 32-bit integer
417
+ };
418
+ /**
419
+ * Converts any value to a readable string representation.
420
+ * Handles primitives, objects, arrays, classes, dates, errors, and functions.
421
+ * Supports depth limiting to prevent infinite recursion on circular references.
422
+ *
423
+ * @param obj - The value to stringify
424
+ * @param maxDepth - Maximum depth for nested objects (default: 3)
425
+ * @param currentDepth - Current recursion depth (default: 0)
426
+ * @returns String representation of the value
427
+ *
428
+ * @example
429
+ * ```ts
430
+ * stringifyObject({ name: "test", count: 5 }) // '{ name: "test", count: 5 }'
431
+ * stringifyObject([1, 2, 3]) // '[1, 2, 3]'
432
+ * stringifyObject(new Date()) // 'Date(2024-01-01T00:00:00.000Z)'
433
+ * ```
434
+ */
435
+ function stringifyObject(obj, maxDepth = 3, currentDepth = 0) {
436
+ if (obj === null)
437
+ return 'null';
438
+ if (obj === undefined)
439
+ return 'undefined';
440
+ const type = typeof obj;
441
+ switch (type) {
442
+ case 'string':
443
+ return `"${obj}"`;
444
+ case 'number':
445
+ case 'boolean':
446
+ return String(obj);
447
+ case 'function':
448
+ return `[Function: ${getFunctionName(obj)}]`;
449
+ case 'object':
450
+ if (currentDepth >= maxDepth) {
451
+ return '[Max Depth Reached]';
452
+ }
453
+ return stringifyObjectValue(obj, maxDepth, currentDepth);
454
+ default:
455
+ return `[${type}]`;
456
+ }
457
+ }
458
+ function getFunctionName(fn) {
459
+ const name = fn.name;
460
+ return name || 'anonymous';
461
+ }
462
+ function getObjectProperties(obj) {
463
+ const properties = {};
464
+ for (const key in obj) {
465
+ if (obj.hasOwnProperty(key)) {
466
+ properties[key] = obj[key];
467
+ }
468
+ }
469
+ return properties;
470
+ }
471
+ function stringifyObjectValue(obj, maxDepth, currentDepth) {
472
+ if (obj === null)
473
+ return 'null';
474
+ if (obj instanceof Date) {
475
+ return `Date(${obj.toISOString()})`;
476
+ }
477
+ if (obj instanceof Error) {
478
+ return `Error(${obj.message})`;
479
+ }
480
+ if (obj instanceof RegExp) {
481
+ return obj.toString();
482
+ }
483
+ if (Array.isArray(obj)) {
484
+ return stringifyArray(obj, maxDepth, currentDepth);
485
+ }
486
+ if (obj.constructor && obj.constructor.name !== 'Object') {
487
+ return stringifyClassInstance(obj, maxDepth, currentDepth);
488
+ }
489
+ return stringifyPlainObject(obj, maxDepth, currentDepth);
490
+ }
491
+ function stringifyArray(arr, maxDepth, currentDepth) {
492
+ if (arr.length === 0)
493
+ return '[]';
494
+ const items = arr.slice(0, 5).map(item => stringifyObject(item, maxDepth, currentDepth + 1));
495
+ const suffix = arr.length > 5 ? `... (+${arr.length - 5} more)` : '';
496
+ return `[${items.join(', ')}${suffix}]`;
497
+ }
498
+ function stringifyClassInstance(obj, maxDepth, currentDepth) {
499
+ const className = obj.constructor.name;
500
+ const properties = getObjectProperties(obj);
501
+ if (Object.keys(properties).length === 0) {
502
+ return `${className} {}`;
503
+ }
504
+ const props = Object.entries(properties)
505
+ .slice(0, 5)
506
+ .map(([key, value]) => {
507
+ const isPrimitive = value === null || value === undefined ||
508
+ (typeof value !== 'object' && typeof value !== 'function');
509
+ const depth = isPrimitive ? currentDepth : currentDepth + 1;
510
+ return `${key}: ${stringifyObject(value, maxDepth, depth)}`;
511
+ });
512
+ const suffix = Object.keys(properties).length > 5 ?
513
+ `... (+${Object.keys(properties).length - 5} more)` : '';
514
+ return `${className} { ${props.join(', ')}${suffix} }`;
515
+ }
516
+ function stringifyPlainObject(obj, maxDepth, currentDepth) {
517
+ const properties = getObjectProperties(obj);
518
+ if (Object.keys(properties).length === 0) {
519
+ return '{}';
520
+ }
521
+ const props = Object.entries(properties)
522
+ .slice(0, 5)
523
+ .map(([key, value]) => {
524
+ const isPrimitive = value === null || value === undefined ||
525
+ (typeof value !== 'object' && typeof value !== 'function');
526
+ const depth = isPrimitive ? currentDepth : currentDepth + 1;
527
+ return `${key}: ${stringifyObject(value, maxDepth, depth)}`;
528
+ });
529
+ const suffix = Object.keys(properties).length > 5 ?
530
+ `... (+${Object.keys(properties).length - 5} more)` : '';
531
+ return `{ ${props.join(', ')}${suffix} }`;
532
+ }
394
533
 
395
534
 
396
535
  }),
@@ -520,11 +659,13 @@ __webpack_require__.d(__webpack_exports__, {
520
659
  cast: () => (/* reexport safe */ _objects__WEBPACK_IMPORTED_MODULE_3__.cast),
521
660
  clone: () => (/* reexport safe */ _objects__WEBPACK_IMPORTED_MODULE_3__.clone),
522
661
  combineQueryOptionsCollections: () => (/* reexport safe */ _queryOptionsCollection__WEBPACK_IMPORTED_MODULE_7__.combineQueryOptionsCollections),
662
+ fastHash: () => (/* reexport safe */ _strings__WEBPACK_IMPORTED_MODULE_1__.fastHash),
523
663
  hash: () => (/* reexport safe */ _strings__WEBPACK_IMPORTED_MODULE_1__.hash),
524
664
  isDate: () => (/* reexport safe */ _dates__WEBPACK_IMPORTED_MODULE_2__.isDate),
525
665
  isNodeRuntime: () => (/* reexport safe */ _runtime__WEBPACK_IMPORTED_MODULE_4__.isNodeRuntime),
526
666
  noop: () => (/* reexport safe */ _functions__WEBPACK_IMPORTED_MODULE_9__.noop),
527
667
  resolveBulkPersistChanges: () => (/* reexport safe */ _replication__WEBPACK_IMPORTED_MODULE_6__.resolveBulkPersistChanges),
668
+ stringifyObject: () => (/* reexport safe */ _strings__WEBPACK_IMPORTED_MODULE_1__.stringifyObject),
528
669
  toEventArray: () => (/* reexport safe */ _dbPluginEventUtils__WEBPACK_IMPORTED_MODULE_8__.toEventArray),
529
670
  toMap: () => (/* reexport safe */ _arrays__WEBPACK_IMPORTED_MODULE_0__.toMap),
530
671
  uuid: () => (/* reexport safe */ _uuid__WEBPACK_IMPORTED_MODULE_5__.uuid),
@@ -557,15 +698,17 @@ __webpack_require__.d(__webpack_exports__, {
557
698
  var __webpack_exports__cast = __webpack_exports__.cast;
558
699
  var __webpack_exports__clone = __webpack_exports__.clone;
559
700
  var __webpack_exports__combineQueryOptionsCollections = __webpack_exports__.combineQueryOptionsCollections;
701
+ var __webpack_exports__fastHash = __webpack_exports__.fastHash;
560
702
  var __webpack_exports__hash = __webpack_exports__.hash;
561
703
  var __webpack_exports__isDate = __webpack_exports__.isDate;
562
704
  var __webpack_exports__isNodeRuntime = __webpack_exports__.isNodeRuntime;
563
705
  var __webpack_exports__noop = __webpack_exports__.noop;
564
706
  var __webpack_exports__resolveBulkPersistChanges = __webpack_exports__.resolveBulkPersistChanges;
707
+ var __webpack_exports__stringifyObject = __webpack_exports__.stringifyObject;
565
708
  var __webpack_exports__toEventArray = __webpack_exports__.toEventArray;
566
709
  var __webpack_exports__toMap = __webpack_exports__.toMap;
567
710
  var __webpack_exports__uuid = __webpack_exports__.uuid;
568
711
  var __webpack_exports__uuidv4 = __webpack_exports__.uuidv4;
569
- export { __webpack_exports__cast as cast, __webpack_exports__clone as clone, __webpack_exports__combineQueryOptionsCollections as combineQueryOptionsCollections, __webpack_exports__hash as hash, __webpack_exports__isDate as isDate, __webpack_exports__isNodeRuntime as isNodeRuntime, __webpack_exports__noop as noop, __webpack_exports__resolveBulkPersistChanges as resolveBulkPersistChanges, __webpack_exports__toEventArray as toEventArray, __webpack_exports__toMap as toMap, __webpack_exports__uuid as uuid, __webpack_exports__uuidv4 as uuidv4 };
712
+ export { __webpack_exports__cast as cast, __webpack_exports__clone as clone, __webpack_exports__combineQueryOptionsCollections as combineQueryOptionsCollections, __webpack_exports__fastHash as fastHash, __webpack_exports__hash as hash, __webpack_exports__isDate as isDate, __webpack_exports__isNodeRuntime as isNodeRuntime, __webpack_exports__noop as noop, __webpack_exports__resolveBulkPersistChanges as resolveBulkPersistChanges, __webpack_exports__stringifyObject as stringifyObject, __webpack_exports__toEventArray as toEventArray, __webpack_exports__toMap as toMap, __webpack_exports__uuid as uuid, __webpack_exports__uuidv4 as uuidv4 };
570
713
 
571
714
  //# sourceMappingURL=index.js.map