Skip to content

Commit 08b996e

Browse files
committed
fix: rebuild
1 parent 1c84fdb commit 08b996e

File tree

3 files changed

+89
-30
lines changed

3 files changed

+89
-30
lines changed

dist/index.cjs.js

+37-13
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,28 @@ class Model {
6060
}
6161
}
6262

63-
function debug(level, ...args) {
64-
debug.adapter(level, ...args);
63+
const DEBUG = {
64+
ACCESSING_NOT_INCLUDED_MODEL: 'ACCESSING_NOT_INCLUDED_MODEL',
65+
UNDECLARED_RELATIONSHOP: 'UNDECLARED_RELATIONSHOP',
66+
MISSING_RELATIONSHIP: 'MISSING_RELATIONSHIP',
67+
UNDECLARED_ATTRIBUTE: 'UNDECLARED_ATTRIBUTE',
68+
MISSING_ATTRIBUTE: 'MISSING_ATTRIBUTE',
69+
SKIPPED_INCLUDED_RELATIONSHIP: 'SKIPPED_INCLUDED_RELATIONSHIP'
70+
};
71+
function debug(level, message, meta) {
72+
debug.adapter(level, message, meta);
6573
}
66-
debug.adapter = (level, ...args) => {
74+
debug.adapter = (level, message, meta) => {
6775
switch (level) {
6876
case 'warn':
69-
console.warn(...args);
77+
console.warn(message, meta);
7078
break;
7179
case 'error':
72-
console.error(...args);
80+
console.error(message, meta);
7381
break;
7482
case 'info':
7583
default:
76-
console.log(...args);
84+
console.log(message, meta);
7785
break;
7886
}
7987
};
@@ -143,7 +151,7 @@ class Parser {
143151
return new Proxy(instance, {
144152
get: function (target, prop) {
145153
if (prop === "$_partial") {
146-
return target[prop];
154+
return true;
147155
}
148156
if (prop in target) {
149157
return target[prop];
@@ -152,7 +160,7 @@ class Parser {
152160
debug('error', `Trying to call property "${propString}" to a model that is not included. Add "${loadedElement.type}" to included models.`, {
153161
model: instance,
154162
property: propString,
155-
type: 'ACCESSING_NOT_INCLUDED_MODEL'
163+
type: DEBUG.ACCESSING_NOT_INCLUDED_MODEL
156164
});
157165
return target[prop];
158166
}
@@ -166,7 +174,10 @@ class Parser {
166174
instance[parser.key] = parser.parser(this.parse(relation, included));
167175
} else {
168176
instance[key] = this.parse(relation, included);
169-
debug('warn', `Undeclared relationship "${key}" in "${loadedElement.type}"`);
177+
debug('warn', `Undeclared relationship "${key}" in "${loadedElement.type}"`, {
178+
relationship: key,
179+
type: DEBUG.UNDECLARED_RELATIONSHOP
180+
});
170181
}
171182
}
172183
if (relsData) {
@@ -176,7 +187,10 @@ class Parser {
176187
if ("default" in parser) {
177188
instance[parser.key] = parser.default;
178189
} else {
179-
debug('warn', `Missing relationships "${key}" in "${loadedElement.type}"`);
190+
debug('warn', `Missing relationships "${key}" in "${loadedElement.type}"`, {
191+
relationship: key,
192+
type: DEBUG.MISSING_RELATIONSHIP
193+
});
180194
}
181195
}
182196
}
@@ -189,7 +203,10 @@ class Parser {
189203
instance[parser.key] = parser.parser(loadedElement.attributes[key]);
190204
} else {
191205
instance[key] = loadedElement.attributes[key];
192-
debug('warn', `Undeclared key "${key}" in "${loadedElement.type}"`);
206+
debug('warn', `Undeclared @Attr() "${key}" in model "${loadedElement.type}"`, {
207+
attribute: key,
208+
type: DEBUG.UNDECLARED_ATTRIBUTE
209+
});
193210
}
194211
}
195212
if (attrData) {
@@ -199,7 +216,10 @@ class Parser {
199216
if ("default" in parser) {
200217
instance[parser.key] = parser.default;
201218
} else {
202-
debug('warn', `Missing attribute "${key}" in "${loadedElement.type}"`);
219+
debug('warn', `Missing attribute "${key}" in "${loadedElement.type}"`, {
220+
attribute: key,
221+
type: DEBUG.MISSING_ATTRIBUTE
222+
});
203223
}
204224
}
205225
}
@@ -208,7 +228,10 @@ class Parser {
208228
static load(element, included) {
209229
const found = included.find(e => e.id == element.id && e.type === element.type);
210230
if (!found) {
211-
debug('info', `Relationship with type ${element.type} with id ${element.id} not present in included`);
231+
debug('info', `Relationship with type ${element.type} with id ${element.id} not present in included. Skipping...`, {
232+
model: element,
233+
type: DEBUG.SKIPPED_INCLUDED_RELATIONSHIP
234+
});
212235
}
213236
return found || {
214237
...element,
@@ -270,6 +293,7 @@ function JSONAPI(type) {
270293
}
271294

272295
exports.Attr = Attr;
296+
exports.DEBUG = DEBUG;
273297
exports.JSONAPI = JSONAPI;
274298
exports.Model = Model;
275299
exports.Parser = Parser;

dist/index.esm.js

+37-14
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,28 @@ class Model {
5656
}
5757
}
5858

59-
function debug(level, ...args) {
60-
debug.adapter(level, ...args);
59+
const DEBUG = {
60+
ACCESSING_NOT_INCLUDED_MODEL: 'ACCESSING_NOT_INCLUDED_MODEL',
61+
UNDECLARED_RELATIONSHOP: 'UNDECLARED_RELATIONSHOP',
62+
MISSING_RELATIONSHIP: 'MISSING_RELATIONSHIP',
63+
UNDECLARED_ATTRIBUTE: 'UNDECLARED_ATTRIBUTE',
64+
MISSING_ATTRIBUTE: 'MISSING_ATTRIBUTE',
65+
SKIPPED_INCLUDED_RELATIONSHIP: 'SKIPPED_INCLUDED_RELATIONSHIP'
66+
};
67+
function debug(level, message, meta) {
68+
debug.adapter(level, message, meta);
6169
}
62-
debug.adapter = (level, ...args) => {
70+
debug.adapter = (level, message, meta) => {
6371
switch (level) {
6472
case 'warn':
65-
console.warn(...args);
73+
console.warn(message, meta);
6674
break;
6775
case 'error':
68-
console.error(...args);
76+
console.error(message, meta);
6977
break;
7078
case 'info':
7179
default:
72-
console.log(...args);
80+
console.log(message, meta);
7381
break;
7482
}
7583
};
@@ -139,7 +147,7 @@ class Parser {
139147
return new Proxy(instance, {
140148
get: function (target, prop) {
141149
if (prop === "$_partial") {
142-
return target[prop];
150+
return true;
143151
}
144152
if (prop in target) {
145153
return target[prop];
@@ -148,7 +156,7 @@ class Parser {
148156
debug('error', `Trying to call property "${propString}" to a model that is not included. Add "${loadedElement.type}" to included models.`, {
149157
model: instance,
150158
property: propString,
151-
type: 'ACCESSING_NOT_INCLUDED_MODEL'
159+
type: DEBUG.ACCESSING_NOT_INCLUDED_MODEL
152160
});
153161
return target[prop];
154162
}
@@ -162,7 +170,10 @@ class Parser {
162170
instance[parser.key] = parser.parser(this.parse(relation, included));
163171
} else {
164172
instance[key] = this.parse(relation, included);
165-
debug('warn', `Undeclared relationship "${key}" in "${loadedElement.type}"`);
173+
debug('warn', `Undeclared relationship "${key}" in "${loadedElement.type}"`, {
174+
relationship: key,
175+
type: DEBUG.UNDECLARED_RELATIONSHOP
176+
});
166177
}
167178
}
168179
if (relsData) {
@@ -172,7 +183,10 @@ class Parser {
172183
if ("default" in parser) {
173184
instance[parser.key] = parser.default;
174185
} else {
175-
debug('warn', `Missing relationships "${key}" in "${loadedElement.type}"`);
186+
debug('warn', `Missing relationships "${key}" in "${loadedElement.type}"`, {
187+
relationship: key,
188+
type: DEBUG.MISSING_RELATIONSHIP
189+
});
176190
}
177191
}
178192
}
@@ -185,7 +199,10 @@ class Parser {
185199
instance[parser.key] = parser.parser(loadedElement.attributes[key]);
186200
} else {
187201
instance[key] = loadedElement.attributes[key];
188-
debug('warn', `Undeclared key "${key}" in "${loadedElement.type}"`);
202+
debug('warn', `Undeclared @Attr() "${key}" in model "${loadedElement.type}"`, {
203+
attribute: key,
204+
type: DEBUG.UNDECLARED_ATTRIBUTE
205+
});
189206
}
190207
}
191208
if (attrData) {
@@ -195,7 +212,10 @@ class Parser {
195212
if ("default" in parser) {
196213
instance[parser.key] = parser.default;
197214
} else {
198-
debug('warn', `Missing attribute "${key}" in "${loadedElement.type}"`);
215+
debug('warn', `Missing attribute "${key}" in "${loadedElement.type}"`, {
216+
attribute: key,
217+
type: DEBUG.MISSING_ATTRIBUTE
218+
});
199219
}
200220
}
201221
}
@@ -204,7 +224,10 @@ class Parser {
204224
static load(element, included) {
205225
const found = included.find(e => e.id == element.id && e.type === element.type);
206226
if (!found) {
207-
debug('info', `Relationship with type ${element.type} with id ${element.id} not present in included`);
227+
debug('info', `Relationship with type ${element.type} with id ${element.id} not present in included. Skipping...`, {
228+
model: element,
229+
type: DEBUG.SKIPPED_INCLUDED_RELATIONSHIP
230+
});
208231
}
209232
return found || {
210233
...element,
@@ -265,4 +288,4 @@ function JSONAPI(type) {
265288
};
266289
}
267290

268-
export { Attr, JSONAPI, Model, Parser, Rel, debug };
291+
export { Attr, DEBUG, JSONAPI, Model, Parser, Rel, debug };

dist/types/utils.d.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
declare function debug(level: 'info' | 'warn' | 'error', ...args: any[]): void;
1+
declare const DEBUG: {
2+
ACCESSING_NOT_INCLUDED_MODEL: "ACCESSING_NOT_INCLUDED_MODEL";
3+
UNDECLARED_RELATIONSHOP: "UNDECLARED_RELATIONSHOP";
4+
MISSING_RELATIONSHIP: "MISSING_RELATIONSHIP";
5+
UNDECLARED_ATTRIBUTE: "UNDECLARED_ATTRIBUTE";
6+
MISSING_ATTRIBUTE: "MISSING_ATTRIBUTE";
7+
SKIPPED_INCLUDED_RELATIONSHIP: "SKIPPED_INCLUDED_RELATIONSHIP";
8+
};
9+
type DebugMetadata = {
10+
type: keyof typeof DEBUG;
11+
[key: string]: unknown;
12+
};
13+
declare function debug(level: 'info' | 'warn' | 'error', message: string, meta?: DebugMetadata): void;
214
declare namespace debug {
3-
var adapter: (level: "error" | "info" | "warn", ...args: any[]) => void;
15+
var adapter: (level: "error" | "info" | "warn", message: string, meta?: DebugMetadata | undefined) => void;
416
}
5-
export { debug };
17+
export { debug, DEBUG };

0 commit comments

Comments
 (0)