@webda/models 0.0.0-stage → 4.0.0-beta.4

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 (51) hide show
  1. package/LICENSE +166 -0
  2. package/README.md +146 -2
  3. package/lib/index.d.ts +11 -0
  4. package/lib/index.d.ts.map +1 -0
  5. package/lib/index.js +11 -0
  6. package/lib/index.js.map +1 -0
  7. package/lib/mock.d.ts +72 -0
  8. package/lib/mock.d.ts.map +1 -0
  9. package/lib/mock.js +83 -0
  10. package/lib/mock.js.map +1 -0
  11. package/lib/model.model.d.ts +286 -0
  12. package/lib/model.model.d.ts.map +1 -0
  13. package/lib/model.model.js +336 -0
  14. package/lib/model.model.js.map +1 -0
  15. package/lib/relations.d.ts +705 -0
  16. package/lib/relations.d.ts.map +1 -0
  17. package/lib/relations.js +938 -0
  18. package/lib/relations.js.map +1 -0
  19. package/lib/repositories/abstract.d.ts +138 -0
  20. package/lib/repositories/abstract.d.ts.map +1 -0
  21. package/lib/repositories/abstract.js +280 -0
  22. package/lib/repositories/abstract.js.map +1 -0
  23. package/lib/repositories/conformance.d.ts +40 -0
  24. package/lib/repositories/conformance.d.ts.map +1 -0
  25. package/lib/repositories/conformance.js +38 -0
  26. package/lib/repositories/conformance.js.map +1 -0
  27. package/lib/repositories/event.d.ts +101 -0
  28. package/lib/repositories/event.d.ts.map +1 -0
  29. package/lib/repositories/event.js +228 -0
  30. package/lib/repositories/event.js.map +1 -0
  31. package/lib/repositories/hooks.d.ts +88 -0
  32. package/lib/repositories/hooks.d.ts.map +1 -0
  33. package/lib/repositories/hooks.js +105 -0
  34. package/lib/repositories/hooks.js.map +1 -0
  35. package/lib/repositories/memory.d.ts +262 -0
  36. package/lib/repositories/memory.d.ts.map +1 -0
  37. package/lib/repositories/memory.js +574 -0
  38. package/lib/repositories/memory.js.map +1 -0
  39. package/lib/repositories/repository.d.ts +238 -0
  40. package/lib/repositories/repository.d.ts.map +1 -0
  41. package/lib/repositories/repository.js +19 -0
  42. package/lib/repositories/repository.js.map +1 -0
  43. package/lib/storable.d.ts +210 -0
  44. package/lib/storable.d.ts.map +1 -0
  45. package/lib/storable.js +76 -0
  46. package/lib/storable.js.map +1 -0
  47. package/lib/types.d.ts +230 -0
  48. package/lib/types.d.ts.map +1 -0
  49. package/lib/types.js +12 -0
  50. package/lib/types.js.map +1 -0
  51. package/package.json +60 -3
