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.
- package/README.md +475 -104
- package/build/legacy.cjs +278 -0
- package/build/legacy.d.cts +105 -0
- package/build/legacy.d.cts.map +1 -0
- package/build/legacy.d.mts +105 -0
- package/build/legacy.d.mts.map +1 -0
- package/build/legacy.mjs +279 -0
- package/build/legacy.mjs.map +1 -0
- package/build/symbols-DSjKJ8vh.mjs +26 -0
- package/build/symbols-DSjKJ8vh.mjs.map +1 -0
- package/build/symbols-nFs99aEX.cjs +61 -0
- package/build/types-BsfPiPEw.d.mts +122 -0
- package/build/types-BsfPiPEw.d.mts.map +1 -0
- package/build/types-DbMIe8E2.d.cts +122 -0
- package/build/types-DbMIe8E2.d.cts.map +1 -0
- package/build/utils.cjs +31 -0
- package/build/utils.d.cts +11 -0
- package/build/utils.d.cts.map +1 -0
- package/build/utils.d.mts +11 -0
- package/build/utils.d.mts.map +1 -0
- package/build/utils.mjs +22 -0
- package/build/utils.mjs.map +1 -0
- package/build/yayson-BJv2Z0Z6.mjs +391 -0
- package/build/yayson-BJv2Z0Z6.mjs.map +1 -0
- package/build/yayson-BKEyEcGk.d.cts +69 -0
- package/build/yayson-BKEyEcGk.d.cts.map +1 -0
- package/build/yayson-CRbukIqr.d.mts +69 -0
- package/build/yayson-CRbukIqr.d.mts.map +1 -0
- package/build/yayson-CUfrxK9d.cjs +407 -0
- package/build/yayson.cjs +3 -0
- package/build/yayson.d.cts +3 -0
- package/build/yayson.d.mts +3 -0
- package/build/yayson.mjs +3 -0
- package/package.json +74 -33
- package/skill/yayson/SKILL.md +233 -0
- package/skill/yayson/references/api.md +266 -0
- package/.circleci/config.yml +0 -35
- package/.github/workflows/node.js.yml +0 -30
- package/.mocharc.js +0 -15
- package/RELEASE.md +0 -3
- package/bower.json +0 -31
- package/coffeelint.json +0 -120
- package/gulpfile.coffee +0 -43
- package/lib/yayson/adapter.js +0 -22
- package/lib/yayson/adapters/index.js +0 -3
- package/lib/yayson/adapters/sequelize.js +0 -14
- package/lib/yayson/presenter.js +0 -209
- package/lib/yayson/store.js +0 -169
- package/lib/yayson/utils.js +0 -47
- package/lib/yayson.js +0 -53
- package/tags +0 -59
package/build/legacy.cjs
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
const require_symbols = require('./symbols-nFs99aEX.cjs');
|
|
2
|
+
const require_yayson = require('./yayson-CUfrxK9d.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/yayson/legacy-presenter.ts
|
|
5
|
+
function hasId(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(obj) ? obj.id : obj);
|
|
31
|
+
else if (hasId(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(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(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
|
+
render(instanceOrCollection) {
|
|
92
|
+
return this.toJSON(instanceOrCollection);
|
|
93
|
+
}
|
|
94
|
+
static toJSON(instanceOrCollection, options) {
|
|
95
|
+
return new this().toJSON(instanceOrCollection, options);
|
|
96
|
+
}
|
|
97
|
+
static render(instanceOrCollection, _options) {
|
|
98
|
+
return new this().render(instanceOrCollection);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/yayson/legacy-store.ts
|
|
105
|
+
var LegacyStore = class {
|
|
106
|
+
types;
|
|
107
|
+
records;
|
|
108
|
+
relations;
|
|
109
|
+
schemas;
|
|
110
|
+
strict;
|
|
111
|
+
validationErrors;
|
|
112
|
+
models;
|
|
113
|
+
constructor(options) {
|
|
114
|
+
this.types = options?.types || {};
|
|
115
|
+
this.schemas = options?.schemas;
|
|
116
|
+
this.strict = options?.strict ?? false;
|
|
117
|
+
this.records = [];
|
|
118
|
+
this.relations = {};
|
|
119
|
+
this.validationErrors = [];
|
|
120
|
+
this.models = {};
|
|
121
|
+
}
|
|
122
|
+
reset() {
|
|
123
|
+
this.records = [];
|
|
124
|
+
this.relations = {};
|
|
125
|
+
this.validationErrors = [];
|
|
126
|
+
this.models = {};
|
|
127
|
+
}
|
|
128
|
+
toModel(rec, type, models) {
|
|
129
|
+
const idStr = String(rec.data.id);
|
|
130
|
+
if (!models[type]) models[type] = {};
|
|
131
|
+
if (models[type][idStr]) return models[type][idStr];
|
|
132
|
+
const model = {
|
|
133
|
+
...rec.data,
|
|
134
|
+
id: rec.data.id
|
|
135
|
+
};
|
|
136
|
+
model[require_symbols.TYPE] = type;
|
|
137
|
+
if (rec.data.meta != null) model[require_symbols.META] = rec.data.meta;
|
|
138
|
+
if (rec.data.links != null) model[require_symbols.LINKS] = rec.data.links;
|
|
139
|
+
models[type][idStr] = model;
|
|
140
|
+
const relations = this.relations[type];
|
|
141
|
+
if (relations) for (const attribute in relations) {
|
|
142
|
+
const relationType = relations[attribute];
|
|
143
|
+
const value = model[attribute];
|
|
144
|
+
model[attribute] = Array.isArray(value) ? value.map((id) => this.find(relationType, String(id), models)) : this.find(relationType, String(value), models);
|
|
145
|
+
}
|
|
146
|
+
if (this.schemas && this.schemas[type]) {
|
|
147
|
+
const schema = this.schemas[type];
|
|
148
|
+
const result = require_yayson.validate(schema, model, this.strict);
|
|
149
|
+
if (!result.valid) this.validationErrors.push({
|
|
150
|
+
type,
|
|
151
|
+
id: idStr,
|
|
152
|
+
error: result.error
|
|
153
|
+
});
|
|
154
|
+
const validatedModel = result.data;
|
|
155
|
+
validatedModel[require_symbols.TYPE] = model[require_symbols.TYPE];
|
|
156
|
+
validatedModel[require_symbols.LINKS] = model[require_symbols.LINKS];
|
|
157
|
+
validatedModel[require_symbols.META] = model[require_symbols.META];
|
|
158
|
+
models[type][idStr] = validatedModel;
|
|
159
|
+
return validatedModel;
|
|
160
|
+
}
|
|
161
|
+
return model;
|
|
162
|
+
}
|
|
163
|
+
setupRelations(links) {
|
|
164
|
+
for (const key in links) {
|
|
165
|
+
const value = links[key];
|
|
166
|
+
const parts = key.split(".");
|
|
167
|
+
const typeRaw = parts[0];
|
|
168
|
+
const attribute = parts[1];
|
|
169
|
+
const type = this.types[typeRaw] || typeRaw;
|
|
170
|
+
if (!this.relations[type]) this.relations[type] = {};
|
|
171
|
+
this.relations[type][attribute] = this.types[value.type] || value.type;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
findRecord(type, id) {
|
|
175
|
+
return this.records.find((r) => r.type === type && String(r.data.id) === id);
|
|
176
|
+
}
|
|
177
|
+
findRecords(type) {
|
|
178
|
+
return this.records.filter((r) => r.type === type);
|
|
179
|
+
}
|
|
180
|
+
/** @deprecated Use retrieve() instead. */
|
|
181
|
+
retrive(type, data) {
|
|
182
|
+
return this.retrieve(type, data);
|
|
183
|
+
}
|
|
184
|
+
retrieve(type, data) {
|
|
185
|
+
const synced = this.syncAll(data);
|
|
186
|
+
const normalizedType = this.types[type] || type;
|
|
187
|
+
const model = synced.find((m) => m[require_symbols.TYPE] === normalizedType);
|
|
188
|
+
if (!model) return null;
|
|
189
|
+
if (synced[require_symbols.META]) model[require_symbols.META] = synced[require_symbols.META];
|
|
190
|
+
return model;
|
|
191
|
+
}
|
|
192
|
+
find(type, id, models) {
|
|
193
|
+
const modelsObj = models ?? this.models;
|
|
194
|
+
const idStr = String(id);
|
|
195
|
+
const rec = this.findRecord(type, idStr);
|
|
196
|
+
if (rec == null) return null;
|
|
197
|
+
if (!modelsObj[type]) modelsObj[type] = {};
|
|
198
|
+
return modelsObj[type][idStr] || this.toModel(rec, type, modelsObj);
|
|
199
|
+
}
|
|
200
|
+
findAll(type, models) {
|
|
201
|
+
const modelsObj = models ?? this.models;
|
|
202
|
+
const recs = this.findRecords(type);
|
|
203
|
+
if (recs.length === 0) return [];
|
|
204
|
+
recs.forEach((rec) => {
|
|
205
|
+
if (!modelsObj[type]) modelsObj[type] = {};
|
|
206
|
+
return this.toModel(rec, type, modelsObj);
|
|
207
|
+
});
|
|
208
|
+
return Object.values(modelsObj[type] || {});
|
|
209
|
+
}
|
|
210
|
+
remove(type, id) {
|
|
211
|
+
const normalizedType = this.types[type] || type;
|
|
212
|
+
const removeOne = (record) => {
|
|
213
|
+
const index = this.records.indexOf(record);
|
|
214
|
+
if (!(index < 0)) this.records.splice(index, 1);
|
|
215
|
+
};
|
|
216
|
+
if (id != null) {
|
|
217
|
+
const idStr = String(id);
|
|
218
|
+
const record = this.findRecord(normalizedType, idStr);
|
|
219
|
+
if (record) removeOne(record);
|
|
220
|
+
} else this.findRecords(normalizedType).forEach(removeOne);
|
|
221
|
+
}
|
|
222
|
+
syncAll(data) {
|
|
223
|
+
this.validationErrors = [];
|
|
224
|
+
this.models = {};
|
|
225
|
+
if (data.links) this.setupRelations(data.links);
|
|
226
|
+
const syncedRecords = [];
|
|
227
|
+
for (const name in data) {
|
|
228
|
+
if (name === "meta" || name === "links") continue;
|
|
229
|
+
const value = data[name];
|
|
230
|
+
const type = this.types[name] || name;
|
|
231
|
+
const add = (d) => {
|
|
232
|
+
this.remove(type, String(d.id));
|
|
233
|
+
const rec = {
|
|
234
|
+
type,
|
|
235
|
+
data: d
|
|
236
|
+
};
|
|
237
|
+
this.records.push(rec);
|
|
238
|
+
syncedRecords.push(rec);
|
|
239
|
+
};
|
|
240
|
+
if (Array.isArray(value)) value.forEach(add);
|
|
241
|
+
else if (typeof value === "object" && value !== null) add(value);
|
|
242
|
+
}
|
|
243
|
+
for (const rec of syncedRecords) this.toModel(rec, rec.type, this.models);
|
|
244
|
+
const result = syncedRecords.map((rec) => this.models[rec.type][String(rec.data.id)]);
|
|
245
|
+
if (data.meta != null) result[require_symbols.META] = data.meta;
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
sync(data) {
|
|
249
|
+
const result = this.syncAll(data);
|
|
250
|
+
if (result.length === 1) {
|
|
251
|
+
const model = result[0];
|
|
252
|
+
if (result[require_symbols.META]) model[require_symbols.META] = result[require_symbols.META];
|
|
253
|
+
return model;
|
|
254
|
+
}
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
retrieveAll(type, data) {
|
|
258
|
+
const normalizedType = this.types[type] || type;
|
|
259
|
+
const synced = this.syncAll(data);
|
|
260
|
+
const result = synced.filter((model) => model[require_symbols.TYPE] === normalizedType);
|
|
261
|
+
result[require_symbols.META] = synced[require_symbols.META];
|
|
262
|
+
return result;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/legacy.ts
|
|
268
|
+
function yayson(options) {
|
|
269
|
+
const { Presenter, Adapter } = require_yayson.yayson_default(options);
|
|
270
|
+
return {
|
|
271
|
+
Store: LegacyStore,
|
|
272
|
+
Presenter: createLegacyPresenter(Presenter),
|
|
273
|
+
Adapter
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
//#endregion
|
|
278
|
+
module.exports = yayson;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { T as ModelLike, _ as ValidationError, a as JsonApiRelationship, c as LegacyPresenterOptions, d as SchemaRegistry, f as StoreModel, g as StoreResult, i as JsonApiLinks, l as LegacyStoreOptions, n as JsonApiDocument, o as JsonApiRelationships, p as StoreModels, r as JsonApiLink, s as JsonApiResource, t as InferModelType, u as PresenterOptions, w as Adapter } from "./types-DbMIe8E2.cjs";
|
|
2
|
+
import { i as Presenter, r as yayson$1, t as YaysonOptions } from "./yayson-BKEyEcGk.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
|
+
render(instanceOrCollection: ModelLike | ModelLike[] | null): LegacyJsonApiDocument;
|
|
17
|
+
id(instance: ModelLike): string | undefined;
|
|
18
|
+
selfLinks(_instance: ModelLike): JsonApiLink | string | undefined;
|
|
19
|
+
links(_instance?: ModelLike): JsonApiLinks | undefined;
|
|
20
|
+
relationships(): Record<string, {
|
|
21
|
+
new (scope?: JsonApiDocument): {
|
|
22
|
+
constructor: /*elided*/any;
|
|
23
|
+
scope: JsonApiDocument;
|
|
24
|
+
id(instance: ModelLike): string | undefined;
|
|
25
|
+
selfLinks(_instance: ModelLike): JsonApiLink | string | undefined;
|
|
26
|
+
links(_instance?: ModelLike): JsonApiLinks | undefined;
|
|
27
|
+
relationships(): Record<string, /*elided*/any>;
|
|
28
|
+
attributes(instance: ModelLike | null): Record<string, unknown>;
|
|
29
|
+
includeRelationships(scope: JsonApiDocument, instance: ModelLike): unknown[];
|
|
30
|
+
buildRelationships(instance: ModelLike | null): JsonApiRelationships | null;
|
|
31
|
+
buildSelfLink(instance: ModelLike): JsonApiLink | undefined;
|
|
32
|
+
toJSON(instanceOrCollection: ModelLike | ModelLike[] | null | undefined, options?: PresenterOptions): JsonApiDocument;
|
|
33
|
+
render(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
|
|
34
|
+
};
|
|
35
|
+
adapter: typeof Adapter;
|
|
36
|
+
type: string;
|
|
37
|
+
fields?: string[];
|
|
38
|
+
toJSON(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
|
|
39
|
+
render(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
|
|
40
|
+
}>;
|
|
41
|
+
buildRelationships(instance: ModelLike | null): JsonApiRelationships | null;
|
|
42
|
+
buildSelfLink(instance: ModelLike): JsonApiLink | undefined;
|
|
43
|
+
};
|
|
44
|
+
type: string;
|
|
45
|
+
plural?: string;
|
|
46
|
+
fields?: string[];
|
|
47
|
+
toJSON(instanceOrCollection: ModelLike | ModelLike[] | null, options?: LegacyPresenterOptions): JsonApiDocument;
|
|
48
|
+
render(instanceOrCollection: ModelLike | ModelLike[] | null, _options?: LegacyPresenterOptions): JsonApiDocument;
|
|
49
|
+
adapter: typeof Adapter;
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/yayson/legacy-store.d.ts
|
|
53
|
+
interface LegacyStoreRecordType {
|
|
54
|
+
type: string;
|
|
55
|
+
data: Record<string, unknown> & {
|
|
56
|
+
meta?: Record<string, unknown>;
|
|
57
|
+
links?: Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
interface LegacyLinks {
|
|
61
|
+
[key: string]: {
|
|
62
|
+
type: string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
type LegacyDataValue = Record<string, unknown> | Array<Record<string, unknown>>;
|
|
66
|
+
interface LegacyData {
|
|
67
|
+
links?: LegacyLinks;
|
|
68
|
+
meta?: Record<string, unknown>;
|
|
69
|
+
[key: string]: LegacyDataValue | LegacyLinks | Record<string, unknown> | undefined;
|
|
70
|
+
}
|
|
71
|
+
declare class LegacyStore<S extends SchemaRegistry = SchemaRegistry> {
|
|
72
|
+
types: Record<string, string>;
|
|
73
|
+
records: LegacyStoreRecordType[];
|
|
74
|
+
relations: Record<string, Record<string, string>>;
|
|
75
|
+
schemas?: S;
|
|
76
|
+
strict: boolean;
|
|
77
|
+
validationErrors: ValidationError[];
|
|
78
|
+
models: StoreModels;
|
|
79
|
+
constructor(options?: LegacyStoreOptions<S>);
|
|
80
|
+
reset(): void;
|
|
81
|
+
toModel(rec: LegacyStoreRecordType, type: string, models: StoreModels): StoreModel;
|
|
82
|
+
setupRelations(links: LegacyLinks): void;
|
|
83
|
+
findRecord(type: string, id: string): LegacyStoreRecordType | undefined;
|
|
84
|
+
findRecords(type: string): LegacyStoreRecordType[];
|
|
85
|
+
/** @deprecated Use retrieve() instead. */
|
|
86
|
+
retrive<T extends string>(type: T, data: LegacyData): InferModelType<S, T> | null;
|
|
87
|
+
retrieve<T extends string>(type: T, data: LegacyData): InferModelType<S, T> | null;
|
|
88
|
+
find<T extends string>(type: T, id: string | number, models?: StoreModels): InferModelType<S, T> | null;
|
|
89
|
+
findAll<T extends string>(type: T, models?: StoreModels): InferModelType<S, T>[];
|
|
90
|
+
remove(type: string, id?: string | number): void;
|
|
91
|
+
syncAll(data: LegacyData): StoreResult;
|
|
92
|
+
sync(data: LegacyData): StoreModel | StoreResult;
|
|
93
|
+
retrieveAll<T extends string>(type: T, data: LegacyData): StoreResult<InferModelType<S, T>>;
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/legacy.d.ts
|
|
97
|
+
interface LegacyYaysonResult {
|
|
98
|
+
Store: typeof LegacyStore;
|
|
99
|
+
Presenter: ReturnType<typeof createLegacyPresenter>;
|
|
100
|
+
Adapter: ReturnType<typeof yayson$1>['Adapter'];
|
|
101
|
+
}
|
|
102
|
+
declare function yayson(options?: YaysonOptions): LegacyYaysonResult;
|
|
103
|
+
//#endregion
|
|
104
|
+
export { type Adapter, type JsonApiDocument, type JsonApiLink, type JsonApiLinks, type JsonApiRelationship, type JsonApiRelationships, type JsonApiResource, type LegacyData, yayson as default };
|
|
105
|
+
//# 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,SAAA;EA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CAAY,IAAA,WAAe,qBAAA;;EAK3B,OAAA,kBAAA,CAA0B,IAAA,EAAM,CAAA,EAAG,IAAA,EAAM,UAAA,GAAa,cAAA,CAAe,CAAA,EAAG,CAAA;EAIxE,QAAA,kBAAA,CAA2B,IAAA,EAAM,CAAA,EAAG,IAAA,EAAM,UAAA,GAAa,cAAA,CAAe,CAAA,EAAG,CAAA;EAYzE,IAAA,kBAAA,CAAuB,IAAA,EAAM,CAAA,EAAG,EAAA,mBAAqB,MAAA,GAAS,WAAA,GAAc,cAAA,CAAe,CAAA,EAAG,CAAA;EAc9F,OAAA,kBAAA,CAA0B,IAAA,EAAM,CAAA,EAAG,MAAA,GAAS,WAAA,GAAc,cAAA,CAAe,CAAA,EAAG,CAAA;EAgB5E,MAAA,CAAO,IAAA,UAAc,EAAA;EAsBrB,OAAA,CAAQ,IAAA,EAAM,UAAA,GAAa,WAAA;EA8C3B,IAAA,CAAK,IAAA,EAAM,UAAA,GAAa,UAAA,GAAa,WAAA;EAYrC,WAAA,kBAAA,CAA8B,IAAA,EAAM,CAAA,EAAG,IAAA,EAAM,UAAA,GAAa,WAAA,CAAY,cAAA,CAAe,CAAA,EAAG,CAAA;AAAA;;;UCzPhF,kBAAA;EACR,KAAA,SAAc,WAAA;EACd,SAAA,EAAW,UAAA,QAAkB,qBAAA;EAC7B,OAAA,EAAS,UAAA,QAAkB,QAAA;AAAA;AAAA,iBAGL,MAAA,CAAO,OAAA,GAAU,aAAA,GAAgB,kBAAA"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { T as ModelLike, _ as ValidationError, a as JsonApiRelationship, c as LegacyPresenterOptions, d as SchemaRegistry, f as StoreModel, g as StoreResult, i as JsonApiLinks, l as LegacyStoreOptions, n as JsonApiDocument, o as JsonApiRelationships, p as StoreModels, r as JsonApiLink, s as JsonApiResource, t as InferModelType, u as PresenterOptions, w as Adapter } from "./types-BsfPiPEw.mjs";
|
|
2
|
+
import { i as Presenter, r as yayson$1, t as YaysonOptions } from "./yayson-CRbukIqr.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
|
+
render(instanceOrCollection: ModelLike | ModelLike[] | null): LegacyJsonApiDocument;
|
|
17
|
+
id(instance: ModelLike): string | undefined;
|
|
18
|
+
selfLinks(_instance: ModelLike): JsonApiLink | string | undefined;
|
|
19
|
+
links(_instance?: ModelLike): JsonApiLinks | undefined;
|
|
20
|
+
relationships(): Record<string, {
|
|
21
|
+
new (scope?: JsonApiDocument): {
|
|
22
|
+
constructor: /*elided*/any;
|
|
23
|
+
scope: JsonApiDocument;
|
|
24
|
+
id(instance: ModelLike): string | undefined;
|
|
25
|
+
selfLinks(_instance: ModelLike): JsonApiLink | string | undefined;
|
|
26
|
+
links(_instance?: ModelLike): JsonApiLinks | undefined;
|
|
27
|
+
relationships(): Record<string, /*elided*/any>;
|
|
28
|
+
attributes(instance: ModelLike | null): Record<string, unknown>;
|
|
29
|
+
includeRelationships(scope: JsonApiDocument, instance: ModelLike): unknown[];
|
|
30
|
+
buildRelationships(instance: ModelLike | null): JsonApiRelationships | null;
|
|
31
|
+
buildSelfLink(instance: ModelLike): JsonApiLink | undefined;
|
|
32
|
+
toJSON(instanceOrCollection: ModelLike | ModelLike[] | null | undefined, options?: PresenterOptions): JsonApiDocument;
|
|
33
|
+
render(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
|
|
34
|
+
};
|
|
35
|
+
adapter: typeof Adapter;
|
|
36
|
+
type: string;
|
|
37
|
+
fields?: string[];
|
|
38
|
+
toJSON(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
|
|
39
|
+
render(instanceOrCollection: ModelLike | ModelLike[] | null, options?: PresenterOptions): JsonApiDocument;
|
|
40
|
+
}>;
|
|
41
|
+
buildRelationships(instance: ModelLike | null): JsonApiRelationships | null;
|
|
42
|
+
buildSelfLink(instance: ModelLike): JsonApiLink | undefined;
|
|
43
|
+
};
|
|
44
|
+
type: string;
|
|
45
|
+
plural?: string;
|
|
46
|
+
fields?: string[];
|
|
47
|
+
toJSON(instanceOrCollection: ModelLike | ModelLike[] | null, options?: LegacyPresenterOptions): JsonApiDocument;
|
|
48
|
+
render(instanceOrCollection: ModelLike | ModelLike[] | null, _options?: LegacyPresenterOptions): JsonApiDocument;
|
|
49
|
+
adapter: typeof Adapter;
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/yayson/legacy-store.d.ts
|
|
53
|
+
interface LegacyStoreRecordType {
|
|
54
|
+
type: string;
|
|
55
|
+
data: Record<string, unknown> & {
|
|
56
|
+
meta?: Record<string, unknown>;
|
|
57
|
+
links?: Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
interface LegacyLinks {
|
|
61
|
+
[key: string]: {
|
|
62
|
+
type: string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
type LegacyDataValue = Record<string, unknown> | Array<Record<string, unknown>>;
|
|
66
|
+
interface LegacyData {
|
|
67
|
+
links?: LegacyLinks;
|
|
68
|
+
meta?: Record<string, unknown>;
|
|
69
|
+
[key: string]: LegacyDataValue | LegacyLinks | Record<string, unknown> | undefined;
|
|
70
|
+
}
|
|
71
|
+
declare class LegacyStore<S extends SchemaRegistry = SchemaRegistry> {
|
|
72
|
+
types: Record<string, string>;
|
|
73
|
+
records: LegacyStoreRecordType[];
|
|
74
|
+
relations: Record<string, Record<string, string>>;
|
|
75
|
+
schemas?: S;
|
|
76
|
+
strict: boolean;
|
|
77
|
+
validationErrors: ValidationError[];
|
|
78
|
+
models: StoreModels;
|
|
79
|
+
constructor(options?: LegacyStoreOptions<S>);
|
|
80
|
+
reset(): void;
|
|
81
|
+
toModel(rec: LegacyStoreRecordType, type: string, models: StoreModels): StoreModel;
|
|
82
|
+
setupRelations(links: LegacyLinks): void;
|
|
83
|
+
findRecord(type: string, id: string): LegacyStoreRecordType | undefined;
|
|
84
|
+
findRecords(type: string): LegacyStoreRecordType[];
|
|
85
|
+
/** @deprecated Use retrieve() instead. */
|
|
86
|
+
retrive<T extends string>(type: T, data: LegacyData): InferModelType<S, T> | null;
|
|
87
|
+
retrieve<T extends string>(type: T, data: LegacyData): InferModelType<S, T> | null;
|
|
88
|
+
find<T extends string>(type: T, id: string | number, models?: StoreModels): InferModelType<S, T> | null;
|
|
89
|
+
findAll<T extends string>(type: T, models?: StoreModels): InferModelType<S, T>[];
|
|
90
|
+
remove(type: string, id?: string | number): void;
|
|
91
|
+
syncAll(data: LegacyData): StoreResult;
|
|
92
|
+
sync(data: LegacyData): StoreModel | StoreResult;
|
|
93
|
+
retrieveAll<T extends string>(type: T, data: LegacyData): StoreResult<InferModelType<S, T>>;
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/legacy.d.ts
|
|
97
|
+
interface LegacyYaysonResult {
|
|
98
|
+
Store: typeof LegacyStore;
|
|
99
|
+
Presenter: ReturnType<typeof createLegacyPresenter>;
|
|
100
|
+
Adapter: ReturnType<typeof yayson$1>['Adapter'];
|
|
101
|
+
}
|
|
102
|
+
declare function yayson(options?: YaysonOptions): LegacyYaysonResult;
|
|
103
|
+
//#endregion
|
|
104
|
+
export { type Adapter, type JsonApiDocument, type JsonApiLink, type JsonApiLinks, type JsonApiRelationship, type JsonApiRelationships, type JsonApiResource, type LegacyData, yayson as default };
|
|
105
|
+
//# 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,iBAIqB,qBAAA,CAAsB,SAAA,EAAW,SAAA;EAAA,aASjC,eAAA;iBAbV;WAOK,qBAAA;;yBAsBM,SAAA,UAAmB,MAAA;gCA8BZ,qBAAA,EAAqB,QAAA,EAAY,SAAA;iCAqCrC,SAAA,GAAY,SAAA,uBAA8B,OAAA,GACtD,sBAAA,GACT,qBAAA;iCA6D0B,SAAA,GAAY,SAAA,YAAqB,qBAAA;;;;;;qBA/D1B;;;;;wCA+D0B;;;;;;;;;;;;;;;;;;;;+BAKtC,SAAA,GAAY,SAAA,WAAkB,OAAA,GAC1C,sBAAA,GACT,eAAA;+BAKqB,SAAA,GAAY,SAAA,WAAkB,QAAA,GACzC,sBAAA,GACV,eAAA;kBAAe,OAAA;AAAA;;;UC3KZ,qBAAA;EACR,IAAA;EACA,IAAA,EAAM,MAAA;IACJ,IAAA,GAAO,MAAA;IACP,KAAA,GAAQ,MAAA;EAAA;AAAA;AAAA,UAIF,WAAA;EAAA,CACP,GAAA;IACC,IAAA;EAAA;AAAA;AAAA,KAIC,eAAA,GAAkB,MAAA,oBAA0B,KAAA,CAAM,MAAA;AAAA,UAEtC,UAAA;EACf,KAAA,GAAQ,WAAA;EACR,IAAA,GAAO,MAAA;EAAA,CACN,GAAA,WAAc,eAAA,GAAkB,WAAA,GAAc,MAAA;AAAA;AAAA,cAG5B,WAAA,WAAsB,cAAA,GAAiB,cAAA;EAC1D,KAAA,EAAO,MAAA;EACP,OAAA,EAAS,qBAAA;EACT,SAAA,EAAW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