gingersnap 0.26.3 → 0.26.5
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/data/model/model.cjs
CHANGED
|
@@ -262,12 +262,28 @@ class Model {
|
|
|
262
262
|
csv(options, config) {
|
|
263
263
|
return Papa.unparse([this.object(options)], config);
|
|
264
264
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Creates a deep copy of the current model instance with optional field overrides
|
|
267
|
+
* @param changes optional field values to override in the cloned model, or a function that receives the deep copied
|
|
268
|
+
* data and returns the modified data
|
|
269
|
+
* @returns a new model instance with the same values as the original, with any specified changes applied
|
|
270
|
+
*/
|
|
271
|
+
clone(changes) {
|
|
272
|
+
let jsonPayload;
|
|
273
|
+
const copy = this.object({ keepOptionals: false, removeMissingFields: true });
|
|
274
|
+
if (changes === undefined) {
|
|
275
|
+
jsonPayload = copy;
|
|
276
|
+
}
|
|
277
|
+
else if (typeof changes === "function") {
|
|
278
|
+
jsonPayload = changes(copy);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
for (const key in changes) {
|
|
282
|
+
copy[key] = changes[key];
|
|
283
|
+
}
|
|
284
|
+
jsonPayload = copy;
|
|
269
285
|
}
|
|
270
|
-
return
|
|
286
|
+
return Object.getPrototypeOf(this).constructor.fromJSON(jsonPayload);
|
|
271
287
|
}
|
|
272
288
|
/**
|
|
273
289
|
* Retrieves the schema of the current model based on the selected format
|
package/data/model/model.d.ts
CHANGED
|
@@ -204,7 +204,13 @@ export declare class Model {
|
|
|
204
204
|
* @returns csv string
|
|
205
205
|
*/
|
|
206
206
|
csv(options?: ModelExportOptions, config?: Papa.UnparseConfig): string;
|
|
207
|
-
|
|
207
|
+
/**
|
|
208
|
+
* Creates a deep copy of the current model instance with optional field overrides
|
|
209
|
+
* @param changes optional field values to override in the cloned model, or a function that receives the deep copied
|
|
210
|
+
* data and returns the modified data
|
|
211
|
+
* @returns a new model instance with the same values as the original, with any specified changes applied
|
|
212
|
+
*/
|
|
213
|
+
clone(changes?: Record<string, any> | ((prev: Record<string, any>) => Record<string, any>)): typeof this;
|
|
208
214
|
/**
|
|
209
215
|
* Retrieves the schema of the current model based on the selected format
|
|
210
216
|
* @param includeTitleAndDraft boolean whether the title and JSON schema draft version should be referenced in the schema
|
package/data/model/model.mjs
CHANGED
|
@@ -241,12 +241,28 @@ class Model {
|
|
|
241
241
|
csv(options, config) {
|
|
242
242
|
return Papa.unparse([this.object(options)], config);
|
|
243
243
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Creates a deep copy of the current model instance with optional field overrides
|
|
246
|
+
* @param changes optional field values to override in the cloned model, or a function that receives the deep copied
|
|
247
|
+
* data and returns the modified data
|
|
248
|
+
* @returns a new model instance with the same values as the original, with any specified changes applied
|
|
249
|
+
*/
|
|
250
|
+
clone(changes) {
|
|
251
|
+
let jsonPayload;
|
|
252
|
+
const copy = this.object({ keepOptionals: false, removeMissingFields: true });
|
|
253
|
+
if (changes === undefined) {
|
|
254
|
+
jsonPayload = copy;
|
|
255
|
+
}
|
|
256
|
+
else if (typeof changes === "function") {
|
|
257
|
+
jsonPayload = changes(copy);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
for (const key in changes) {
|
|
261
|
+
copy[key] = changes[key];
|
|
262
|
+
}
|
|
263
|
+
jsonPayload = copy;
|
|
248
264
|
}
|
|
249
|
-
return
|
|
265
|
+
return Object.getPrototypeOf(this).constructor.fromJSON(jsonPayload);
|
|
250
266
|
}
|
|
251
267
|
/**
|
|
252
268
|
* Retrieves the schema of the current model based on the selected format
|
|
@@ -487,6 +487,29 @@ class Instant {
|
|
|
487
487
|
static now() {
|
|
488
488
|
return new Instant(new Date().getTime());
|
|
489
489
|
}
|
|
490
|
+
/**
|
|
491
|
+
* Creates an Instant from an ISO 8601 string or epoch milliseconds.
|
|
492
|
+
*
|
|
493
|
+
* @param value - An ISO 8601 date-time string or epoch milliseconds
|
|
494
|
+
* @returns An Instant representing the specified moment
|
|
495
|
+
* @throws {Error} If the input is not a valid ISO 8601 string
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* ```ts
|
|
499
|
+
* const i1 = Instant.from('2024-01-01T12:00:00.000Z');
|
|
500
|
+
* const i2 = Instant.from(1704110400000); // Epoch milliseconds
|
|
501
|
+
* ```
|
|
502
|
+
*/
|
|
503
|
+
static from(value) {
|
|
504
|
+
if (typeof value === "number") {
|
|
505
|
+
return new Instant(value);
|
|
506
|
+
}
|
|
507
|
+
const timestamp = Date.parse(value);
|
|
508
|
+
if (isNaN(timestamp)) {
|
|
509
|
+
throw new Error(`Invalid ISO 8601 date-time format: ${value}`);
|
|
510
|
+
}
|
|
511
|
+
return new Instant(timestamp);
|
|
512
|
+
}
|
|
490
513
|
/**
|
|
491
514
|
* Checks if this instant is in the distant future.
|
|
492
515
|
*
|
|
@@ -392,6 +392,20 @@ export declare class Instant {
|
|
|
392
392
|
* ```
|
|
393
393
|
*/
|
|
394
394
|
static now(): Instant;
|
|
395
|
+
/**
|
|
396
|
+
* Creates an Instant from an ISO 8601 string or epoch milliseconds.
|
|
397
|
+
*
|
|
398
|
+
* @param value - An ISO 8601 date-time string or epoch milliseconds
|
|
399
|
+
* @returns An Instant representing the specified moment
|
|
400
|
+
* @throws {Error} If the input is not a valid ISO 8601 string
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```ts
|
|
404
|
+
* const i1 = Instant.from('2024-01-01T12:00:00.000Z');
|
|
405
|
+
* const i2 = Instant.from(1704110400000); // Epoch milliseconds
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
static from(value: string | number): Instant;
|
|
395
409
|
/**
|
|
396
410
|
* Checks if this instant is in the distant future.
|
|
397
411
|
*
|
|
@@ -485,6 +485,29 @@ class Instant {
|
|
|
485
485
|
static now() {
|
|
486
486
|
return new Instant(new Date().getTime());
|
|
487
487
|
}
|
|
488
|
+
/**
|
|
489
|
+
* Creates an Instant from an ISO 8601 string or epoch milliseconds.
|
|
490
|
+
*
|
|
491
|
+
* @param value - An ISO 8601 date-time string or epoch milliseconds
|
|
492
|
+
* @returns An Instant representing the specified moment
|
|
493
|
+
* @throws {Error} If the input is not a valid ISO 8601 string
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* ```ts
|
|
497
|
+
* const i1 = Instant.from('2024-01-01T12:00:00.000Z');
|
|
498
|
+
* const i2 = Instant.from(1704110400000); // Epoch milliseconds
|
|
499
|
+
* ```
|
|
500
|
+
*/
|
|
501
|
+
static from(value) {
|
|
502
|
+
if (typeof value === "number") {
|
|
503
|
+
return new Instant(value);
|
|
504
|
+
}
|
|
505
|
+
const timestamp = Date.parse(value);
|
|
506
|
+
if (isNaN(timestamp)) {
|
|
507
|
+
throw new Error(`Invalid ISO 8601 date-time format: ${value}`);
|
|
508
|
+
}
|
|
509
|
+
return new Instant(timestamp);
|
|
510
|
+
}
|
|
488
511
|
/**
|
|
489
512
|
* Checks if this instant is in the distant future.
|
|
490
513
|
*
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"gingersnap","version":"0.26.
|
|
1
|
+
{"name":"gingersnap","version":"0.26.5","description":"A general purpose library built with the aim of filling the gaps of javascript shortcomings","dependencies":{"@msgpack/msgpack":"^3.0.0-beta2","browser-or-node":"^3.0.0-pre.0","modern-isomorphic-ws":"^1.0.5","object-hash":"^3.0.0","papaparse":"^5.4.1","protobufjs":"^7.2.6","ramda":"^0.30.1","reflect-metadata":"^0.2.2","tslib":"^2.6.3","uuid":"^9.0.1","ws":"^8.16.0","x2js":"^3.4.4"},"author":"CookieNerds LLC","exports":{"./synchronize":{"import":{"types":"./synchronize.d.ts","default":"./synchronize.mjs"},"require":{"types":"./synchronize.d.ts","default":"./synchronize.cjs"}},"./mocks":{"import":{"types":"./mocks.d.ts","default":"./mocks.mjs"},"require":{"types":"./mocks.d.ts","default":"./mocks.cjs"}},"./socket":{"import":{"types":"./socket.d.ts","default":"./socket.mjs"},"require":{"types":"./socket.d.ts","default":"./socket.cjs"}},"./typing/types":{"import":{"types":"./typing/types.d.ts","default":"./typing/types.mjs"},"require":{"types":"./typing/types.d.ts","default":"./typing/types.cjs"}},"./stream":{"import":{"types":"./stream/index.d.ts","default":"./stream.mjs"},"require":{"types":"./stream/index.d.ts","default":"./stream.cjs"}},"./reflection/injector":{"import":{"types":"./reflection/injector.d.ts","default":"./reflection/injector.mjs"},"require":{"types":"./reflection/injector.d.ts","default":"./reflection/injector.cjs"}},"./stream/call":{"import":{"types":"./stream/call.d.ts","default":"./stream/call.mjs"},"require":{"types":"./stream/call.d.ts","default":"./stream/call.cjs"}},"./stream/state":{"import":{"types":"./stream/state.d.ts","default":"./stream/state.mjs"},"require":{"types":"./stream/state.d.ts","default":"./stream/state.cjs"}},"./stream/collector":{"import":{"types":"./stream/collector.d.ts","default":"./stream/collector.mjs"},"require":{"types":"./stream/collector.d.ts","default":"./stream/collector.cjs"}},"./stream/observable":{"import":{"types":"./stream/observable.d.ts","default":"./stream/observable.mjs"},"require":{"types":"./stream/observable.d.ts","default":"./stream/observable.cjs"}},"./networking":{"import":{"types":"./networking/index.d.ts","default":"./networking.mjs"},"require":{"types":"./networking/index.d.ts","default":"./networking.cjs"}},"./managers":{"import":{"types":"./managers/index.d.ts","default":"./managers.mjs"},"require":{"types":"./managers/index.d.ts","default":"./managers.cjs"}},"./future":{"import":{"types":"./future/index.d.ts","default":"./future.mjs"},"require":{"types":"./future/index.d.ts","default":"./future.cjs"}},"./errors":{"import":{"types":"./errors/index.d.ts","default":"./errors.mjs"},"require":{"types":"./errors/index.d.ts","default":"./errors.cjs"}},"./data-structures/array":{"import":{"types":"./data-structures/array/index.d.ts","default":"./data-structures/array.mjs"},"require":{"types":"./data-structures/array/index.d.ts","default":"./data-structures/array.cjs"}},"./data-structures/object":{"import":{"types":"./data-structures/object/index.d.ts","default":"./data-structures/object.mjs"},"require":{"types":"./data-structures/object/index.d.ts","default":"./data-structures/object.cjs"}},"./data/decoders":{"import":{"types":"./data/decoders/index.d.ts","default":"./data/decoders.mjs"},"require":{"types":"./data/decoders/index.d.ts","default":"./data/decoders.cjs"}},"./data/model":{"import":{"types":"./data/model/index.d.ts","default":"./data/model.mjs"},"require":{"types":"./data/model/index.d.ts","default":"./data/model.cjs"}},"./data/bus":{"import":{"types":"./data/bus.d.ts","default":"./data/bus.mjs"},"require":{"types":"./data/bus.d.ts","default":"./data/bus.cjs"}},"./data/AtomicValue":{"import":{"types":"./data/AtomicValue.d.ts","default":"./data/AtomicValue.mjs"},"require":{"types":"./data/AtomicValue.d.ts","default":"./data/AtomicValue.cjs"}},"./data/store":{"import":{"types":"./data/store/index.d.ts","default":"./data/store.mjs"},"require":{"types":"./data/store/index.d.ts","default":"./data/store.cjs"}},"./functools":{"import":{"types":"./functools/index.d.ts","default":"./functools.mjs"},"require":{"types":"./functools/index.d.ts","default":"./functools.cjs"}},"./files":{"import":{"types":"./files.d.ts","default":"./files.mjs"},"require":{"types":"./files.d.ts","default":"./files.cjs"}}}}
|