@@ -0,0 +1,286 @@
1
+ import { WEBDA_EVENTS, WEBDA_PRIMARY_KEY, type PK, type PrimaryKeyType, type Storable, WEBDA_PRIMARY_KEY_SEPARATOR, WEBDA_STORAGE, ModelClass } from "./storable.js";
2
+ import { WEBDA_DIRTY } from "@webda/utils";
3
+ import type { SelfDTO, SelfJSONed } from "./types.js";
4
+ import { type ModelRef } from "./relations.js";
5
+ import type { Repository } from "./repositories/repository.js";
6
+ import { ObjectSerializer, type SerializerContext } from "@webda/serialize";
7
+ import { LoadParameters } from "./types.js";
8
+ /**
9
+ * Make all properties optional except those in K.
10
+ */
11
+ export type PartialExcept<T, K extends keyof T> = Partial<T> & Pick<T, K>;
12
+ /**
13
+ * Make only the properties in K optional, keeping the rest required.
14
+ */
15
+ export type ExceptPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
16
+ /**
17
+ * Allow simulated delete
18
+ */
19
+ export declare const WEBDA_DELETED = "__deleted";
20
+ /**
21
+ * Event sent by models
22
+ *
23
+ * Events are sent by the model to notify of changes
24
+ * after the changes are done
25
+ *
26
+ * If you need to prevent the change, you should extend the object
27
+ */
28
+ export type ModelEvents<T = any> = {
29
+ Create: {
30
+ object_id: string;
31
+ object: T;
32
+ };
33
+ PartialUpdate: any;
34
+ Delete: {
35
+ object_id: string;
36
+ };
37
+ Update: {
38
+ object_id: string;
39
+ object: T;
40
+ previous: T;
41
+ };
42
+ Patch: {
43
+ object_id: string;
44
+ object: T;
45
+ previous: T;
46
+ };
47
+ Query: {
48
+ query: string;
49
+ };
50
+ Created: {
51
+ object_id: string;
52
+ object: T;
53
+ };
54
+ PartialUpdated: any;
55
+ Deleted: {
56
+ object_id: string;
57
+ };
58
+ Patched: {
59
+ object_id: string;
60
+ object: T;
61
+ previous: T;
62
+ };
63
+ Updated: {
64
+ object_id: string;
65
+ object: T;
66
+ previous: T;
67
+ };
68
+ Queried: {
69
+ query: string;
70
+ results: T[];
71
+ continuationToken?: string;
72
+ };
73
+ };
74
+ /**
75
+ * Serializer used by repositories to store a model.
76
+ *
77
+ * `ObjectSerializer` walks a model with `for...in`, which only reaches its
78
+ * enumerable fields. Accessors generated by `@webda/content-mapper` (Date
79
+ * coercion, relation links) are non-enumerable prototype properties whose
80
+ * values live in `WEBDA_STORAGE`, so a repository silently dropped them. This
81
+ * serializer adds them, and stores a relation link (`ModelLink`,
82
+ * `ModelLinksSimpleArray`, ...) as its `toJSON()` — the primary key(s) — which
83
+ * is what the generated setter accepts back on load and what queries compare
84
+ * against.
85
+ */
86
+ export declare class ModelSerializer extends ObjectSerializer {
87
+ /**
88
+ * Serialize the model's fields, including those held in `WEBDA_STORAGE`
89
+ * @param obj - the model to serialize
90
+ * @param context - the serializer context
91
+ * @returns the serialized value and metadata
92
+ */
93
+ serializer(obj: any, context: SerializerContext): {
94
+ value: {
95
+ [key: string]: any;
96
+ };
97
+ metadata: {
98
+ [key: string]: any;
99
+ } | undefined;
100
+ };
101
+ }
102
+ declare const Model_base: {
103
+ new (...args: any[]): {
104
+ toProxy(): /*elided*/ any;
105
+ };
106
+ getRepository<T extends ModelClass>(this: T): Repository<T>;
107
+ create<T extends ModelClass>(this: T, data: InstanceType<T> extends infer T_1 ? { [K in keyof T_1 as K extends symbol ? never : InstanceType<T>[K] extends (...args: any[]) => any ? never : K]: T_1[K]; } : never, save?: boolean): Promise<InstanceType<T>>;
108
+ query<T extends ModelClass>(this: T, query: import("@webda/ql").WebdaQLString<InstanceType<T>>, params?: import("@webda/ql").QueryParameters): Promise<{
109
+ results: InstanceType<T>[];
110
+ continuationToken?: string;
111
+ }>;
112
+ iterate<T extends ModelClass>(this: T, query: import("@webda/ql").WebdaQLString<InstanceType<T>>, params?: import("@webda/ql").QueryParameters): AsyncGenerator<InstanceType<T>, any, any>;
113
+ ref<T extends ModelClass>(this: T, key: import("./storable.js").SettablePrimaryKey<InstanceType<T>>): import("./relations.js").ModelRefWithCreate<InstanceType<T>>;
114
+ } & ObjectConstructor;
115
+ /**
116
+ * Model object definition
117
+ *
118
+ * This is the core of many application
119
+ */
120
+ export declare abstract class Model extends Model_base implements Storable {
121
+ /**
122
+ * Model events
123
+ */
124
+ [WEBDA_EVENTS]?: ModelEvents<this>;
125
+ /**
126
+ * Internal backing store for morpher-generated accessor properties.
127
+ * Populated automatically when getter/setter pairs are generated at build time.
128
+ */
129
+ protected [WEBDA_STORAGE]: Record<string, any>;
130
+ /**
131
+ * Properties that are dirty and need to be saved
132
+ * @private
133
+ */
134
+ [WEBDA_DIRTY]?: Set<string>;
135
+ /** Non-abstract class need to define their PrimaryKey */
136
+ abstract [WEBDA_PRIMARY_KEY]: readonly (keyof this)[];
137
+ /**
138
+ * K is inferred as the literal tuple type of `this.keyFields`,
139
+ * so K[number] is the exact union of keys you wrote.
140
+ * @returns the primary key value
141
+ */
142
+ getPrimaryKey<K extends readonly (keyof this)[]>(this: this & {
143
+ [WEBDA_PRIMARY_KEY]: K;
144
+ [WEBDA_PRIMARY_KEY_SEPARATOR]?: string;
145
+ }): PrimaryKeyType<this>;
146
+ /**
147
+ * Return the string representation of the primary key
148
+ * @returns the string UID
149
+ */
150
+ getUUID(): string;
151
+ /**
152
+ * Get a reference to this model instance in its repository
153
+ * @returns a model reference
154
+ */
155
+ ref(): ModelRef<this>;
156
+ /**
157
+ * Set the primary key of the model
158
+ * @param this - the model instance
159
+ * @param value - the primary key value to set
160
+ * @returns the model instance
161
+ */
162
+ setPrimaryKey<K extends readonly (keyof this)[]>(this: this & {
163
+ [WEBDA_PRIMARY_KEY]: K;
164
+ }, value: PK<this, K[number]>): this;
165
+ /**
166
+ * Get the repository associated with this model class
167
+ * @returns the repository
168
+ */
169
+ getRepository(): Repository<ModelClass<this>>;
170
+ /**
171
+ * Register Model custom serializer
172
+ * @param this - the model class constructor
173
+ * @param overwrite - whether to overwrite an existing serializer
174
+ * @param identifier - fully-qualified model identifier (e.g. `WebdaSample/User`)
175
+ * used to namespace the serializer key when multiple classes share the same
176
+ * JS constructor name. Defaults to the constructor's own name.
177
+ *
178
+ * TODO Might want to move to deserialize static function
179
+ */
180
+ static registerSerializer<T extends ModelClass>(this: T & {
181
+ fromJSON?: (data: any) => InstanceType<T>;
182
+ getStaticProperties?: () => any;
183
+ }, overwrite?: boolean, identifier?: string): void;
184
+ /**
185
+ * Serialize the model to JSON.
186
+ *
187
+ * Uses `for...in` to include both own enumerable properties (regular class fields)
188
+ * and inherited enumerable prototype getters generated by the morpher for coercible
189
+ * fields (e.g. Date). Symbol-keyed internals and methods are excluded automatically.
190
+ * @returns the model instance
191
+ */
192
+ toJSON(): this;
193
+ /**
194
+ * Public representation of the model: its JSON form without `__`-prefixed
195
+ * (server-only) keys, at any depth. Dates are serialized as strings.
196
+ *
197
+ * Implemented as a `JSON.parse(JSON.stringify(this))` round-trip, so circular
198
+ * references throw, BigInt throws and Buffers become `{ type: "Buffer", data }`.
199
+ * A model with such fields must override `toDTO`.
200
+ * @returns the DTO
201
+ */
202
+ toDTO(): SelfDTO<this>;
203
+ /**
204
+ * Reload the model from the repository, updating all properties in-place
205
+ * @returns the refreshed model instance
206
+ */
207
+ refresh(): Promise<this>;
208
+ /**
209
+ * Save the model to the repository
210
+ * @returns the saved model instance
211
+ */
212
+ save(): Promise<this>;
213
+ /**
214
+ * Helper to emit events from the class
215
+ * @param event - the event name to emit
216
+ * @param payload - the event data
217
+ */
218
+ protected emit<T extends keyof this[typeof WEBDA_EVENTS]>(event: T, payload: this[typeof WEBDA_EVENTS][T]): Promise<void>;
219
+ /**
220
+ * Custom deserializers for the model
221
+ * @returns a map of field deserializers, or undefined
222
+ */
223
+ static getDeserializers<T extends ModelClass>(this: T): Partial<Record<keyof InstanceType<T>, (value: any) => any>> | undefined;
224
+ /** Built-in deserializer helpers for common types */
225
+ static DefaultDeserializer: {
226
+ Date: (value: string | number | Date | undefined) => Date;
227
+ };
228
+ /**
229
+ * Deserialize the model
230
+ * @param this - the model class constructor
231
+ * @param data - the raw data to deserialize
232
+ * @param instance - optional existing instance to populate
233
+ * @returns the deserialized model instance
234
+ */
235
+ static deserialize<T extends ModelClass, K extends object = InstanceType<T>>(this: T, data: any, instance?: K): K;
236
+ /**
237
+ * Allow to load from Storage, Dto and helper formats
238
+ * @param params - the data to load
239
+ * @returns the model instance
240
+ */
241
+ load(params: LoadParameters<this>): this;
242
+ /**
243
+ * Check whether this model instance has been soft-deleted
244
+ * @returns true if soft-deleted
245
+ */
246
+ isDeleted(): any;
247
+ /**
248
+ * Delete a model
249
+ * @returns a promise resolving when deleted (void)
250
+ */
251
+ delete(): Promise<void>;
252
+ /**
253
+ * Patch the object
254
+ * @param data - the partial data to patch with
255
+ * @returns the patched model instance
256
+ */
257
+ patch(data: Partial<SelfJSONed<this>>): Promise<this>;
258
+ }
259
+ /**
260
+ * Simple model with a UUID
261
+ */
262
+ export declare class UuidModel extends Model {
263
+ /**
264
+ * Definition of the primary key
265
+ */
266
+ [WEBDA_PRIMARY_KEY]: readonly ["uuid"];
267
+ /**
268
+ * UUID of the model
269
+ * @format uuid
270
+ */
271
+ uuid: string;
272
+ /**
273
+ * Constructor
274
+ * @param data - optional initial data
275
+ */
276
+ constructor(data?: Partial<UuidModel>);
277
+ /**
278
+ * Generate a new UUID for this model.
279
+ * Override to provide custom ID generation logic.
280
+ * @param data - Optional partial data used during construction
281
+ * @returns the generated UUID string
282
+ */
283
+ generateUUID(data?: any): string;
284
+ }
285
+ export {};
286
+ //# sourceMappingURL=model.model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.model.d.ts","sourceRoot":"","sources":["../src/model.model.ts"],"names":[],"mappings":"AAAA,OAAO,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,SAAU,SAAQ,KAAK;IAClC;;OAEG;IACI,CAAC,iBAAiB,CAAC,YAAI,MAAM,EAAW;IAC/C;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,YAAY,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,EAGpC;IAED;;;;;OAKG;IACH,YAAY,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,MAAM,CAE/B;CACF"}
@@ -0,0 +1,336 @@
1
+ var _a, _b;
2
+ import { WEBDA_EVENTS, WEBDA_PRIMARY_KEY, WEBDA_PRIMARY_KEY_SEPARATOR, WEBDA_STORAGE } from "./storable.js";
3
+ import { WEBDA_DIRTY } from "@webda/utils";
4
+ import { randomUUID } from "crypto";
5
+ import { RelationRole } from "./relations.js";
6
+ import { ObjectSerializer, registerSerializer } from "@webda/serialize";
7
+ import { RepositoryStorageClassMixIn } from "./repositories/hooks.js";
8
+ /**
9
+ * Allow simulated delete
10
+ */
11
+ export const WEBDA_DELETED = "__deleted";
12
+ /**
13
+ * Serializer used by repositories to store a model.
14
+ *
15
+ * `ObjectSerializer` walks a model with `for...in`, which only reaches its
16
+ * enumerable fields. Accessors generated by `@webda/content-mapper` (Date
17
+ * coercion, relation links) are non-enumerable prototype properties whose
18
+ * values live in `WEBDA_STORAGE`, so a repository silently dropped them. This
19
+ * serializer adds them, and stores a relation link (`ModelLink`,
20
+ * `ModelLinksSimpleArray`, ...) as its `toJSON()` — the primary key(s) — which
21
+ * is what the generated setter accepts back on load and what queries compare
22
+ * against.
23
+ */
24
+ export class ModelSerializer extends ObjectSerializer {
25
+ /**
26
+ * Serialize the model's fields, including those held in `WEBDA_STORAGE`
27
+ * @param obj - the model to serialize
28
+ * @param context - the serializer context
29
+ * @returns the serialized value and metadata
30
+ */
31
+ serializer(obj, context) {
32
+ const storage = obj?.[WEBDA_STORAGE];
33
+ if (!storage || !Object.keys(storage).length) {
34
+ return super.serializer(obj, context);
35
+ }
36
+ const fields = {};
37
+ for (const key in obj) {
38
+ fields[key] = obj[key];
39
+ }
40
+ for (const key of Object.keys(storage)) {
41
+ const value = obj[key];
42
+ fields[key] = value !== null && typeof value === "object" && RelationRole in value ? value.toJSON() : value;
43
+ }
44
+ return super.serializer(fields, context);
45
+ }
46
+ }
47
+ /**
48
+ * Model object definition
49
+ *
50
+ * This is the core of many application
51
+ */
52
+ export class Model extends RepositoryStorageClassMixIn(Object) {
53
+ constructor() {
54
+ super(...arguments);
55
+ /**
56
+ * Internal backing store for morpher-generated accessor properties.
57
+ * Populated automatically when getter/setter pairs are generated at build time.
58
+ */
59
+ this[_a] = {};
60
+ }
61
+ static { _a = WEBDA_STORAGE; }
62
+ /**
63
+ * K is inferred as the literal tuple type of `this.keyFields`,
64
+ * so K[number] is the exact union of keys you wrote.
65
+ * @returns the primary key value
66
+ */
67
+ getPrimaryKey() {
68
+ const result = {};
69
+ if (this[WEBDA_PRIMARY_KEY].length === 1) {
70
+ return this[this[WEBDA_PRIMARY_KEY][0]];
71
+ }
72
+ for (const k of this[WEBDA_PRIMARY_KEY]) {
73
+ result[k] = this[k];
74
+ }
75
+ result.toString = () => {
76
+ return this[WEBDA_PRIMARY_KEY].map(k => `${this[k]}`).join(this[WEBDA_PRIMARY_KEY_SEPARATOR] || "_");
77
+ };
78
+ return result;
79
+ }
80
+ /**
81
+ * Return the string representation of the primary key
82
+ * @returns the string UID
83
+ */
84
+ getUUID() {
85
+ return this.getRepository().getUID(this);
86
+ }
87
+ /**
88
+ * Get a reference to this model instance in its repository
89
+ * @returns a model reference
90
+ */
91
+ ref() {
92
+ return this.getRepository().ref(this.getPrimaryKey());
93
+ }
94
+ /**
95
+ * Set the primary key of the model
96
+ * @param this - the model instance
97
+ * @param value - the primary key value to set
98
+ * @returns the model instance
99
+ */
100
+ setPrimaryKey(value) {
101
+ if (this[WEBDA_PRIMARY_KEY].length === 1) {
102
+ this[this[WEBDA_PRIMARY_KEY][0]] = value;
103
+ }
104
+ else {
105
+ for (const k of this[WEBDA_PRIMARY_KEY]) {
106
+ this[k] = value[k];
107
+ }
108
+ }
109
+ return this;
110
+ }
111
+ /**
112
+ * Get the repository associated with this model class
113
+ * @returns the repository
114
+ */
115
+ getRepository() {
116
+ return this.constructor.getRepository();
117
+ }
118
+ /**
119
+ * Register Model custom serializer
120
+ * @param this - the model class constructor
121
+ * @param overwrite - whether to overwrite an existing serializer
122
+ * @param identifier - fully-qualified model identifier (e.g. `WebdaSample/User`)
123
+ * used to namespace the serializer key when multiple classes share the same
124
+ * JS constructor name. Defaults to the constructor's own name.
125
+ *
126
+ * TODO Might want to move to deserialize static function
127
+ */
128
+ static registerSerializer(overwrite = true, identifier) {
129
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
130
+ const clazz = this;
131
+ if (!clazz.getStaticProperties) {
132
+ clazz.getStaticProperties = () => ({});
133
+ }
134
+ // Use the fully-qualified model identifier (e.g. "WebdaSample/User") when
135
+ // available so two classes that share a JS constructor name — like an app
136
+ // override shadowing a framework-provided model — don't collide on the
137
+ // same serializer key.
138
+ const typeKey = identifier ? `@webda/models/${identifier}` : `@webda/models/${this.prototype.constructor.name}`;
139
+ // The base ObjectSerializer.deserializer is responsible for invoking the
140
+ // model's compile-time-emitted `__hydrateBehaviors(rawData)` method (when
141
+ // present), so a model loaded from a store ends up with the same wired
142
+ // Behavior instances as one populated via `model.load(...)`.
143
+ registerSerializer(typeKey, new ModelSerializer(clazz, clazz.getStaticProperties()), overwrite);
144
+ }
145
+ /**
146
+ * Serialize the model to JSON.
147
+ *
148
+ * Uses `for...in` to include both own enumerable properties (regular class fields)
149
+ * and inherited enumerable prototype getters generated by the morpher for coercible
150
+ * fields (e.g. Date). Symbol-keyed internals and methods are excluded automatically.
151
+ * @returns the model instance
152
+ */
153
+ toJSON() {
154
+ return this;
155
+ }
156
+ /**
157
+ * Public representation of the model: its JSON form without `__`-prefixed
158
+ * (server-only) keys, at any depth. Dates are serialized as strings.
159
+ *
160
+ * Implemented as a `JSON.parse(JSON.stringify(this))` round-trip, so circular
161
+ * references throw, BigInt throws and Buffers become `{ type: "Buffer", data }`.
162
+ * A model with such fields must override `toDTO`.
163
+ * @returns the DTO
164
+ */
165
+ toDTO() {
166
+ const strip = (value) => {
167
+ if (Array.isArray(value))
168
+ return value.map(strip);
169
+ if (value && typeof value === "object") {
170
+ const out = {};
171
+ for (const [k, v] of Object.entries(value)) {
172
+ if (!k.startsWith("__"))
173
+ out[k] = strip(v);
174
+ }
175
+ return out;
176
+ }
177
+ return value;
178
+ };
179
+ return strip(JSON.parse(JSON.stringify(this)));
180
+ }
181
+ /**
182
+ * Reload the model from the repository, updating all properties in-place
183
+ * @returns the refreshed model instance
184
+ */
185
+ async refresh() {
186
+ const repo = this.getRepository();
187
+ const data = await repo.get(this.getPrimaryKey());
188
+ Object.assign(this, data);
189
+ return this;
190
+ }
191
+ /**
192
+ * Save the model to the repository
193
+ * @returns the saved model instance
194
+ */
195
+ async save() {
196
+ const repo = this.getRepository();
197
+ const concreteThis = this;
198
+ if (!concreteThis["dirty"]?.valueOf()) {
199
+ await repo.upsert(concreteThis);
200
+ }
201
+ else {
202
+ const patch = concreteThis["dirty"].getPatch();
203
+ await repo.patch(this.getPrimaryKey(), patch);
204
+ concreteThis["dirty"].clear();
205
+ }
206
+ return this;
207
+ }
208
+ /**
209
+ * Helper to emit events from the class
210
+ * @param event - the event name to emit
211
+ * @param payload - the event data
212
+ */
213
+ async emit(event, payload) {
214
+ await this.getRepository().emit(event, payload);
215
+ }
216
+ /**
217
+ * Custom deserializers for the model
218
+ * @returns a map of field deserializers, or undefined
219
+ */
220
+ static getDeserializers() {
221
+ return undefined;
222
+ }
223
+ /** Built-in deserializer helpers for common types */
224
+ static { this.DefaultDeserializer = {
225
+ Date: (value) => (value ? new Date(value) : new Date())
226
+ }; }
227
+ /**
228
+ * Deserialize the model
229
+ * @param this - the model class constructor
230
+ * @param data - the raw data to deserialize
231
+ * @param instance - optional existing instance to populate
232
+ * @returns the deserialized model instance
233
+ */
234
+ static deserialize(data, instance) {
235
+ if (!instance) {
236
+ instance = new this(data);
237
+ return instance;
238
+ }
239
+ // Deserialize with custom deserializers if any
240
+ const deserializers = this.getDeserializers ? this.getDeserializers() : undefined;
241
+ let info = deserializers ? {} : data;
242
+ if (deserializers) {
243
+ for (const key in data) {
244
+ if (deserializers[key]) {
245
+ info[key] = deserializers[key](data[key]);
246
+ }
247
+ else {
248
+ info[key] = data[key];
249
+ }
250
+ }
251
+ }
252
+ else {
253
+ info = data;
254
+ }
255
+ Object.assign(instance, info);
256
+ // Hydrate Behavior-typed attributes by delegating to the per-model
257
+ // `__hydrateBehaviors(rawData)` method generated by `@webda/content-mapper`
258
+ // transformer for any model that declares Behavior-typed properties.
259
+ // Models without such properties simply lack the method, so the optional
260
+ // chain makes this a no-op for them. The same call sits inside the base
261
+ // ObjectSerializer.deserializer so both load paths share the contract.
262
+ instance.__hydrateBehaviors?.(data);
263
+ return instance;
264
+ }
265
+ /**
266
+ * Allow to load from Storage, Dto and helper formats
267
+ * @param params - the data to load
268
+ * @returns the model instance
269
+ */
270
+ load(params) {
271
+ // @ts-ignore
272
+ this.constructor.deserialize(params, this);
273
+ return this;
274
+ }
275
+ /**
276
+ * Check whether this model instance has been soft-deleted
277
+ * @returns true if soft-deleted
278
+ */
279
+ isDeleted() {
280
+ return this[WEBDA_DELETED];
281
+ }
282
+ /**
283
+ * Delete a model
284
+ * @returns a promise resolving when deleted (void)
285
+ */
286
+ async delete() {
287
+ // Mark the model as deleted
288
+ // return this.ref().setAttribute(WEBDA_DELETED, Date.now());
289
+ // or delete for real
290
+ return this.ref().delete();
291
+ }
292
+ /**
293
+ * Patch the object
294
+ * @param data - the partial data to patch with
295
+ * @returns the patched model instance
296
+ */
297
+ async patch(data) {
298
+ this.load(data);
299
+ const repo = this.getRepository();
300
+ await repo.patch(this.getPrimaryKey(), Object.keys(data).reduce((acc, key) => {
301
+ acc[key] = this[key];
302
+ return acc;
303
+ }, {}));
304
+ return this;
305
+ }
306
+ }
307
+ /**
308
+ * Simple model with a UUID
309
+ */
310
+ export class UuidModel extends Model {
311
+ static { _b = WEBDA_PRIMARY_KEY; }
312
+ /**
313
+ * Constructor
314
+ * @param data - optional initial data
315
+ */
316
+ constructor(data) {
317
+ super();
318
+ /**
319
+ * Definition of the primary key
320
+ */
321
+ this[_b] = ["uuid"];
322
+ this.uuid = data?.uuid || this.generateUUID(data);
323
+ }
324
+ /**
325
+ * Generate a new UUID for this model.
326
+ * Override to provide custom ID generation logic.
327
+ * @param data - Optional partial data used during construction
328
+ * @returns the generated UUID string
329
+ */
330
+ generateUUID(data) {
331
+ return randomUUID();
332
+ }
333
+ }
334
+ // Register serializer for UuidModel
335
+ UuidModel.registerSerializer();
336
+ //# sourceMappingURL=model.model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.model.js","sourceRoot":"","sources":["../src/model.model.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,YAAY,EACZ,iBAAiB,EAIjB,2BAA2B,EAC3B,aAAa,EAEd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAc,WAAW,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAiB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE7D,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAA0B,MAAM,kBAAkB,CAAC;AAEhG,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAWtE;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;AA0BzC;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,eAAgB,SAAQ,gBAAgB;IACnD;;;;;OAKG;IACH,UAAU,CAAC,GAAQ,EAAE,OAA0B;QAC7C,MAAM,OAAO,GAAoC,GAAG,EAAE,CAAC,aAAa,CAAC,CAAC;QACtE,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CA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