yayson 3.0.0 → 4.1.0

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 (57) hide show
  1. package/README.md +586 -67
  2. package/build/legacy.cjs +331 -0
  3. package/build/legacy.d.cts +113 -0
  4. package/build/legacy.d.cts.map +1 -0
  5. package/build/legacy.d.mts +113 -0
  6. package/build/legacy.d.mts.map +1 -0
  7. package/build/legacy.mjs +332 -0
  8. package/build/legacy.mjs.map +1 -0
  9. package/build/symbols-DSjKJ8vh.mjs +26 -0
  10. package/build/symbols-DSjKJ8vh.mjs.map +1 -0
  11. package/build/symbols-nFs99aEX.cjs +61 -0
  12. package/build/types-Do2flKZX.d.mts +129 -0
  13. package/build/types-Do2flKZX.d.mts.map +1 -0
  14. package/build/types-NiKV-lj-.d.cts +129 -0
  15. package/build/types-NiKV-lj-.d.cts.map +1 -0
  16. package/build/utils.cjs +31 -0
  17. package/build/utils.d.cts +11 -0
  18. package/build/utils.d.cts.map +1 -0
  19. package/build/utils.d.mts +11 -0
  20. package/build/utils.d.mts.map +1 -0
  21. package/build/utils.mjs +22 -0
  22. package/build/utils.mjs.map +1 -0
  23. package/build/yayson-3UYKq2H5.d.cts +81 -0
  24. package/build/yayson-3UYKq2H5.d.cts.map +1 -0
  25. package/build/yayson-Ce5uGpgU.d.mts +81 -0
  26. package/build/yayson-Ce5uGpgU.d.mts.map +1 -0
  27. package/build/yayson-CwZg5FNt.mjs +452 -0
  28. package/build/yayson-CwZg5FNt.mjs.map +1 -0
  29. package/build/yayson-l2JKseMH.cjs +468 -0
  30. package/build/yayson.cjs +3 -0
  31. package/build/yayson.d.cts +3 -0
  32. package/build/yayson.d.mts +3 -0
  33. package/build/yayson.mjs +3 -0
  34. package/package.json +72 -28
  35. package/skill/yayson/SKILL.md +233 -0
  36. package/skill/yayson/references/api.md +266 -0
  37. package/.eslintrc.json +0 -28
  38. package/.github/workflows/node.js.yml +0 -30
  39. package/.mocharc.js +0 -15
  40. package/.nvmrc +0 -1
  41. package/RELEASE.md +0 -3
  42. package/babel.config.json +0 -4
  43. package/legacy.js +0 -2
  44. package/prettier.config.js +0 -5
  45. package/src/legacy.js +0 -14
  46. package/src/yayson/adapter.js +0 -18
  47. package/src/yayson/adapters/index.js +0 -1
  48. package/src/yayson/adapters/sequelize.js +0 -11
  49. package/src/yayson/legacy-presenter.js +0 -121
  50. package/src/yayson/legacy-store.js +0 -156
  51. package/src/yayson/presenter.js +0 -198
  52. package/src/yayson/store.js +0 -194
  53. package/src/yayson.js +0 -23
  54. package/tags +0 -59
  55. package/webpack.browser.js +0 -27
  56. package/webpack.common.js +0 -39
  57. package/webpack.dist.js +0 -21
