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,331 @@
1
+ const require_symbols = require('./symbols-nFs99aEX.cjs');
2
+ const require_yayson = require('./yayson-l2JKseMH.cjs');
3
+
4
+ //#region src/yayson/legacy-presenter.ts
5
+ function hasId$1(value) {
6
+ return typeof value === "object" && value !== null && "id" in value;
7
+ }
8
+ function createLegacyPresenter(Presenter) {
9
+ return class LegacyPresenter extends Presenter {
10
+ static type = "object";
11
+ static plural;
12
+ static fields;
13
+ constructor(scope) {
14
+ super(scope || { data: null });
15
+ if (!scope) delete this.scope.data;
16
+ }
17
+ pluralType() {
18
+ return this.constructor.plural || this.constructor.type + "s";
19
+ }
20
+ attributes(instance) {
21
+ if (!instance) return {};
22
+ const attributes = { ...this.constructor.adapter.get(instance) };
23
+ const relationships = this.relationships();
24
+ if (relationships) for (const key in relationships) {
25
+ let id;
26
+ const data = attributes[key];
27
+ if (data == null) {
28
+ id = attributes[key + "Id"];
29
+ if (id != null) attributes[key] = id;
30
+ } else if (Array.isArray(data)) attributes[key] = data.map((obj) => hasId$1(obj) ? obj.id : obj);
31
+ else if (hasId$1(data)) attributes[key] = data.id;
32
+ }
33
+ const relationshipKeys = relationships ? Object.keys(relationships) : [];
34
+ return require_yayson.filterByFields(attributes, this.constructor.fields ? [...this.constructor.fields, ...relationshipKeys] : void 0);
35
+ }
36
+ includeRelationships(scope, instance) {
37
+ if (!scope.links) scope.links = {};
38
+ const relationships = this.relationships();
39
+ const result = [];
40
+ if (!relationships) return result;
41
+ for (const key in relationships) {
42
+ const factory = relationships[key];
43
+ if (!factory) throw new Error(`Presenter for ${key} in ${this.constructor.type} is not defined`);
44
+ const presenter = new factory(scope);
45
+ const data = this.constructor.adapter.get(instance, key);
46
+ if (data != null) presenter.toJSON(data, { defaultPlural: true });
47
+ const type = scope[this.pluralType()] != null ? this.pluralType() : this.constructor.type;
48
+ const presenterType = presenter.constructor.type;
49
+ const link = { type: scope[presenter.pluralType()] != null ? presenter.pluralType() : presenterType };
50
+ if (scope.links) scope.links[`${type}.${key}`] = link;
51
+ result.push(link);
52
+ }
53
+ return result;
54
+ }
55
+ toJSON(instanceOrCollection, options) {
56
+ const opts = options ?? {};
57
+ if (!this.scope.links) this.scope.links = {};
58
+ if (Array.isArray(instanceOrCollection)) {
59
+ const collection = instanceOrCollection;
60
+ const type = this.pluralType();
61
+ if (!this.scope[type]) this.scope[type] = [];
62
+ collection.forEach((instance) => {
63
+ return this.toJSON(instance);
64
+ });
65
+ } else {
66
+ let links;
67
+ const instance = instanceOrCollection;
68
+ let added = true;
69
+ const attrs = instance ? this.attributes(instance) : null;
70
+ if (links = this.links()) {
71
+ if (attrs) attrs.links = links;
72
+ }
73
+ if (this.scope[this.constructor.type] && !this.scope[this.pluralType()]) {
74
+ const existingValue = this.scope[this.constructor.type];
75
+ if (attrs && hasId$1(existingValue) && existingValue.id !== attrs.id) {
76
+ this.scope[this.pluralType()] = [this.scope[this.constructor.type]];
77
+ delete this.scope[this.constructor.type];
78
+ const pluralArray = this.scope[this.pluralType()];
79
+ if (Array.isArray(pluralArray)) pluralArray.push(attrs);
80
+ } else added = false;
81
+ } else if (this.scope[this.pluralType()]) {
82
+ const existing = this.scope[this.pluralType()];
83
+ if (Array.isArray(existing)) if (attrs && !existing.some((i) => hasId$1(i) && i.id === attrs.id)) existing.push(attrs);
84
+ else added = false;
85
+ } else if (opts.defaultPlural) this.scope[this.pluralType()] = attrs ? [attrs] : [];
86
+ else this.scope[this.constructor.type] = attrs;
87
+ if (added && instance) this.includeRelationships(this.scope, instance);
88
+ }
89
+ return this.scope;
90
+ }
91
+ payload(instance) {
92
+ if (Array.isArray(instance)) throw new Error("payload() expects a single resource, not an array");
93
+ if (instance == null) throw new Error("payload() requires a resource, got null");
94
+ return { [this.constructor.type]: this.attributes(instance) };
95
+ }
96
+ render(instanceOrCollection) {
97
+ return this.toJSON(instanceOrCollection);
98
+ }
99
+ static toJSON(instanceOrCollection, options) {
100
+ return new this().toJSON(instanceOrCollection, options);
101
+ }
102
+ static render(instanceOrCollection, _options) {
103
+ return new this().render(instanceOrCollection);
104
+ }
105
+ static payload(instance) {
106
+ return new this().payload(instance);
107
+ }
108
+ };
109
+ }
110
+
111
+ //#endregion
112
+ //#region src/yayson/legacy-store.ts
113
+ function hasId(model) {
114
+ return model.id != null;
115
+ }
116
+ var LegacyStore = class LegacyStore {
117
+ types;
118
+ records;
119
+ relations;
120
+ schemas;
121
+ strict;
122
+ validationErrors;
123
+ models;
124
+ constructor(options) {
125
+ this.types = options?.types || {};
126
+ this.schemas = options?.schemas;
127
+ this.strict = options?.strict ?? false;
128
+ this.records = [];
129
+ this.relations = {};
130
+ this.validationErrors = [];
131
+ this.models = {};
132
+ }
133
+ reset() {
134
+ this.records = [];
135
+ this.relations = {};
136
+ this.validationErrors = [];
137
+ this.models = {};
138
+ }
139
+ #createStub(type, id) {
140
+ const stub = { id };
141
+ stub[require_symbols.TYPE] = type;
142
+ return stub;
143
+ }
144
+ #resolveRelationships(model, type, resolver) {
145
+ const relations = this.relations[type];
146
+ if (!relations) return;
147
+ for (const attribute in relations) {
148
+ const relationType = relations[attribute];
149
+ const value = model[attribute];
150
+ if (Array.isArray(value)) model[attribute] = value.filter((id) => id != null).map((id) => resolver(relationType, String(id)));
151
+ else if (value != null) model[attribute] = resolver(relationType, String(value));
152
+ else model[attribute] = null;
153
+ }
154
+ }
155
+ #createModel(rec, type, options) {
156
+ const models = options?.models;
157
+ const model = { ...rec.data };
158
+ if (rec.data.id != null) model.id = rec.data.id;
159
+ model[require_symbols.TYPE] = type;
160
+ if (rec.data.meta != null) model[require_symbols.META] = rec.data.meta;
161
+ if (rec.data.links != null) model[require_symbols.LINKS] = rec.data.links;
162
+ if (models && hasId(model)) {
163
+ const idStr = String(model.id);
164
+ if (!models[type]) models[type] = {};
165
+ models[type][idStr] = model;
166
+ }
167
+ const resolver = (relationType, id) => {
168
+ return this.#findModel(relationType, id, models ?? {}) ?? this.#createStub(relationType, id);
169
+ };
170
+ this.#resolveRelationships(model, type, resolver);
171
+ return model;
172
+ }
173
+ toModel(rec, type, models) {
174
+ const idStr = String(rec.data.id);
175
+ if (!models[type]) models[type] = {};
176
+ if (models[type][idStr]) return models[type][idStr];
177
+ const result = this.#createModel(rec, type, { models });
178
+ if (!hasId(result)) throw new Error(`Expected model of type ${type} to have an id`);
179
+ const model = result;
180
+ if (this.schemas && this.schemas[type]) {
181
+ const schema = this.schemas[type];
182
+ const result$1 = require_yayson.validate(schema, model, this.strict);
183
+ if (!result$1.valid) this.validationErrors.push({
184
+ type,
185
+ id: idStr,
186
+ error: result$1.error
187
+ });
188
+ const validatedModel = result$1.data;
189
+ validatedModel[require_symbols.TYPE] = model[require_symbols.TYPE];
190
+ validatedModel[require_symbols.LINKS] = model[require_symbols.LINKS];
191
+ validatedModel[require_symbols.META] = model[require_symbols.META];
192
+ models[type][idStr] = validatedModel;
193
+ return validatedModel;
194
+ }
195
+ return model;
196
+ }
197
+ setupRelations(links) {
198
+ for (const key in links) {
199
+ const value = links[key];
200
+ const parts = key.split(".");
201
+ const typeRaw = parts[0];
202
+ const attribute = parts[1];
203
+ const type = this.types[typeRaw] || typeRaw;
204
+ if (!this.relations[type]) this.relations[type] = {};
205
+ this.relations[type][attribute] = this.types[value.type] || value.type;
206
+ }
207
+ }
208
+ findRecord(type, id) {
209
+ return this.records.find((r) => r.type === type && String(r.data.id) === id);
210
+ }
211
+ findRecords(type) {
212
+ return this.records.filter((r) => r.type === type);
213
+ }
214
+ #findModel(type, id, models) {
215
+ const rec = this.findRecord(type, id);
216
+ if (rec == null) return null;
217
+ return models[type]?.[id] ?? this.toModel(rec, type, models);
218
+ }
219
+ static build(data) {
220
+ return new LegacyStore().build(data);
221
+ }
222
+ build(data) {
223
+ if (data.links) this.setupRelations(data.links);
224
+ let name;
225
+ for (const key in data) if (key !== "meta" && key !== "links") {
226
+ name = key;
227
+ break;
228
+ }
229
+ if (name == null) throw new Error("build() expects a single resource, not an array");
230
+ const value = data[name];
231
+ if (value == null || Array.isArray(value)) throw new Error("build() expects a single resource, not an array");
232
+ const type = this.types[name] || name;
233
+ return this.#createModel({
234
+ type,
235
+ data: value
236
+ }, type);
237
+ }
238
+ /** @deprecated Use retrieve() instead. */
239
+ retrive(type, data) {
240
+ return this.retrieve(type, data);
241
+ }
242
+ retrieve(type, data) {
243
+ const synced = this.syncAll(data);
244
+ const normalizedType = this.types[type] || type;
245
+ const model = synced.find((m) => m[require_symbols.TYPE] === normalizedType);
246
+ if (!model) return null;
247
+ if (synced[require_symbols.META]) model[require_symbols.META] = synced[require_symbols.META];
248
+ return model;
249
+ }
250
+ find(type, id, models) {
251
+ return this.#findModel(type, String(id), models ?? this.models);
252
+ }
253
+ findAll(type, models) {
254
+ const modelsObj = models ?? this.models;
255
+ const recs = this.findRecords(type);
256
+ if (recs.length === 0) return [];
257
+ recs.forEach((rec) => {
258
+ if (!modelsObj[type]) modelsObj[type] = {};
259
+ return this.toModel(rec, type, modelsObj);
260
+ });
261
+ return Object.values(modelsObj[type] || {});
262
+ }
263
+ remove(type, id) {
264
+ const normalizedType = this.types[type] || type;
265
+ const removeOne = (record) => {
266
+ const index = this.records.indexOf(record);
267
+ if (!(index < 0)) this.records.splice(index, 1);
268
+ };
269
+ if (id != null) {
270
+ const idStr = String(id);
271
+ const record = this.findRecord(normalizedType, idStr);
272
+ if (record) removeOne(record);
273
+ } else this.findRecords(normalizedType).forEach(removeOne);
274
+ }
275
+ syncAll(data) {
276
+ this.validationErrors = [];
277
+ this.models = {};
278
+ if (data.links) this.setupRelations(data.links);
279
+ const syncedRecords = [];
280
+ for (const name in data) {
281
+ if (name === "meta" || name === "links") continue;
282
+ const value = data[name];
283
+ const type = this.types[name] || name;
284
+ const add = (d) => {
285
+ this.remove(type, String(d.id));
286
+ const rec = {
287
+ type,
288
+ data: d
289
+ };
290
+ this.records.push(rec);
291
+ syncedRecords.push(rec);
292
+ };
293
+ if (Array.isArray(value)) value.forEach(add);
294
+ else if (typeof value === "object" && value !== null) add(value);
295
+ }
296
+ for (const rec of syncedRecords) this.toModel(rec, rec.type, this.models);
297
+ const result = syncedRecords.map((rec) => this.models[rec.type][String(rec.data.id)]);
298
+ if (data.meta != null) result[require_symbols.META] = data.meta;
299
+ return result;
300
+ }
301
+ sync(data) {
302
+ const result = this.syncAll(data);
303
+ if (result.length === 1) {
304
+ const model = result[0];
305
+ if (result[require_symbols.META]) model[require_symbols.META] = result[require_symbols.META];
306
+ return model;
307
+ }
308
+ return result;
309
+ }
310
+ retrieveAll(type, data) {
311
+ const normalizedType = this.types[type] || type;
312
+ const synced = this.syncAll(data);
313
+ const result = synced.filter((model) => model[require_symbols.TYPE] === normalizedType);
314
+ result[require_symbols.META] = synced[require_symbols.META];
315
+ return result;
316
+ }
317
+ };
318
+
319
+ //#endregion
320
+ //#region src/legacy.ts
321
+ function yayson(options) {
322
+ const { Presenter, Adapter } = require_yayson.yayson_default(options);
323
+ return {
324
+ Store: LegacyStore,
325
+ Presenter: createLegacyPresenter(Presenter),
326
+ Adapter
327
+ };
328
+ }
329
+
330
+ //#endregion
331
+ module.exports = yayson;
@@ -0,0 +1,113 @@
1
+ import { E as ModelLike, T as Adapter, _ as StoreResult, a as JsonApiRelationship, c as LegacyPresenterOptions, d as SchemaRegistry, f as StoreModel, i as JsonApiLinks, l as LegacyStoreOptions, m as StoreModels, n as JsonApiDocument, o as JsonApiRelationships, p as StoreModelWithOptionalId, r as JsonApiLink, s as JsonApiResource, t as InferModelType, u as PresenterOptions, v as ValidationError } from "./types-NiKV-lj-.cjs";
2
+ import { i as Presenter, r as yayson$1, t as YaysonOptions } from "./yayson-3UYKq2H5.cjs";
3
+
4
+ //#region src/yayson/legacy-presenter.d.ts
5
+ interface LegacyJsonApiDocument extends JsonApiDocument {
6
+ [key: string]: unknown;
7
+ }
8
+ declare function createLegacyPresenter(Presenter: Presenter): {
9
+ new (scope?: JsonApiDocument): {
10
+ constructor: /*elided*/any;
11
+ scope: LegacyJsonApiDocument;
12
+ pluralType(): string;
13
+ attributes(instance: ModelLike | null): Record<string, unknown>;
14
+ includeRelationships(scope: LegacyJsonApiDocument, instance: ModelLike): unknown[];
15
+ toJSON(instanceOrCollection: ModelLike | ModelLike[] | null | undefined, options?: LegacyPresenterOptions): LegacyJsonApiDocument;
16
+ payload(instance: ModelLike): LegacyJsonApiDocument;
17
+ render(instanceOrCollection: ModelLike | ModelLike[] | null): LegacyJsonApiDocument;
18
+ id(instance: ModelLike): string | undefined;
19
+ selfLinks(_instance: ModelLike): JsonApiLink | string | undefined;
20
+ links(_instance?: ModelLike): JsonApiLinks | undefined;
21
+ relationships(): Record<string, {
22
+ new (scope?: JsonApiDocument): {
23
+ constructor: /*elided*/any;
24
+ scope: JsonApiDocument;
25
+ id(instance: ModelLike): string | undefined;
26
+ selfLinks(_instance: ModelLike): JsonApiLink | string | undefined;
27
+ links(_instance?: ModelLike): JsonApiLinks | undefined;
28
+ relationships(): Record<string, /*elided*/any>;
29
+ attributes(instance: ModelLike | null): Record<string, unknown>;
30
+ includeRelationships(scope: JsonApiDocument, instance: ModelLike): unknown[];
31
+ buildRelationships(instance: ModelLike | null): JsonApiRelationships | null;
32
+ buildSelfLink(instance: ModelLike): JsonApiLink | undefined;
33
+ toJSON(instanceOrCollection: ModelLike | ModelLike[] | null | undefined, options?: PresenterOptions): JsonApiDocument;
34
+ payload(instance: ModelLike, options?: PresenterOptions): JsonApiDocument;
35
+ render(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
36
+ };
37
+ adapter: typeof Adapter;
38
+ type: string;
39
+ fields?: string[];
40
+ toJSON(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
41
+ render(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
42
+ payload(instance: ModelLike, options?: PresenterOptions): JsonApiDocument;
43
+ }>;
44
+ buildRelationships(instance: ModelLike | null): JsonApiRelationships | null;
45
+ buildSelfLink(instance: ModelLike): JsonApiLink | undefined;
46
+ };
47
+ type: string;
48
+ plural?: string;
49
+ fields?: string[];
50
+ toJSON(instanceOrCollection: ModelLike | ModelLike[] | null, options?: LegacyPresenterOptions): LegacyJsonApiDocument;
51
+ render(instanceOrCollection: ModelLike | ModelLike[] | null, _options?: LegacyPresenterOptions): LegacyJsonApiDocument;
52
+ payload(instance: ModelLike): LegacyJsonApiDocument;
53
+ adapter: typeof Adapter;
54
+ };
55
+ //#endregion
56
+ //#region src/yayson/legacy-store.d.ts
57
+ interface LegacyStoreRecordType {
58
+ type: string;
59
+ data: Record<string, unknown> & {
60
+ id?: string | number;
61
+ meta?: Record<string, unknown>;
62
+ links?: Record<string, unknown>;
63
+ };
64
+ }
65
+ interface LegacyLinks {
66
+ [key: string]: {
67
+ type: string;
68
+ };
69
+ }
70
+ type LegacyDataValue = Record<string, unknown> | Array<Record<string, unknown>>;
71
+ interface LegacyData {
72
+ links?: LegacyLinks;
73
+ meta?: Record<string, unknown>;
74
+ [key: string]: LegacyDataValue | LegacyLinks | Record<string, unknown> | undefined;
75
+ }
76
+ declare class LegacyStore<S extends SchemaRegistry = SchemaRegistry> {
77
+ #private;
78
+ types: Record<string, string>;
79
+ records: LegacyStoreRecordType[];
80
+ relations: Record<string, Record<string, string>>;
81
+ schemas?: S;
82
+ strict: boolean;
83
+ validationErrors: ValidationError[];
84
+ models: StoreModels;
85
+ constructor(options?: LegacyStoreOptions<S>);
86
+ reset(): void;
87
+ toModel(rec: LegacyStoreRecordType, type: string, models: StoreModels): StoreModel;
88
+ setupRelations(links: LegacyLinks): void;
89
+ findRecord(type: string, id: string): LegacyStoreRecordType | undefined;
90
+ findRecords(type: string): LegacyStoreRecordType[];
91
+ static build(data: LegacyData): StoreModelWithOptionalId;
92
+ build(data: LegacyData): StoreModelWithOptionalId;
93
+ /** @deprecated Use retrieve() instead. */
94
+ retrive<T extends string>(type: T, data: LegacyData): InferModelType<S, T> | null;
95
+ retrieve<T extends string>(type: T, data: LegacyData): InferModelType<S, T> | null;
96
+ find<T extends string>(type: T, id: string | number, models?: StoreModels): InferModelType<S, T> | null;
97
+ findAll<T extends string>(type: T, models?: StoreModels): InferModelType<S, T>[];
98
+ remove(type: string, id?: string | number): void;
99
+ syncAll(data: LegacyData): StoreResult;
100
+ sync(data: LegacyData): StoreModel | StoreResult;
101
+ retrieveAll<T extends string>(type: T, data: LegacyData): StoreResult<InferModelType<S, T>>;
102
+ }
103
+ //#endregion
104
+ //#region src/legacy.d.ts
105
+ interface LegacyYaysonResult {
106
+ Store: typeof LegacyStore;
107
+ Presenter: ReturnType<typeof createLegacyPresenter>;
108
+ Adapter: ReturnType<typeof yayson$1>['Adapter'];
109
+ }
110
+ declare function yayson(options?: YaysonOptions): LegacyYaysonResult;
111
+ //#endregion
112
+ export { type Adapter, type JsonApiDocument, type JsonApiLink, type JsonApiLinks, type JsonApiRelationship, type JsonApiRelationships, type JsonApiResource, type LegacyData, yayson as default };
113
+ //# sourceMappingURL=legacy.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy.d.cts","names":[],"sources":["../../../../../../yayson/legacy-presenter.ts","../../../../../../yayson/legacy-store.ts","../../../../../../legacy.ts"],"mappings":";;;;UASU,qBAAA,SAA8B,eAAA;EAAA,CACrC,GAAA;AAAA;AAAA,iBAIqB,qBAAA,CAAsB,SAAA,EAAW,SAA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inks, l as LegacyStoreOptions, m as StoreModels, n as JsonApiDocument, o as JsonApiRelationships, p as StoreModelWithOptionalId, r as JsonApiLink, s as JsonApiResource, t as InferModelType, u as PresenterOptions, v as ValidationError } from "./types-Do2flKZX.mjs";
2
+ import { i as Presenter, r as yayson$1, t as YaysonOptions } from "./yayson-Ce5uGpgU.mjs";
3
+
4
+ //#region src/yayson/legacy-presenter.d.ts
5
+ interface LegacyJsonApiDocument extends JsonApiDocument {
6
+ [key: string]: unknown;
7
+ }
8
+ declare function createLegacyPresenter(Presenter: Presenter): {
9
+ new (scope?: JsonApiDocument): {
10
+ constructor: /*elided*/any;
11
+ scope: LegacyJsonApiDocument;
12
+ pluralType(): string;
13
+ attributes(instance: ModelLike | null): Record<string, unknown>;
14
+ includeRelationships(scope: LegacyJsonApiDocument, instance: ModelLike): unknown[];
15
+ toJSON(instanceOrCollection: ModelLike | ModelLike[] | null | undefined, options?: LegacyPresenterOptions): LegacyJsonApiDocument;
16
+ payload(instance: ModelLike): LegacyJsonApiDocument;
17
+ render(instanceOrCollection: ModelLike | ModelLike[] | null): LegacyJsonApiDocument;
18
+ id(instance: ModelLike): string | undefined;
19
+ selfLinks(_instance: ModelLike): JsonApiLink | string | undefined;
20
+ links(_instance?: ModelLike): JsonApiLinks | undefined;
21
+ relationships(): Record<string, {
22
+ new (scope?: JsonApiDocument): {
23
+ constructor: /*elided*/any;
24
+ scope: JsonApiDocument;
25
+ id(instance: ModelLike): string | undefined;
26
+ selfLinks(_instance: ModelLike): JsonApiLink | string | undefined;
27
+ links(_instance?: ModelLike): JsonApiLinks | undefined;
28
+ relationships(): Record<string, /*elided*/any>;
29
+ attributes(instance: ModelLike | null): Record<string, unknown>;
30
+ includeRelationships(scope: JsonApiDocument, instance: ModelLike): unknown[];
31
+ buildRelationships(instance: ModelLike | null): JsonApiRelationships | null;
32
+ buildSelfLink(instance: ModelLike): JsonApiLink | undefined;
33
+ toJSON(instanceOrCollection: ModelLike | ModelLike[] | null | undefined, options?: PresenterOptions): JsonApiDocument;
34
+ payload(instance: ModelLike, options?: PresenterOptions): JsonApiDocument;
35
+ render(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
36
+ };
37
+ adapter: typeof Adapter;
38
+ type: string;
39
+ fields?: string[];
40
+ toJSON(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
41
+ render(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
42
+ payload(instance: ModelLike, options?: PresenterOptions): JsonApiDocument;
43
+ }>;
44
+ buildRelationships(instance: ModelLike | null): JsonApiRelationships | null;
45
+ buildSelfLink(instance: ModelLike): JsonApiLink | undefined;
46
+ };
47
+ type: string;
48
+ plural?: string;
49
+ fields?: string[];
50
+ toJSON(instanceOrCollection: ModelLike | ModelLike[] | null, options?: LegacyPresenterOptions): LegacyJsonApiDocument;
51
+ render(instanceOrCollection: ModelLike | ModelLike[] | null, _options?: LegacyPresenterOptions): LegacyJsonApiDocument;
52
+ payload(instance: ModelLike): LegacyJsonApiDocument;
53
+ adapter: typeof Adapter;
54
+ };
55
+ //#endregion
56
+ //#region src/yayson/legacy-store.d.ts
57
+ interface LegacyStoreRecordType {
58
+ type: string;
59
+ data: Record<string, unknown> & {
60
+ id?: string | number;
61
+ meta?: Record<string, unknown>;
62
+ links?: Record<string, unknown>;
63
+ };
64
+ }
65
+ interface LegacyLinks {
66
+ [key: string]: {
67
+ type: string;
68
+ };
69
+ }
70
+ type LegacyDataValue = Record<string, unknown> | Array<Record<string, unknown>>;
71
+ interface LegacyData {
72
+ links?: LegacyLinks;
73
+ meta?: Record<string, unknown>;
74
+ [key: string]: LegacyDataValue | LegacyLinks | Record<string, unknown> | undefined;
75
+ }
76
+ declare class LegacyStore<S extends SchemaRegistry = SchemaRegistry> {
77
+ #private;
78
+ types: Record<string, string>;
79
+ records: LegacyStoreRecordType[];
80
+ relations: Record<string, Record<string, string>>;
81
+ schemas?: S;
82
+ strict: boolean;
83
+ validationErrors: ValidationError[];
84
+ models: StoreModels;
85
+ constructor(options?: LegacyStoreOptions<S>);
86
+ reset(): void;
87
+ toModel(rec: LegacyStoreRecordType, type: string, models: StoreModels): StoreModel;
88
+ setupRelations(links: LegacyLinks): void;
89
+ findRecord(type: string, id: string): LegacyStoreRecordType | undefined;
90
+ findRecords(type: string): LegacyStoreRecordType[];
91
+ static build(data: LegacyData): StoreModelWithOptionalId;
92
+ build(data: LegacyData): StoreModelWithOptionalId;
93
+ /** @deprecated Use retrieve() instead. */
94
+ retrive<T extends string>(type: T, data: LegacyData): InferModelType<S, T> | null;
95
+ retrieve<T extends string>(type: T, data: LegacyData): InferModelType<S, T> | null;
96
+ find<T extends string>(type: T, id: string | number, models?: StoreModels): InferModelType<S, T> | null;
97
+ findAll<T extends string>(type: T, models?: StoreModels): InferModelType<S, T>[];
98
+ remove(type: string, id?: string | number): void;
99
+ syncAll(data: LegacyData): StoreResult;
100
+ sync(data: LegacyData): StoreModel | StoreResult;
101
+ retrieveAll<T extends string>(type: T, data: LegacyData): StoreResult<InferModelType<S, T>>;
102
+ }
103
+ //#endregion
104
+ //#region src/legacy.d.ts
105
+ interface LegacyYaysonResult {
106
+ Store: typeof LegacyStore;
107
+ Presenter: ReturnType<typeof createLegacyPresenter>;
108
+ Adapter: ReturnType<typeof yayson$1>['Adapter'];
109
+ }
110
+ declare function yayson(options?: YaysonOptions): LegacyYaysonResult;
111
+ //#endregion
112
+ export { type Adapter, type JsonApiDocument, type JsonApiLink, type JsonApiLinks, type JsonApiRelationship, type JsonApiRelationships, type JsonApiResource, type LegacyData, yayson as default };
113
+ //# sourceMappingURL=legacy.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy.d.mts","names":[],"sources":["../../../../../../yayson/legacy-presenter.ts","../../../../../../yayson/legacy-store.ts","../../../../../../legacy.ts"],"mappings":";;;;UASU,qBAAA,SAA8B,eAAA;EAAA,CACrC,GAAA;AAAA;AAAA,i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