yayson 2.1.0 → 4.0.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 (51) hide show
  1. package/README.md +475 -104
  2. package/build/legacy.cjs +278 -0
  3. package/build/legacy.d.cts +105 -0
  4. package/build/legacy.d.cts.map +1 -0
  5. package/build/legacy.d.mts +105 -0
  6. package/build/legacy.d.mts.map +1 -0
  7. package/build/legacy.mjs +279 -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-BsfPiPEw.d.mts +122 -0
  13. package/build/types-BsfPiPEw.d.mts.map +1 -0
  14. package/build/types-DbMIe8E2.d.cts +122 -0
  15. package/build/types-DbMIe8E2.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-BJv2Z0Z6.mjs +391 -0
  24. package/build/yayson-BJv2Z0Z6.mjs.map +1 -0
  25. package/build/yayson-BKEyEcGk.d.cts +69 -0
  26. package/build/yayson-BKEyEcGk.d.cts.map +1 -0
  27. package/build/yayson-CRbukIqr.d.mts +69 -0
  28. package/build/yayson-CRbukIqr.d.mts.map +1 -0
  29. package/build/yayson-CUfrxK9d.cjs +407 -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 +74 -33
  35. package/skill/yayson/SKILL.md +233 -0
  36. package/skill/yayson/references/api.md +266 -0
  37. package/.circleci/config.yml +0 -35
  38. package/.github/workflows/node.js.yml +0 -30
  39. package/.mocharc.js +0 -15
  40. package/RELEASE.md +0 -3
  41. package/bower.json +0 -31
  42. package/coffeelint.json +0 -120
  43. package/gulpfile.coffee +0 -43
  44. package/lib/yayson/adapter.js +0 -22
  45. package/lib/yayson/adapters/index.js +0 -3
  46. package/lib/yayson/adapters/sequelize.js +0 -14
  47. package/lib/yayson/presenter.js +0 -209
  48. package/lib/yayson/store.js +0 -169
  49. package/lib/yayson/utils.js +0 -47
  50. package/lib/yayson.js +0 -53
  51. package/tags +0 -59
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DbMIe8E2.d.cts","names":[],"sources":["../../../../../../yayson/adapter.ts","../../../../../../yayson/symbols.ts","../../../../../../yayson/schema.ts","../../../../../../yayson/types.ts"],"mappings":";KAAY,SAAA;AAAA,cAEN,OAAA;EAAA,OACG,GAAA,CAAI,KAAA,EAAO,SAAA,GAAY,MAAA;EAAA,OACvB,GAAA,CAAI,KAAA,EAAO,SAAA,EAAW,GAAA;EAAA,OAUtB,EAAA,CAAG,KAAA,EAAO,SAAA;AAAA;;;cCdN,IAAA;AAAA,cACA,KAAA;AAAA,cACA,IAAA;AAAA,cACA,SAAA;AAAA,cACA,QAAA;;;;ADJb;;;UEIiB,aAAA;EACf,KAAA,GAAQ,IAAA;EACR,SAAA,GAAY,IAAA;IAAoB,OAAA;IAAe,IAAA;EAAA;IAAoB,OAAA;IAAgB,KAAA;EAAA;AAAA;;;UCHpE,WAAA,SAAoB,MAAA;EACnC,IAAA;EACA,OAAA;AAAA;AAAA,UAGe,YAAA;EAAA,CACd,GAAA,WAAc,WAAA;AAAA;AAAA,UAGA,yBAAA;EACf,EAAA;EACA,IAAA;AAAA;AAAA,UAGe,mBAAA;EACf,IAAA,GAAO,yBAAA,GAA4B,yBAAA;EACnC,KAAA,GAAQ,WAAA;EACR,IAAA,GAAO,MAAA;AAAA;AAAA,UAGQ,oBAAA;EAAA,CACd,GAAA,WAAc,mBAAA;AAAA;AAAA,UAGA,eAAA;EACf,EAAA;EACA,IAAA;EAC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;AAAA,UAGe,eAAA;EACf,IAAA;EACA,EAAA;EACA,KAAA;AAAA;AAAA,UAGe,kBAAA,WAA6B,cAAA,GAAiB,cAAA;EAC7D,KAAA,GAAQ,MAAA;EACR,OAAA,GAAU,CAAA;EACV,MAAA;AAAA"}
@@ -0,0 +1,31 @@
1
+ const require_symbols = require('./symbols-nFs99aEX.cjs');
2
+
3
+ //#region src/utils.ts
4
+ function getType(model) {
5
+ return model[require_symbols.TYPE];
6
+ }
7
+ function getLinks(model) {
8
+ return model[require_symbols.LINKS];
9
+ }
10
+ function getMeta(model) {
11
+ return model[require_symbols.META];
12
+ }
13
+ function getRelationshipLinks(model) {
14
+ return model[require_symbols.REL_LINKS];
15
+ }
16
+ function getRelationshipMeta(model) {
17
+ return model[require_symbols.REL_META];
18
+ }
19
+
20
+ //#endregion
21
+ exports.Adapter = require_symbols.adapter_default;
22
+ exports.LINKS = require_symbols.LINKS;
23
+ exports.META = require_symbols.META;
24
+ exports.REL_LINKS = require_symbols.REL_LINKS;
25
+ exports.REL_META = require_symbols.REL_META;
26
+ exports.TYPE = require_symbols.TYPE;
27
+ exports.getLinks = getLinks;
28
+ exports.getMeta = getMeta;
29
+ exports.getRelationshipLinks = getRelationshipLinks;
30
+ exports.getRelationshipMeta = getRelationshipMeta;
31
+ exports.getType = getType;
@@ -0,0 +1,11 @@
1
+ import { C as TYPE, S as REL_META, T as ModelLike, b as META, f as StoreModel, r as JsonApiLink, w as Adapter, x as REL_LINKS, y as LINKS } from "./types-DbMIe8E2.cjs";
2
+
3
+ //#region src/utils.d.ts
4
+ declare function getType(model: StoreModel): string | undefined;
5
+ declare function getLinks(model: StoreModel): JsonApiLink | undefined;
6
+ declare function getMeta(model: StoreModel): Record<string, unknown> | undefined;
7
+ declare function getRelationshipLinks(model: StoreModel): JsonApiLink | undefined;
8
+ declare function getRelationshipMeta(model: StoreModel): Record<string, unknown> | undefined;
9
+ //#endregion
10
+ export { Adapter, LINKS, META, type ModelLike, REL_LINKS, REL_META, TYPE, getLinks, getMeta, getRelationshipLinks, getRelationshipMeta, getType };
11
+ //# sourceMappingURL=utils.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.cts","names":[],"sources":["../../../../../../utils.ts"],"mappings":";;;iBAMgB,OAAA,CAAQ,KAAA,EAAO,UAAA;AAAA,iBAIf,QAAA,CAAS,KAAA,EAAO,UAAA,GAAa,WAAA;AAAA,iBAI7B,OAAA,CAAQ,KAAA,EAAO,UAAA,GAAa,MAAA;AAAA,iBAI5B,oBAAA,CAAqB,KAAA,EAAO,UAAA,GAAa,WAAA;AAAA,iBAIzC,mBAAA,CAAoB,KAAA,EAAO,UAAA,GAAa,MAAA"}
@@ -0,0 +1,11 @@
1
+ import { C as TYPE, S as REL_META, T as ModelLike, b as META, f as StoreModel, r as JsonApiLink, w as Adapter, x as REL_LINKS, y as LINKS } from "./types-BsfPiPEw.mjs";
2
+
3
+ //#region src/utils.d.ts
4
+ declare function getType(model: StoreModel): string | undefined;
5
+ declare function getLinks(model: StoreModel): JsonApiLink | undefined;
6
+ declare function getMeta(model: StoreModel): Record<string, unknown> | undefined;
7
+ declare function getRelationshipLinks(model: StoreModel): JsonApiLink | undefined;
8
+ declare function getRelationshipMeta(model: StoreModel): Record<string, unknown> | undefined;
9
+ //#endregion
10
+ export { Adapter, LINKS, META, type ModelLike, REL_LINKS, REL_META, TYPE, getLinks, getMeta, getRelationshipLinks, getRelationshipMeta, getType };
11
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","names":[],"sources":["../../../../../../utils.ts"],"mappings":";;;iBAMgB,OAAA,CAAQ,KAAA,EAAO,UAAA;AAAA,iBAIf,QAAA,CAAS,KAAA,EAAO,UAAA,GAAa,WAAA;AAAA,iBAI7B,OAAA,CAAQ,KAAA,EAAO,UAAA,GAAa,MAAA;AAAA,iBAI5B,oBAAA,CAAqB,KAAA,EAAO,UAAA,GAAa,WAAA;AAAA,iBAIzC,mBAAA,CAAoB,KAAA,EAAO,UAAA,GAAa,MAAA"}
@@ -0,0 +1,22 @@
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/utils.ts
4
+ function getType(model) {
5
+ return model[TYPE];
6
+ }
7
+ function getLinks(model) {
8
+ return model[LINKS];
9
+ }
10
+ function getMeta(model) {
11
+ return model[META];
12
+ }
13
+ function getRelationshipLinks(model) {
14
+ return model[REL_LINKS];
15
+ }
16
+ function getRelationshipMeta(model) {
17
+ return model[REL_META];
18
+ }
19
+
20
+ //#endregion
21
+ export { adapter_default as Adapter, LINKS, META, REL_LINKS, REL_META, TYPE, getLinks, getMeta, getRelationshipLinks, getRelationshipMeta, getType };
22
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import { TYPE, LINKS, META, REL_LINKS, REL_META } from './yayson/symbols.js'\nimport type { StoreModel, JsonApiLink } from './yayson/types.js'\n\nexport { default as Adapter, type ModelLike } from './yayson/adapter.js'\nexport { TYPE, LINKS, META, REL_LINKS, REL_META }\n\nexport function getType(model: StoreModel): string | undefined {\n return model[TYPE]\n}\n\nexport function getLinks(model: StoreModel): JsonApiLink | undefined {\n return model[LINKS]\n}\n\nexport function getMeta(model: StoreModel): Record<string, unknown> | undefined {\n return model[META]\n}\n\nexport function getRelationshipLinks(model: StoreModel): JsonApiLink | undefined {\n return model[REL_LINKS]\n}\n\nexport function getRelationshipMeta(model: StoreModel): Record<string, unknown> | undefined {\n return model[REL_META]\n}\n"],"mappings":";;;AAMA,SAAgB,QAAQ,OAAuC;AAC7D,QAAO,MAAM;;AAGf,SAAgB,SAAS,OAA4C;AACnE,QAAO,MAAM;;AAGf,SAAgB,QAAQ,OAAwD;AAC9E,QAAO,MAAM;;AAGf,SAAgB,qBAAqB,OAA4C;AAC/E,QAAO,MAAM;;AAGf,SAAgB,oBAAoB,OAAwD;AAC1F,QAAO,MAAM"}
@@ -0,0 +1,391 @@
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 === void 0) return id;
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
+ render(instanceOrCollection, options) {
154
+ return this.toJSON(instanceOrCollection, options);
155
+ }
156
+ static toJSON(instanceOrCollection, options) {
157
+ return new this().toJSON(instanceOrCollection, options);
158
+ }
159
+ static render(instanceOrCollection, options) {
160
+ return new this().render(instanceOrCollection, options);
161
+ }
162
+ }
163
+ return Presenter;
164
+ }
165
+
166
+ //#endregion
167
+ //#region src/yayson/schema.ts
168
+ function isZodLikeSchema(schema) {
169
+ return schema != null && typeof schema === "object" && "parse" in schema && typeof schema.parse === "function" && "safeParse" in schema && typeof schema.safeParse === "function";
170
+ }
171
+ function validate(schema, data, strict) {
172
+ if (!isZodLikeSchema(schema)) throw new Error("Invalid schema: must have parse and safeParse methods");
173
+ if (strict) return {
174
+ valid: true,
175
+ data: schema.parse(data)
176
+ };
177
+ else {
178
+ const result = schema.safeParse(data);
179
+ if (result.success) return {
180
+ valid: true,
181
+ data: result.data
182
+ };
183
+ else return {
184
+ valid: false,
185
+ data,
186
+ error: result.error
187
+ };
188
+ }
189
+ }
190
+
191
+ //#endregion
192
+ //#region src/yayson/store.ts
193
+ var StoreRecord = class {
194
+ id;
195
+ type;
196
+ attributes;
197
+ relationships;
198
+ links;
199
+ meta;
200
+ constructor(options) {
201
+ this.id = options.id;
202
+ this.type = options.type;
203
+ this.attributes = options.attributes;
204
+ this.relationships = options.relationships;
205
+ this.links = options.links;
206
+ this.meta = options.meta;
207
+ }
208
+ };
209
+ var Store = class {
210
+ records = [];
211
+ schemas;
212
+ strict;
213
+ validationErrors = [];
214
+ constructor(options) {
215
+ this.schemas = options?.schemas;
216
+ this.strict = options?.strict ?? false;
217
+ this.reset();
218
+ }
219
+ reset() {
220
+ this.records = [];
221
+ this.validationErrors = [];
222
+ }
223
+ toModel(rec, type, models) {
224
+ const model = {
225
+ ...rec.attributes || {},
226
+ id: rec.id
227
+ };
228
+ model[TYPE] = rec.type;
229
+ const idStr = String(rec.id);
230
+ if (!models[type]) models[type] = {};
231
+ if (!models[type][idStr]) models[type][idStr] = model;
232
+ if (rec.meta != null) model[META] = rec.meta;
233
+ if (rec.links != null) model[LINKS] = rec.links;
234
+ if (rec.relationships != null) for (const key in rec.relationships) {
235
+ const rel = rec.relationships[key];
236
+ const { data } = rel;
237
+ const { links } = rel;
238
+ const { meta } = rel;
239
+ model[key] = null;
240
+ if (data == null && links == null) continue;
241
+ const resolve = ({ type: type$1, id }) => {
242
+ return this.find(type$1, id, models);
243
+ };
244
+ if (Array.isArray(data)) model[key] = data.map(resolve);
245
+ else {
246
+ const relModel = data != null ? resolve(data) : { id: "" };
247
+ if (relModel) {
248
+ relModel[REL_LINKS] = links || {};
249
+ relModel[REL_META] = meta || {};
250
+ model[key] = relModel;
251
+ }
252
+ }
253
+ }
254
+ if (this.schemas && this.schemas[rec.type]) {
255
+ const schema = this.schemas[rec.type];
256
+ const result = validate(schema, model, this.strict);
257
+ if (!result.valid) this.validationErrors.push({
258
+ type: rec.type,
259
+ id: rec.id,
260
+ error: result.error
261
+ });
262
+ const validatedModel = result.data;
263
+ validatedModel[TYPE] = model[TYPE];
264
+ validatedModel[LINKS] = model[LINKS];
265
+ validatedModel[META] = model[META];
266
+ return validatedModel;
267
+ }
268
+ return model;
269
+ }
270
+ findRecord(type, id) {
271
+ const idStr = String(id);
272
+ return this.records.find((r) => r.type === type && String(r.id) === idStr);
273
+ }
274
+ findRecords(type) {
275
+ return this.records.filter((r) => r.type === type);
276
+ }
277
+ find(type, id, models) {
278
+ const modelsObj = models ?? {};
279
+ const idStr = String(id);
280
+ const rec = this.findRecord(type, idStr);
281
+ if (rec == null) return null;
282
+ if (!modelsObj[type]) modelsObj[type] = {};
283
+ return modelsObj[type][idStr] || this.toModel(rec, type, modelsObj);
284
+ }
285
+ findAll(type, models) {
286
+ const modelsObj = models ?? {};
287
+ const recs = this.findRecords(type);
288
+ if (recs == null) return [];
289
+ recs.forEach((rec) => {
290
+ if (!modelsObj[type]) modelsObj[type] = {};
291
+ return this.toModel(rec, type, modelsObj);
292
+ });
293
+ return Object.values(modelsObj[type] || {});
294
+ }
295
+ remove(type, id) {
296
+ const removeOne = (record) => {
297
+ const index = this.records.indexOf(record);
298
+ if (!(index < 0)) this.records.splice(index, 1);
299
+ };
300
+ if (id != null) {
301
+ const record = this.findRecord(type, String(id));
302
+ if (record) removeOne(record);
303
+ } else this.findRecords(type).forEach(removeOne);
304
+ }
305
+ syncAll(body) {
306
+ this.validationErrors = [];
307
+ const previousRecords = [...this.records];
308
+ const syncData = (data) => {
309
+ if (data == null) return [];
310
+ const add = (obj) => {
311
+ const { type, id } = obj;
312
+ this.remove(type, id);
313
+ const rec = new StoreRecord(obj);
314
+ this.records.push(rec);
315
+ return rec;
316
+ };
317
+ if (Array.isArray(data)) return data.map((item) => {
318
+ if (!item.id) throw new Error(`Resource of type ${item.type} is missing an id`);
319
+ return add({
320
+ ...item,
321
+ attributes: item.attributes ?? void 0,
322
+ relationships: item.relationships ?? void 0,
323
+ id: item.id
324
+ });
325
+ });
326
+ else {
327
+ if (!data.id) throw new Error(`Resource of type ${data.type} is missing an id`);
328
+ return [add({
329
+ ...data,
330
+ attributes: data.attributes ?? void 0,
331
+ relationships: data.relationships ?? void 0,
332
+ id: data.id
333
+ })];
334
+ }
335
+ };
336
+ try {
337
+ syncData(body.included);
338
+ const recs = syncData(body.data);
339
+ const models = {};
340
+ const result = recs.map((rec) => this.toModel(rec, rec.type, models));
341
+ if (body.meta != null) result[META] = body.meta;
342
+ return result;
343
+ } catch (e) {
344
+ this.records = previousRecords;
345
+ throw e;
346
+ }
347
+ }
348
+ sync(body) {
349
+ const result = this.syncAll(body);
350
+ if (!Array.isArray(body.data) && body.data != null) {
351
+ const model = result[0];
352
+ if (result[META]) model[META] = result[META];
353
+ return model;
354
+ }
355
+ return result;
356
+ }
357
+ retrieve(type, body) {
358
+ const synced = this.syncAll(body);
359
+ const model = synced.find((m) => m[TYPE] === type);
360
+ if (!model) return null;
361
+ if (synced[META]) model[META] = synced[META];
362
+ return model;
363
+ }
364
+ retrieveAll(type, body) {
365
+ const synced = this.syncAll(body);
366
+ const result = synced.filter((model) => model[TYPE] === type);
367
+ result[META] = synced[META];
368
+ return result;
369
+ }
370
+ };
371
+
372
+ //#endregion
373
+ //#region src/yayson.ts
374
+ function lookupAdapter(nameOrAdapter) {
375
+ if (nameOrAdapter === "default" || !nameOrAdapter) return adapter_default;
376
+ else if (typeof nameOrAdapter === "string") if (nameOrAdapter === "sequelize") return sequelize_default;
377
+ else throw new Error("Adapter not found: " + nameOrAdapter);
378
+ return nameOrAdapter;
379
+ }
380
+ function yayson(options) {
381
+ return {
382
+ Store,
383
+ Presenter: createPresenter(lookupAdapter(options?.adapter)),
384
+ Adapter: adapter_default
385
+ };
386
+ }
387
+ var yayson_default = yayson;
388
+
389
+ //#endregion
390
+ export { validate as n, filterByFields as r, yayson_default as t };
391
+ //# sourceMappingURL=yayson-BJv2Z0Z6.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yayson-BJv2Z0Z6.mjs","names":["Adapter","type","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 === undefined) {\n return id\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 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\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 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\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 toModel(rec: StoreRecord, type: string, models: StoreModels): StoreModel {\n const model: StoreModel = { ...(rec.attributes || {}), id: rec.id }\n\n model[TYPE] = rec.type\n const idStr = String(rec.id)\n if (!models[type]) {\n models[type] = {}\n }\n if (!models[type][idStr]) {\n models[type][idStr] = model\n }\n\n if (rec.meta != null) {\n model[META] = rec.meta\n }\n\n if (rec.links != null) {\n model[LINKS] = rec.links\n }\n\n if (rec.relationships != null) {\n for (const key in rec.relationships) {\n const rel = rec.relationships[key]\n const { data } = rel\n const { links } = rel\n const { meta } = rel\n\n model[key] = null\n if (data == null && links == null) {\n continue\n }\n const resolve = ({ type, id }: JsonApiResourceIdentifier): StoreModel | null => {\n const result = this.find(type, id, models)\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Runtime type string cannot use type parameter\n return result as StoreModel | null\n }\n if (Array.isArray(data)) {\n model[key] = data.map(resolve)\n } else {\n const relModel: StoreModel | null = data != null ? resolve(data) : { id: '' }\n\n if (relModel) {\n relModel[REL_LINKS] = links || {}\n relModel[REL_META] = meta || {}\n model[key] = relModel\n }\n }\n }\n }\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 find<T extends string>(type: T, id: string | number, models?: StoreModels): InferModelType<S, T> | null {\n const modelsObj = models ?? {}\n const idStr = String(id)\n const rec = this.findRecord(type, idStr)\n if (rec == null) {\n return null\n }\n if (!modelsObj[type]) {\n modelsObj[type] = {}\n }\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Enable type inference from schema registry\n return (modelsObj[type][idStr] || this.toModel(rec, type, modelsObj)) as InferModelType<S, T>\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 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,OAAO,OACT,QAAO;AAET,SAAO,GAAG;;;AAId,wBAAe;;;;;;;;AC7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;AACV,QAAK,UAAU;AACf,SAAM;;;CAIV,KAAK,MAAiD;EACpD,MAAM,SAAS,KAAK,QAAQ,KAAK;AACjC,MAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,IAAI,KAAK,QAAQ,MAAM;GAClD,MAAM,QAAQ,OAAO;AACrB,OAAI,OAAO,MACT,OAAM,QAAQ,OAAO;AAEvB,UAAO;;AAET,SAAO;;CAGT,SAA2B,MAAS,MAAoD;EACtF,MAAM,SAAS,KAAK,QAAQ,KAAK;EACjC,MAAM,QAAQ,OAAO,MAAM,MAAM,EAAE,UAAU,KAAK;AAClD,MAAI,CAAC,MAAO,QAAO;AACnB,MAAI,OAAO,MACT,OAAM,QAAQ,OAAO;AAGvB,SAAO;;CAGT,YAA8B,MAAS,MAA0D;EAC/F,MAAM,SAAS,KAAK,QAAQ,KAAK;EAEjC,MAAM,SAA4C,OAAO,QAAQ,UAAU,MAAM,UAAU,KAAK;AAGhG,SAAO,QAAQ,OAAO;AACtB,SAAO;;;;;;ACvPX,SAAS,cAAc,eAA+C;AACpE,KAAI,kBAAkB,aAAa,CAAC,cAClC,QAAOC;UACE,OAAO,kBAAkB,SAClC,KAAI,kBAAkB,YACpB,QAAOC;KAEP,OAAM,IAAI,MAAM,wBAAwB,cAAc;AAG1D,QAAO;;AAGT,SAAS,OAAO,SAAuC;AAIrD,QAAO;EACL;EACA,WAJgB,gBADF,cAAc,SAAS,QAAQ,CACL;EAKxC;EACD;;AAGH,qBAAe"}
@@ -0,0 +1,69 @@
1
+ import { T as ModelLike, _ as ValidationError, d as SchemaRegistry, f as StoreModel, g as StoreResult, h as StoreRecord$1, i as JsonApiLinks, m as StoreOptions, n as JsonApiDocument, o as JsonApiRelationships, p as StoreModels, r as JsonApiLink, t as InferModelType, u as PresenterOptions, w as Adapter } from "./types-DbMIe8E2.cjs";
2
+
3
+ //#region src/yayson/presenter.d.ts
4
+ declare function createPresenter(adapter: typeof Adapter): {
5
+ new (scope?: JsonApiDocument): {
6
+ constructor: /*elided*/any;
7
+ scope: JsonApiDocument;
8
+ id(instance: ModelLike): string | undefined;
9
+ selfLinks(_instance: ModelLike): JsonApiLink | string | undefined;
10
+ links(_instance?: ModelLike): JsonApiLinks | undefined;
11
+ relationships(): Record<string, /*elided*/any>;
12
+ attributes(instance: ModelLike | null): Record<string, unknown>;
13
+ includeRelationships(scope: JsonApiDocument, instance: ModelLike): unknown[];
14
+ buildRelationships(instance: ModelLike | null): JsonApiRelationships | null;
15
+ buildSelfLink(instance: ModelLike): JsonApiLink | undefined;
16
+ toJSON(instanceOrCollection: ModelLike | ModelLike[] | null | undefined, options?: PresenterOptions): JsonApiDocument;
17
+ render(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
18
+ };
19
+ adapter: typeof Adapter;
20
+ type: string;
21
+ fields?: string[];
22
+ toJSON(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
23
+ render(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
24
+ };
25
+ type Presenter = ReturnType<typeof createPresenter>;
26
+ //#endregion
27
+ //#region src/yayson/store.d.ts
28
+ declare class StoreRecord implements StoreRecord$1 {
29
+ id: string | number;
30
+ type: string;
31
+ attributes?: Record<string, unknown>;
32
+ relationships?: JsonApiRelationships;
33
+ links?: JsonApiLink;
34
+ meta?: Record<string, unknown>;
35
+ constructor(options: StoreRecord$1);
36
+ }
37
+ declare class Store<S extends SchemaRegistry = SchemaRegistry> {
38
+ records: StoreRecord[];
39
+ schemas?: S;
40
+ strict: boolean;
41
+ validationErrors: ValidationError[];
42
+ constructor(options?: StoreOptions<S>);
43
+ reset(): void;
44
+ toModel(rec: StoreRecord, type: string, models: StoreModels): StoreModel;
45
+ findRecord(type: string, id: string | number): StoreRecord | undefined;
46
+ findRecords(type: string): StoreRecord[];
47
+ find<T extends string>(type: T, id: string | number, models?: StoreModels): InferModelType<S, T> | null;
48
+ findAll<T extends string>(type: T, models?: StoreModels): InferModelType<S, T>[];
49
+ remove(type: string, id?: string | number): void;
50
+ syncAll(body: JsonApiDocument): StoreResult;
51
+ sync(body: JsonApiDocument): StoreModel | StoreResult;
52
+ retrieve<T extends string>(type: T, body: JsonApiDocument): InferModelType<S, T> | null;
53
+ retrieveAll<T extends string>(type: T, body: JsonApiDocument): StoreResult<InferModelType<S, T>>;
54
+ }
55
+ //#endregion
56
+ //#region src/yayson.d.ts
57
+ type AdapterOption = string | typeof Adapter;
58
+ interface YaysonOptions {
59
+ adapter?: AdapterOption;
60
+ }
61
+ interface YaysonResult {
62
+ Store: typeof Store;
63
+ Presenter: Presenter;
64
+ Adapter: typeof Adapter;
65
+ }
66
+ declare function yayson(options?: YaysonOptions): YaysonResult;
67
+ //#endregion
68
+ export { Presenter as i, YaysonResult as n, yayson as r, YaysonOptions as t };
69
+ //# sourceMappingURL=yayson-BKEyEcGk.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yayson-BKEyEcGk.d.cts","names":[],"sources":["../../../../../../yayson/presenter.ts","../../../../../../yayson/store.ts","../../../../../../yayson.ts"],"mappings":";;;iBAyBwB,eAAA,CAAgB,OAAA,SAAgB,OAAA;EAAA,aAUhC,eAAA;iBAVe;WAQ5B,eAAA;iBAMM,SAAA;yBAIQ,SAAA,GAAY,WAAA;sBAIf,SAAA,GAAY,YAAA;qBAIb,MAAA,SAZJ;yBAgBQ,SAAA,UAAmB,MAAA;gCAiBZ,eAAA,EAAe,QAAA,EAAY,SAAA;iCAoB1B,SAAA,UAAmB,oBAAA;4BA0DxB,SAAA,GAAY,WAAA;iCAKZ,SAAA,GAAY,SAAA,uBAA8B,OAAA,GACtD,gBAAA,GACT,eAAA;iCA8E0B,SAAA,GAAY,SAAA,WAAkB,OAAA,GAAY,gBAAA,GAAmB,eAAA;EAAA;;;;+BAItD,SAAA,GAAY,SAAA,WAAkB,OAAA,GAAY,gBAAA,GAAmB,eAAA;+BAI7D,SAAA,GAAY,SAAA,WAAk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