@@ -0,0 +1,452 @@
1
+ import { a as TYPE, i as REL_META, n as META, o as adapter_default, r as REL_LINKS, t as LINKS } from "./symbols-DSjKJ8vh.mjs";
2
+
3
+ //#region src/yayson/adapters/sequelize.ts
4
+ function isSequelizeModel(model) {
5
+ return model != null && typeof model === "object" && "get" in model && typeof model.get === "function";
6
+ }
7
+ var SequelizeAdapter = class extends adapter_default {
8
+ static get(model, key) {
9
+ if (isSequelizeModel(model)) return model.get(key);
10
+ }
11
+ static id(model) {
12
+ const pkFields = model.constructor && "primaryKeys" in model.constructor ? Object.keys(model.constructor.primaryKeys) : ["id"];
13
+ if (pkFields.length > 1) throw new Error("YAYSON does not support Sequelize models with composite primary keys. You can only use one column for your primary key. Currently using: " + pkFields.join(","));
14
+ else if (pkFields.length < 1) throw new Error("YAYSON can only serialize Sequelize models which have a primary key. This is used for the JSON:API model id.");
15
+ const id = this.get(model, pkFields[0]);
16
+ if (id == null) return;
17
+ return `${id}`;
18
+ }
19
+ };
20
+ var sequelize_default = SequelizeAdapter;
21
+
22
+ //#endregion
23
+ //#region src/yayson/utils.ts
24
+ /**
25
+ * Filters an attributes object to only include keys in the fields array.
26
+ * Returns the original attributes if fields is undefined.
27
+ */
28
+ function filterByFields(attributes, fields) {
29
+ if (!fields) return attributes;
30
+ const filtered = {};
31
+ for (const key of fields) if (key in attributes) filtered[key] = attributes[key];
32
+ return filtered;
33
+ }
34
+
35
+ //#endregion
36
+ //#region src/yayson/presenter.ts
37
+ function buildLinks(link) {
38
+ if (link == null) return;
39
+ if (typeof link === "object" && (link.self != null || link.related != null)) return link;
40
+ else return { self: String(link) };
41
+ }
42
+ function createPresenter(adapter) {
43
+ class Presenter {
44
+ static adapter = adapter;
45
+ static type = "objects";
46
+ static fields;
47
+ scope;
48
+ constructor(scope) {
49
+ this.scope = scope ?? { data: null };
50
+ }
51
+ id(instance) {
52
+ return this.constructor.adapter.id(instance);
53
+ }
54
+ selfLinks(_instance) {}
55
+ links(_instance) {}
56
+ relationships() {
57
+ return {};
58
+ }
59
+ attributes(instance) {
60
+ if (instance == null) return {};
61
+ const attributes = { ...this.constructor.adapter.get(instance) };
62
+ delete attributes["id"];
63
+ const relationships = this.relationships();
64
+ if (relationships) for (const key in relationships) delete attributes[key];
65
+ return filterByFields(attributes, this.constructor.fields);
66
+ }
67
+ includeRelationships(scope, instance) {
68
+ const relationships = this.relationships();
69
+ const result = [];
70
+ if (!relationships) return result;
71
+ for (const key in relationships) {
72
+ const factory = relationships[key];
73
+ if (!factory) throw new Error(`Presenter for ${key} in ${this.constructor.type} is not defined`);
74
+ const presenter = new factory(scope);
75
+ const data = this.constructor.adapter.get(instance, key);
76
+ result.push(presenter.toJSON(data, { include: true }));
77
+ }
78
+ return result;
79
+ }
80
+ buildRelationships(instance) {
81
+ if (instance == null) return null;
82
+ const rels = this.relationships();
83
+ const links = this.links(instance) || {};
84
+ let relationships = null;
85
+ if (!rels) return null;
86
+ for (const key in rels) {
87
+ const data = this.constructor.adapter.get(instance, key);
88
+ const presenter = rels[key];
89
+ const buildData = (d) => {
90
+ const id = this.constructor.adapter.id(d);
91
+ if (!id) throw new Error(`Model of type ${presenter.type} is missing an id (relationship '${key}' of ${this.constructor.type})`);
92
+ return {
93
+ id,
94
+ type: presenter.type
95
+ };
96
+ };
97
+ const build = (d) => {
98
+ const rel = {};
99
+ if (d != null) rel.data = buildData(d);
100
+ if (links[key] != null) rel.links = buildLinks(links[key]);
101
+ else if (d == null) rel.data = null;
102
+ return rel;
103
+ };
104
+ if (!relationships) relationships = {};
105
+ if (!relationships[key]) relationships[key] = {};
106
+ if (Array.isArray(data)) {
107
+ relationships[key].data = data.map(buildData);
108
+ if (links[key] != null) relationships[key].links = buildLinks(links[key]);
109
+ } else relationships[key] = build(data);
110
+ }
111
+ return relationships;
112
+ }
113
+ buildSelfLink(instance) {
114
+ return buildLinks(this.selfLinks(instance));
115
+ }
116
+ toJSON(instanceOrCollection, options) {
117
+ const opts = options ?? {};
118
+ if (opts.meta != null) this.scope.meta = opts.meta;
119
+ if (opts.links != null) this.scope.links = opts.links;
120
+ if (!this.scope.data) this.scope.data = null;
121
+ if (instanceOrCollection == null) return this.scope;
122
+ if (Array.isArray(instanceOrCollection)) {
123
+ const collection = instanceOrCollection;
124
+ if (!this.scope.data) this.scope.data = [];
125
+ collection.forEach((instance) => {
126
+ return this.toJSON(instance, options);
127
+ });
128
+ } else {
129
+ const instance = instanceOrCollection;
130
+ let added = true;
131
+ const model = {
132
+ id: this.id(instance),
133
+ type: this.constructor.type,
134
+ attributes: this.attributes(instance)
135
+ };
136
+ if (model.id === void 0) delete model.id;
137
+ const relationships = this.buildRelationships(instance);
138
+ if (relationships != null) model.relationships = relationships;
139
+ const links = this.buildSelfLink(instance);
140
+ if (links != null) model.links = links;
141
+ if (opts.include) {
142
+ if (!this.scope.included) this.scope.included = [];
143
+ if (!(this.scope.included || []).concat(Array.isArray(this.scope.data) ? this.scope.data : this.scope.data ? [this.scope.data] : []).some((i) => i.id === model.id && i.type === model.type)) this.scope.included.push(model);
144
+ else added = false;
145
+ } else if (this.scope.data != null) if (Array.isArray(this.scope.data)) if (!this.scope.data.some((i) => i.id === model.id && i.type === model.type)) this.scope.data.push(model);
146
+ else added = false;
147
+ else this.scope.data = model;
148
+ else this.scope.data = model;
149
+ if (added) this.includeRelationships(this.scope, instance);
150
+ }
151
+ return this.scope;
152
+ }
153
+ payload(instance, options) {
154
+ if (Array.isArray(instance)) throw new Error("payload() expects a single resource, not an array");
155
+ if (instance == null) throw new Error("payload() requires a resource, got null");
156
+ const model = {
157
+ type: this.constructor.type,
158
+ attributes: this.attributes(instance)
159
+ };
160
+ const id = this.id(instance);
161
+ if (id != null) model.id = id;
162
+ const relationships = this.buildRelationships(instance);
163
+ if (relationships != null) model.relationships = relationships;
164
+ const result = { data: model };
165
+ const opts = options ?? {};
166
+ if (opts.meta != null) result.meta = opts.meta;
167
+ if (opts.links != null) result.links = opts.links;
168
+ return result;
169
+ }
170
+ render(instanceOrCollection, options) {
171
+ return this.toJSON(instanceOrCollection, options);
172
+ }
173
+ static toJSON(instanceOrCollection, options) {
174
+ return new this().toJSON(instanceOrCollection, options);
175
+ }
176
+ static render(instanceOrCollection, options) {
177
+ return new this().render(instanceOrCollection, options);
178
+ }
179
+ static payload(instance, options) {
180
+ return new this().payload(instance, options);
181
+ }
182
+ }
183
+ return Presenter;
184
+ }
185
+
186
+ //#endregion
187
+ //#region src/yayson/schema.ts
188
+ function isZodLikeSchema(schema) {
189
+ return schema != null && typeof schema === "object" && "parse" in schema && typeof schema.parse === "function" && "safeParse" in schema && typeof schema.safeParse === "function";
190
+ }
191
+ function validate(schema, data, strict) {
192
+ if (!isZodLikeSchema(schema)) throw new Error("Invalid schema: must have parse and safeParse methods");
193
+ if (strict) return {
194
+ valid: true,
195
+ data: schema.parse(data)
196
+ };
197
+ else {
198
+ const result = schema.safeParse(data);
199
+ if (result.success) return {
200
+ valid: true,
201
+ data: result.data
202
+ };
203
+ else return {
204
+ valid: false,
205
+ data,
206
+ error: result.error
207
+ };
208
+ }
209
+ }
210
+
211
+ //#endregion
212
+ //#region src/yayson/store.ts
213
+ function hasId(model) {
214
+ return model.id != null;
215
+ }
216
+ var StoreRecord = class {
217
+ id;
218
+ type;
219
+ attributes;
220
+ relationships;
221
+ links;
222
+ meta;
223
+ constructor(options) {
224
+ this.id = options.id;
225
+ this.type = options.type;
226
+ this.attributes = options.attributes;
227
+ this.relationships = options.relationships;
228
+ this.links = options.links;
229
+ this.meta = options.meta;
230
+ }
231
+ };
232
+ var Store = class Store {
233
+ records = [];
234
+ schemas;
235
+ strict;
236
+ validationErrors = [];
237
+ constructor(options) {
238
+ this.schemas = options?.schemas;
239
+ this.strict = options?.strict ?? false;
240
+ this.reset();
241
+ }
242
+ reset() {
243
+ this.records = [];
244
+ this.validationErrors = [];
245
+ }
246
+ #createStub(type, id) {
247
+ const stub = { id };
248
+ stub[TYPE] = type;
249
+ return stub;
250
+ }
251
+ #createModel(resource, options) {
252
+ const models = options?.models ?? {};
253
+ const model = { ...resource.attributes || {} };
254
+ if (resource.id != null) model.id = resource.id;
255
+ const type = resource.type;
256
+ model[TYPE] = type;
257
+ if (resource.meta != null) model[META] = resource.meta;
258
+ if (resource.links != null) model[LINKS] = resource.links;
259
+ if (hasId(model)) {
260
+ const idStr = String(model.id);
261
+ if (!models[type]) models[type] = {};
262
+ if (!models[type][idStr]) models[type][idStr] = model;
263
+ }
264
+ if (resource.relationships != null) {
265
+ const resolver = (ref) => {
266
+ return this.#findModel(ref.type, ref.id, models) ?? this.#createStub(ref.type, ref.id);
267
+ };
268
+ this.#resolveRelationships(model, resource.relationships, resolver, { includeRelMeta: options?.includeRelMeta });
269
+ }
270
+ return model;
271
+ }
272
+ #resolveRelationships(model, relationships, resolver, options) {
273
+ const includeRelMeta = options?.includeRelMeta ?? true;
274
+ for (const key in relationships) {
275
+ const { data, links, meta } = relationships[key];
276
+ model[key] = null;
277
+ if (data == null && links == null) continue;
278
+ if (Array.isArray(data)) model[key] = data.filter((item) => item.id != null).map(resolver);
279
+ else if (data != null && data.id != null) {
280
+ const relModel = resolver(data);
281
+ if (includeRelMeta) {
282
+ const modelWithMeta = relModel;
283
+ modelWithMeta[REL_LINKS] = links || {};
284
+ modelWithMeta[REL_META] = meta || {};
285
+ }
286
+ model[key] = relModel;
287
+ } else if (data == null && (links != null || meta != null) && includeRelMeta) {
288
+ const relModel = { id: "" };
289
+ relModel[REL_LINKS] = links || {};
290
+ relModel[REL_META] = meta || {};
291
+ model[key] = relModel;
292
+ }
293
+ }
294
+ }
295
+ toModel(rec, type, models) {
296
+ const model = this.#createModel(rec, { models });
297
+ if (this.schemas && this.schemas[rec.type]) {
298
+ const schema = this.schemas[rec.type];
299
+ const result = validate(schema, model, this.strict);
300
+ if (!result.valid) this.validationErrors.push({
301
+ type: rec.type,
302
+ id: rec.id,
303
+ error: result.error
304
+ });
305
+ const validatedModel = result.data;
306
+ validatedModel[TYPE] = model[TYPE];
307
+ validatedModel[LINKS] = model[LINKS];
308
+ validatedModel[META] = model[META];
309
+ return validatedModel;
310
+ }
311
+ return model;
312
+ }
313
+ findRecord(type, id) {
314
+ const idStr = String(id);
315
+ return this.records.find((r) => r.type === type && String(r.id) === idStr);
316
+ }
317
+ findRecords(type) {
318
+ return this.records.filter((r) => r.type === type);
319
+ }
320
+ #findModel(type, id, models) {
321
+ const idStr = String(id);
322
+ const cached = models[type]?.[idStr];
323
+ if (cached) return cached;
324
+ const rec = this.findRecord(type, id);
325
+ if (rec == null) return null;
326
+ return this.toModel(rec, type, models);
327
+ }
328
+ find(type, id, models) {
329
+ return this.#findModel(type, id, models ?? {});
330
+ }
331
+ findAll(type, models) {
332
+ const modelsObj = models ?? {};
333
+ const recs = this.findRecords(type);
334
+ if (recs == null) return [];
335
+ recs.forEach((rec) => {
336
+ if (!modelsObj[type]) modelsObj[type] = {};
337
+ return this.toModel(rec, type, modelsObj);
338
+ });
339
+ return Object.values(modelsObj[type] || {});
340
+ }
341
+ remove(type, id) {
342
+ const removeOne = (record) => {
343
+ const index = this.records.indexOf(record);
344
+ if (!(index < 0)) this.records.splice(index, 1);
345
+ };
346
+ if (id != null) {
347
+ const record = this.findRecord(type, String(id));
348
+ if (record) removeOne(record);
349
+ } else this.findRecords(type).forEach(removeOne);
350
+ }
351
+ syncAll(body) {
352
+ this.validationErrors = [];
353
+ const previousRecords = [...this.records];
354
+ const syncData = (data) => {
355
+ if (data == null) return [];
356
+ const add = (obj) => {
357
+ const { type, id } = obj;
358
+ this.remove(type, id);
359
+ const rec = new StoreRecord(obj);
360
+ this.records.push(rec);
361
+ return rec;
362
+ };
363
+ if (Array.isArray(data)) return data.map((item) => {
364
+ if (!item.id) throw new Error(`Resource of type ${item.type} is missing an id`);
365
+ return add({
366
+ ...item,
367
+ attributes: item.attributes ?? void 0,
368
+ relationships: item.relationships ?? void 0,
369
+ id: item.id
370
+ });
371
+ });
372
+ else {
373
+ if (!data.id) throw new Error(`Resource of type ${data.type} is missing an id`);
374
+ return [add({
375
+ ...data,
376
+ attributes: data.attributes ?? void 0,
377
+ relationships: data.relationships ?? void 0,
378
+ id: data.id
379
+ })];
380
+ }
381
+ };
382
+ try {
383
+ syncData(body.included);
384
+ const recs = syncData(body.data);
385
+ const models = {};
386
+ const result = recs.map((rec) => this.toModel(rec, rec.type, models));
387
+ if (body.meta != null) result[META] = body.meta;
388
+ return result;
389
+ } catch (e) {
390
+ this.records = previousRecords;
391
+ throw e;
392
+ }
393
+ }
394
+ sync(body) {
395
+ const result = this.syncAll(body);
396
+ if (!Array.isArray(body.data) && body.data != null) {
397
+ const model = result[0];
398
+ if (result[META]) model[META] = result[META];
399
+ return model;
400
+ }
401
+ return result;
402
+ }
403
+ /**
404
+ * Build a model from a JSON:API document without storing it.
405
+ * Useful for create payloads where id may be absent.
406
+ *
407
+ * Per JSON:API spec: "The id member is not required when the resource object
408
+ * originates at the client and represents a new resource to be created on the server."
409
+ */
410
+ static build(body) {
411
+ return new Store().build(body);
412
+ }
413
+ build(body) {
414
+ const { data } = body;
415
+ if (data == null || Array.isArray(data)) throw new Error("build() expects a single resource in data, not null or an array");
416
+ return this.#createModel(data);
417
+ }
418
+ retrieve(type, body) {
419
+ const synced = this.syncAll(body);
420
+ const model = synced.find((m) => m[TYPE] === type);
421
+ if (!model) return null;
422
+ if (synced[META]) model[META] = synced[META];
423
+ return model;
424
+ }
425
+ retrieveAll(type, body) {
426
+ const synced = this.syncAll(body);
427
+ const result = synced.filter((model) => model[TYPE] === type);
428
+ result[META] = synced[META];
429
+ return result;
430
+ }
431
+ };
432
+
433
+ //#endregion
434
+ //#region src/yayson.ts
435
+ function lookupAdapter(nameOrAdapter) {
436
+ if (nameOrAdapter === "default" || !nameOrAdapter) return adapter_default;
437
+ else if (typeof nameOrAdapter === "string") if (nameOrAdapter === "sequelize") return sequelize_default;
438
+ else throw new Error("Adapter not found: " + nameOrAdapter);
439
+ return nameOrAdapter;
440
+ }
441
+ function yayson(options) {
442
+ return {
443
+ Store,
444
+ Presenter: createPresenter(lookupAdapter(options?.adapter)),
445
+ Adapter: adapter_default
446
+ };
447
+ }
448
+ var yayson_default = yayson;
449
+
450
+ //#endregion
451
+ export { validate as n, filterByFields as r, yayson_default as t };
452
+ //# sourceMappingURL=yayson-CwZg5FNt.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yayson-CwZg5FNt.mjs","names":["Adapter","#findModel","#createStub","#resolveRelationships","#createModel","Adapter","adapters.sequelize"],"sources":["../src/yayson/adapters/sequelize.ts","../src/yayson/utils.ts","../src/yayson/presenter.ts","../src/yayson/schema.ts","../src/yayson/store.ts","../src/yayson.ts"],"sourcesContent":["import Adapter, { type ModelLike } from '../adapter.js'\n\ninterface SequelizeModel {\n get(key?: string): unknown\n constructor?: {\n primaryKeys?: Record<string, unknown>\n }\n}\nfunction isSequelizeModel(model: unknown): model is SequelizeModel {\n return model != null && typeof model === 'object' && 'get' in model && typeof model.get === 'function'\n}\n\nclass SequelizeAdapter extends Adapter {\n static override get(model: ModelLike): Record<string, unknown>\n static override get(model: ModelLike, key: string): unknown\n static override get(model: ModelLike, key?: string): unknown {\n if (isSequelizeModel(model)) {\n return model.get(key)\n }\n return undefined\n }\n\n static override id(model: ModelLike): string | undefined {\n // Retain backwards compatibility with older sequelize versions\n const hasPrimaryKeys = model.constructor && 'primaryKeys' in model.constructor\n const pkFields = hasPrimaryKeys\n ? // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Access primaryKeys for Sequelize v3/v4 compatibility\n Object.keys((model.constructor as unknown as { primaryKeys: Record<string, unknown> }).primaryKeys)\n : ['id']\n\n if (pkFields.length > 1) {\n throw new Error(\n 'YAYSON does not support Sequelize models with composite primary keys. You can only use one column for your primary key. Currently using: ' +\n pkFields.join(','),\n )\n } else if (pkFields.length < 1) {\n throw new Error(\n 'YAYSON can only serialize Sequelize models which have a primary key. This is used for the JSON:API model id.',\n )\n }\n\n const id = this.get(model, pkFields[0])\n if (id == null) {\n return undefined\n }\n return `${id}`\n }\n}\n\nexport default SequelizeAdapter\n","/**\n * Filters an attributes object to only include keys in the fields array.\n * Returns the original attributes if fields is undefined.\n */\nexport function filterByFields(\n attributes: Record<string, unknown>,\n fields: string[] | undefined,\n): Record<string, unknown> {\n if (!fields) {\n return attributes\n }\n const filtered: Record<string, unknown> = {}\n for (const key of fields) {\n if (key in attributes) {\n filtered[key] = attributes[key]\n }\n }\n return filtered\n}\n","import Adapter, { ModelLike } from './adapter.js'\nimport type {\n JsonApiDocument,\n JsonApiLink,\n JsonApiLinks,\n JsonApiRelationship,\n JsonApiRelationships,\n JsonApiResource,\n JsonApiResourceIdentifier,\n PresenterOptions,\n} from './types.js'\nimport { filterByFields } from './utils.js'\n\nfunction buildLinks(link: JsonApiLink | string | null | undefined): JsonApiLink | undefined {\n if (link == null) {\n return\n }\n if (typeof link === 'object' && (link.self != null || link.related != null)) {\n return link\n } else {\n return { self: String(link) }\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -- Return type is inferred from class\nexport default function createPresenter(adapter: typeof Adapter) {\n class Presenter {\n declare ['constructor']: typeof Presenter\n\n static adapter = adapter\n static type = 'objects'\n static fields?: string[]\n\n scope: JsonApiDocument\n\n constructor(scope?: JsonApiDocument) {\n this.scope = scope ?? { data: null }\n }\n\n id(instance: ModelLike): string | undefined {\n return this.constructor.adapter.id(instance)\n }\n\n selfLinks(_instance: ModelLike): JsonApiLink | string | undefined {\n return undefined\n }\n\n links(_instance?: ModelLike): JsonApiLinks | undefined {\n return undefined\n }\n\n relationships(): Record<string, typeof Presenter> {\n return {}\n }\n\n attributes(instance: ModelLike | null): Record<string, unknown> {\n if (instance == null) {\n return {}\n }\n const attributes = { ...this.constructor.adapter.get(instance) }\n delete attributes['id']\n\n const relationships = this.relationships()\n if (relationships) {\n for (const key in relationships) {\n delete attributes[key]\n }\n }\n\n return filterByFields(attributes, this.constructor.fields)\n }\n\n includeRelationships(scope: JsonApiDocument, instance: ModelLike): unknown[] {\n const relationships = this.relationships()\n const result: unknown[] = []\n if (!relationships) {\n return result\n }\n\n for (const key in relationships) {\n const factory = relationships[key]\n if (!factory) throw new Error(`Presenter for ${key} in ${this.constructor.type} is not defined`)\n\n const presenter = new factory(scope)\n\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- unknown from adapter.get\n const data = this.constructor.adapter.get(instance, key) as ModelLike | ModelLike[] | null\n result.push(presenter.toJSON(data, { include: true }))\n }\n return result\n }\n\n buildRelationships(instance: ModelLike | null): JsonApiRelationships | null {\n if (instance == null) {\n return null\n }\n const rels = this.relationships()\n const links = this.links(instance) || {}\n let relationships: JsonApiRelationships | null = null\n\n if (!rels) {\n return null\n }\n\n for (const key in rels) {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- unknown from adapter.get\n const data = this.constructor.adapter.get(instance, key) as ModelLike | ModelLike[] | null | undefined\n const presenter = rels[key]\n const buildData = (d: ModelLike): JsonApiResourceIdentifier => {\n const id = this.constructor.adapter.id(d)\n if (!id) {\n throw new Error(\n `Model of type ${presenter.type} is missing an id (relationship '${key}' of ${this.constructor.type})`,\n )\n }\n return {\n id,\n type: presenter.type,\n }\n }\n const build = (d: ModelLike | null | undefined): JsonApiRelationship => {\n const rel: JsonApiRelationship = {}\n if (d != null) {\n rel.data = buildData(d)\n }\n if (links[key] != null) {\n rel.links = buildLinks(links[key])\n } else if (d == null) {\n rel.data = null\n }\n return rel\n }\n if (!relationships) {\n relationships = {}\n }\n if (!relationships[key]) {\n relationships[key] = {}\n }\n if (Array.isArray(data)) {\n relationships[key].data = data.map(buildData)\n if (links[key] != null) {\n relationships[key].links = buildLinks(links[key])\n }\n } else {\n relationships[key] = build(data)\n }\n }\n return relationships\n }\n\n buildSelfLink(instance: ModelLike): JsonApiLink | undefined {\n return buildLinks(this.selfLinks(instance))\n }\n\n toJSON(\n instanceOrCollection: ModelLike | ModelLike[] | null | undefined,\n options?: PresenterOptions,\n ): JsonApiDocument {\n const opts = options ?? {}\n if (opts.meta != null) {\n this.scope.meta = opts.meta\n }\n if (opts.links != null) {\n this.scope.links = opts.links\n }\n if (!this.scope.data) {\n this.scope.data = null\n }\n\n if (instanceOrCollection == null) {\n return this.scope\n }\n\n if (Array.isArray(instanceOrCollection)) {\n const collection = instanceOrCollection\n if (!this.scope.data) {\n this.scope.data = []\n }\n collection.forEach((instance: ModelLike) => {\n return this.toJSON(instance, options)\n })\n } else {\n const instance = instanceOrCollection\n let added = true\n const model: JsonApiResource = {\n id: this.id(instance),\n type: this.constructor.type,\n attributes: this.attributes(instance),\n }\n if (model.id === undefined) {\n delete model.id\n }\n const relationships = this.buildRelationships(instance)\n if (relationships != null) {\n model.relationships = relationships\n }\n const links = this.buildSelfLink(instance)\n if (links != null) {\n model.links = links\n }\n\n if (opts.include) {\n if (!this.scope.included) {\n this.scope.included = []\n }\n const allResources = (this.scope.included || []).concat(\n Array.isArray(this.scope.data) ? this.scope.data : this.scope.data ? [this.scope.data] : [],\n )\n if (!allResources.some((i) => i.id === model.id && i.type === model.type)) {\n this.scope.included.push(model)\n } else {\n added = false\n }\n } else if (this.scope.data != null) {\n if (Array.isArray(this.scope.data)) {\n if (!this.scope.data.some((i) => i.id === model.id && i.type === model.type)) {\n this.scope.data.push(model)\n } else {\n added = false\n }\n } else {\n // data is a single object, convert to array if needed\n this.scope.data = model\n }\n } else {\n this.scope.data = model\n }\n\n if (added) {\n this.includeRelationships(this.scope, instance)\n }\n }\n return this.scope\n }\n\n payload(instance: ModelLike, options?: PresenterOptions): JsonApiDocument {\n if (Array.isArray(instance)) {\n throw new Error('payload() expects a single resource, not an array')\n }\n if (instance == null) {\n throw new Error('payload() requires a resource, got null')\n }\n const model: JsonApiResource = {\n type: this.constructor.type,\n attributes: this.attributes(instance),\n }\n const id = this.id(instance)\n if (id != null) {\n model.id = id\n }\n const relationships = this.buildRelationships(instance)\n if (relationships != null) {\n model.relationships = relationships\n }\n const result: JsonApiDocument = { data: model }\n const opts = options ?? {}\n if (opts.meta != null) result.meta = opts.meta\n if (opts.links != null) result.links = opts.links\n return result\n }\n\n render(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument {\n return this.toJSON(instanceOrCollection, options)\n }\n\n static toJSON(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument {\n return new this().toJSON(instanceOrCollection, options)\n }\n\n static render(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument {\n return new this().render(instanceOrCollection, options)\n }\n\n static payload(instance: ModelLike, options?: PresenterOptions): JsonApiDocument {\n return new this().payload(instance, options)\n }\n }\n\n return Presenter\n}\n\nexport type Presenter = ReturnType<typeof createPresenter>\n","/**\n * Interface for Zod-like schema objects.\n * Any schema library that implements `parse` and `safeParse` methods will work.\n */\nexport interface ZodLikeSchema {\n parse: (data: unknown) => unknown\n safeParse: (data: unknown) => { success: true; data: unknown } | { success: false; error: unknown }\n}\n\nexport function isZodLikeSchema(schema: unknown): schema is ZodLikeSchema {\n return (\n schema != null &&\n typeof schema === 'object' &&\n 'parse' in schema &&\n typeof schema.parse === 'function' &&\n 'safeParse' in schema &&\n typeof schema.safeParse === 'function'\n )\n}\n\nexport interface ValidationResult {\n valid: boolean\n data: unknown\n error?: unknown\n}\n\nexport function validate(schema: unknown, data: unknown, strict: boolean): ValidationResult {\n if (!isZodLikeSchema(schema)) {\n throw new Error('Invalid schema: must have parse and safeParse methods')\n }\n\n if (strict) {\n const validData = schema.parse(data)\n return { valid: true, data: validData }\n } else {\n const result = schema.safeParse(data)\n if (result.success) {\n return { valid: true, data: result.data }\n } else {\n return { valid: false, data, error: result.error }\n }\n }\n}\n","import type {\n InferModelType,\n JsonApiDocument,\n JsonApiLink,\n JsonApiRelationships,\n JsonApiResourceIdentifier,\n SchemaRegistry,\n StoreModel,\n StoreModelWithOptionalId,\n StoreModels,\n StoreOptions,\n StoreRecord as StoreRecordType,\n StoreResult,\n ValidationError,\n} from './types.js'\nimport { TYPE, LINKS, META, REL_LINKS, REL_META } from './symbols.js'\nimport { validate } from './schema.js'\n\nfunction hasId<T extends StoreModelWithOptionalId>(model: T): model is T & { id: string | number } {\n return model.id != null\n}\n\nclass StoreRecord implements StoreRecordType {\n id: string | number\n type: string\n attributes?: Record<string, unknown>\n relationships?: JsonApiRelationships\n links?: JsonApiLink\n meta?: Record<string, unknown>\n\n constructor(options: StoreRecordType) {\n this.id = options.id\n this.type = options.type\n this.attributes = options.attributes\n this.relationships = options.relationships\n this.links = options.links\n this.meta = options.meta\n }\n}\n\nexport default class Store<S extends SchemaRegistry = SchemaRegistry> {\n records: StoreRecord[] = []\n schemas?: S\n strict: boolean\n validationErrors: ValidationError[] = []\n\n constructor(options?: StoreOptions<S>) {\n this.schemas = options?.schemas\n this.strict = options?.strict ?? false\n this.reset()\n }\n\n reset(): void {\n this.records = []\n this.validationErrors = []\n }\n\n #createStub(type: string, id: string | number): StoreModel {\n const stub: StoreModel = { id }\n stub[TYPE] = type\n return stub\n }\n\n #createModel(\n resource: {\n type: string\n id?: string | number | null\n attributes?: Record<string, unknown> | null\n relationships?: JsonApiRelationships | null\n meta?: Record<string, unknown> | null\n links?: JsonApiLink | null\n },\n options?: {\n models?: StoreModels\n includeRelMeta?: boolean\n },\n ): StoreModelWithOptionalId {\n const models = options?.models ?? {}\n\n const model: StoreModelWithOptionalId = { ...(resource.attributes || {}) }\n if (resource.id != null) {\n model.id = resource.id\n }\n const type = resource.type\n model[TYPE] = type\n if (resource.meta != null) {\n model[META] = resource.meta\n }\n if (resource.links != null) {\n model[LINKS] = resource.links\n }\n\n // Cache before resolving relationships (for circular refs)\n if (hasId(model)) {\n const idStr = String(model.id)\n if (!models[type]) {\n models[type] = {}\n }\n if (!models[type][idStr]) {\n models[type][idStr] = model\n }\n }\n\n if (resource.relationships != null) {\n const resolver = (ref: JsonApiResourceIdentifier): StoreModel => {\n return this.#findModel(ref.type, ref.id, models) ?? this.#createStub(ref.type, ref.id)\n }\n this.#resolveRelationships(model, resource.relationships, resolver, {\n includeRelMeta: options?.includeRelMeta,\n })\n }\n return model\n }\n\n #resolveRelationships(\n model: StoreModel | StoreModelWithOptionalId,\n relationships: JsonApiRelationships,\n resolver: (ref: JsonApiResourceIdentifier) => StoreModel | StoreModelWithOptionalId,\n options?: { includeRelMeta?: boolean },\n ): void {\n const includeRelMeta = options?.includeRelMeta ?? true\n\n for (const key in relationships) {\n const rel = relationships[key]\n const { data, links, meta } = rel\n\n model[key] = null\n if (data == null && links == null) {\n continue\n }\n\n if (Array.isArray(data)) {\n model[key] = data.filter((item) => item.id != null).map(resolver)\n } else if (data != null && data.id != null) {\n const relModel = resolver(data)\n if (includeRelMeta) {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- REL_LINKS/REL_META only used when resolver returns StoreModel\n const modelWithMeta = relModel as StoreModel\n modelWithMeta[REL_LINKS] = links || {}\n modelWithMeta[REL_META] = meta || {}\n }\n model[key] = relModel\n } else if (data == null && (links != null || meta != null) && includeRelMeta) {\n const relModel: StoreModel = { id: '' }\n relModel[REL_LINKS] = links || {}\n relModel[REL_META] = meta || {}\n model[key] = relModel\n }\n }\n }\n\n toModel(rec: StoreRecord, type: string, models: StoreModels): StoreModel {\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- StoreRecord always has id\n const model = this.#createModel(rec, { models }) as StoreModel\n\n // Validate with schema if provided\n if (this.schemas && this.schemas[rec.type]) {\n const schema = this.schemas[rec.type]\n const result = validate(schema, model, this.strict)\n\n if (!result.valid) {\n this.validationErrors.push({\n type: rec.type,\n id: rec.id,\n error: result.error,\n })\n }\n\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Schema validation returns unknown, cast to StoreModel after validation\n const validatedModel = result.data as StoreModel\n\n // Preserve symbol keys from original model (schema validation may not preserve them)\n validatedModel[TYPE] = model[TYPE]\n validatedModel[LINKS] = model[LINKS]\n validatedModel[META] = model[META]\n\n return validatedModel\n }\n\n return model\n }\n\n findRecord(type: string, id: string | number): StoreRecord | undefined {\n const idStr = String(id)\n return this.records.find((r) => r.type === type && String(r.id) === idStr)\n }\n\n findRecords(type: string): StoreRecord[] {\n return this.records.filter((r) => r.type === type)\n }\n\n #findModel(type: string, id: string | number, models: StoreModels): StoreModel | null {\n const idStr = String(id)\n const cached = models[type]?.[idStr]\n if (cached) {\n return cached\n }\n const rec = this.findRecord(type, id)\n if (rec == null) {\n return null\n }\n return this.toModel(rec, type, models)\n }\n\n find<T extends string>(type: T, id: string | number, models?: StoreModels): InferModelType<S, T> | null {\n const result = this.#findModel(type, id, models ?? {})\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Enable type inference from schema registry\n return result as InferModelType<S, T> | null\n }\n\n findAll<T extends string>(type: T, models?: StoreModels): InferModelType<S, T>[] {\n const modelsObj = models ?? {}\n const recs = this.findRecords(type)\n if (recs == null) {\n return []\n }\n recs.forEach((rec) => {\n if (!modelsObj[type]) {\n modelsObj[type] = {}\n }\n return this.toModel(rec, type, modelsObj)\n })\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Enable type inference from schema registry\n return Object.values(modelsObj[type] || {}) as InferModelType<S, T>[]\n }\n\n remove(type: string, id?: string | number): void {\n const removeOne = (record: StoreRecord): void => {\n const index = this.records.indexOf(record)\n if (!(index < 0)) {\n this.records.splice(index, 1)\n }\n }\n\n if (id != null) {\n const record = this.findRecord(type, String(id))\n if (record) {\n removeOne(record)\n }\n } else {\n this.findRecords(type).forEach(removeOne)\n }\n }\n\n syncAll(body: JsonApiDocument): StoreResult {\n // Clear previous validation errors\n this.validationErrors = []\n\n // Snapshot for rollback if strict validation throws\n const previousRecords = [...this.records]\n\n const syncData = (data: JsonApiDocument['data'] | JsonApiDocument['included']): StoreRecord[] => {\n if (data == null) {\n return []\n }\n const add = (obj: StoreRecordType): StoreRecord => {\n const { type, id } = obj\n this.remove(type, id)\n const rec = new StoreRecord(obj)\n this.records.push(rec)\n return rec\n }\n\n if (Array.isArray(data)) {\n return data.map((item) => {\n if (!item.id) {\n throw new Error(`Resource of type ${item.type} is missing an id`)\n }\n return add({\n ...item,\n attributes: item.attributes ?? undefined,\n relationships: item.relationships ?? undefined,\n id: item.id,\n })\n })\n } else {\n if (!data.id) {\n throw new Error(`Resource of type ${data.type} is missing an id`)\n }\n return [\n add({\n ...data,\n attributes: data.attributes ?? undefined,\n relationships: data.relationships ?? undefined,\n id: data.id,\n }),\n ]\n }\n }\n\n try {\n syncData(body.included)\n const recs = syncData(body.data)\n\n const models: StoreModels = {}\n const result: StoreResult = recs.map((rec) => this.toModel(rec, rec.type, models))\n if (body.meta != null) {\n result[META] = body.meta\n }\n return result\n } catch (e) {\n this.records = previousRecords\n throw e\n }\n }\n\n sync(body: JsonApiDocument): StoreModel | StoreResult {\n const result = this.syncAll(body)\n if (!Array.isArray(body.data) && body.data != null) {\n const model = result[0]\n if (result[META]) {\n model[META] = result[META]\n }\n return model\n }\n return result\n }\n\n /**\n * Build a model from a JSON:API document without storing it.\n * Useful for create payloads where id may be absent.\n *\n * Per JSON:API spec: \"The id member is not required when the resource object\n * originates at the client and represents a new resource to be created on the server.\"\n */\n static build(body: JsonApiDocument): StoreModelWithOptionalId {\n return new Store().build(body)\n }\n\n build(body: JsonApiDocument): StoreModelWithOptionalId {\n const { data } = body\n if (data == null || Array.isArray(data)) {\n throw new Error('build() expects a single resource in data, not null or an array')\n }\n return this.#createModel(data)\n }\n\n retrieve<T extends string>(type: T, body: JsonApiDocument): InferModelType<S, T> | null {\n const synced = this.syncAll(body)\n const model = synced.find((m) => m[TYPE] === type)\n if (!model) return null\n if (synced[META]) {\n model[META] = synced[META]\n }\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Enable type inference from type parameter\n return model as InferModelType<S, T>\n }\n\n retrieveAll<T extends string>(type: T, body: JsonApiDocument): StoreResult<InferModelType<S, T>> {\n const synced = this.syncAll(body)\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Enable type inference from type parameter\n const result: StoreResult<InferModelType<S, T>> = synced.filter((model) => model[TYPE] === type) as StoreResult<\n InferModelType<S, T>\n >\n result[META] = synced[META]\n return result\n }\n}\n","import Adapter from './yayson/adapter.js'\nimport * as adapters from './yayson/adapters/index.js'\nimport createPresenter, { Presenter } from './yayson/presenter.js'\nimport Store from './yayson/store.js'\nimport type {\n JsonApiDocument,\n JsonApiLink,\n JsonApiLinks,\n JsonApiRelationship,\n JsonApiRelationships,\n JsonApiResource,\n LegacyStoreOptions,\n PresenterOptions,\n SchemaRegistry,\n StoreOptions,\n ValidationError,\n} from './yayson/types.js'\nimport type { ZodLikeSchema } from './yayson/schema.js'\n\ntype AdapterOption = string | typeof Adapter\n\ninterface YaysonOptions {\n adapter?: AdapterOption\n}\n\ninterface YaysonResult {\n Store: typeof Store\n Presenter: Presenter\n Adapter: typeof Adapter\n}\n\nfunction lookupAdapter(nameOrAdapter?: AdapterOption): typeof Adapter {\n if (nameOrAdapter === 'default' || !nameOrAdapter) {\n return Adapter\n } else if (typeof nameOrAdapter === 'string') {\n if (nameOrAdapter === 'sequelize') {\n return adapters.sequelize\n } else {\n throw new Error('Adapter not found: ' + nameOrAdapter)\n }\n }\n return nameOrAdapter\n}\n\nfunction yayson(options?: YaysonOptions): YaysonResult {\n const adapter = lookupAdapter(options?.adapter)\n const Presenter = createPresenter(adapter)\n\n return {\n Store,\n Presenter,\n Adapter,\n }\n}\n\nexport default yayson\nexport type {\n Adapter,\n JsonApiDocument,\n JsonApiLink,\n JsonApiLinks,\n JsonApiRelationship,\n JsonApiRelationships,\n JsonApiResource,\n LegacyStoreOptions,\n PresenterOptions,\n SchemaRegistry,\n StoreOptions,\n ValidationError,\n YaysonOptions,\n YaysonResult,\n ZodLikeSchema,\n}\n"],"mappings":";;;AAQA,SAAS,iBAAiB,OAAyC;AACjE,QAAO,SAAS,QAAQ,OAAO,UAAU,YAAY,SAAS,SAAS,OAAO,MAAM,QAAQ;;AAG9F,IAAM,mBAAN,cAA+BA,gBAAQ;CAGrC,OAAgB,IAAI,OAAkB,KAAuB;AAC3D,MAAI,iBAAiB,MAAM,CACzB,QAAO,MAAM,IAAI,IAAI;;CAKzB,OAAgB,GAAG,OAAsC;EAGvD,MAAM,WADiB,MAAM,eAAe,iBAAiB,MAAM,cAG/D,OAAO,KAAM,MAAM,YAAoE,YAAY,GACnG,CAAC,KAAK;AAEV,MAAI,SAAS,SAAS,EACpB,OAAM,IAAI,MACR,8IACE,SAAS,KAAK,IAAI,CACrB;WACQ,SAAS,SAAS,EAC3B,OAAM,IAAI,MACR,+GACD;EAGH,MAAM,KAAK,KAAK,IAAI,OAAO,SAAS,GAAG;AACvC,MAAI,MAAM,KACR;AAEF,SAAO,GAAG;;;AAId,wBAAe;;;;;;;;AC7Cf,SAAgB,eACd,YACA,QACyB;AACzB,KAAI,CAAC,OACH,QAAO;CAET,MAAM,WAAoC,EAAE;AAC5C,MAAK,MAAM,OAAO,OAChB,KAAI,OAAO,WACT,UAAS,OAAO,WAAW;AAG/B,QAAO;;;;;ACJT,SAAS,WAAW,MAAwE;AAC1F,KAAI,QAAQ,KACV;AAEF,KAAI,OAAO,SAAS,aAAa,KAAK,QAAQ,QAAQ,KAAK,WAAW,MACpE,QAAO;KAEP,QAAO,EAAE,MAAM,OAAO,KAAK,EAAE;;AAKjC,SAAwB,gBAAgB,SAAyB;CAC/D,MAAM,UAAU;EAGd,OA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