@h3ravel/arquebus 0.6.6 → 0.6.7
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 +5 -4
- package/package.json +4 -3
- package/bin/index.cjs +0 -5927
- package/bin/index.d.cts +0 -1
- package/bin/index.d.ts +0 -1
- package/bin/index.js +0 -5925
- package/bin/seeders-8GJzfIIN.js +0 -3
- package/bin/seeders-ByeSoCAQ.cjs +0 -131
- package/bin/seeders-CltigymO.js +0 -79
- package/bin/seeders-_xJ6VGVS.cjs +0 -3
- package/dist/browser/index.cjs +0 -1271
- package/dist/browser/index.d.cts +0 -4932
- package/dist/browser/index.d.ts +0 -4932
- package/dist/browser/index.js +0 -1218
- package/dist/index.cjs +0 -5713
- package/dist/index.d.cts +0 -5129
- package/dist/index.d.ts +0 -5129
- package/dist/index.js +0 -5644
- package/dist/inspector/index.cjs +0 -4908
- package/dist/inspector/index.d.cts +0 -83
- package/dist/inspector/index.d.ts +0 -83
- package/dist/inspector/index.js +0 -4881
- package/dist/migrations/chunk-PECeCxCb.js +0 -15
- package/dist/migrations/index.cjs +0 -5470
- package/dist/migrations/index.d.cts +0 -4965
- package/dist/migrations/index.d.ts +0 -4962
- package/dist/migrations/index.js +0 -5419
- package/dist/migrations/stubs/migration-js.stub +0 -21
- package/dist/migrations/stubs/migration-ts.stub +0 -18
- package/dist/migrations/stubs/migration.create-js.stub +0 -24
- package/dist/migrations/stubs/migration.create-ts.stub +0 -21
- package/dist/migrations/stubs/migration.update-js.stub +0 -25
- package/dist/migrations/stubs/migration.update-ts.stub +0 -22
- package/dist/seeders/index.cjs +0 -141
- package/dist/seeders/index.d.cts +0 -4766
- package/dist/seeders/index.d.ts +0 -4766
- package/dist/seeders/index.js +0 -118
- package/dist/seeders/index.ts +0 -3
- package/dist/seeders/runner.ts +0 -101
- package/dist/seeders/seeder-creator.ts +0 -42
- package/dist/seeders/seeder.ts +0 -10
- package/dist/stubs/arquebus.config-js.stub +0 -25
- package/dist/stubs/arquebus.config-ts.stub +0 -24
- package/dist/stubs/model-js.stub +0 -5
- package/dist/stubs/model-ts.stub +0 -5
- package/dist/stubs/seeder-js.stub +0 -13
- package/dist/stubs/seeder-ts.stub +0 -9
package/dist/browser/index.cjs
DELETED
|
@@ -1,1271 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
-
//#region rolldown:runtime
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (all) => {
|
|
10
|
-
let target = {};
|
|
11
|
-
for (var name in all) __defProp(target, name, {
|
|
12
|
-
get: all[name],
|
|
13
|
-
enumerable: true
|
|
14
|
-
});
|
|
15
|
-
return target;
|
|
16
|
-
};
|
|
17
|
-
var __copyProps = (to, from, except, desc) => {
|
|
18
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
19
|
-
key = keys[i];
|
|
20
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
21
|
-
get: ((k) => from[k]).bind(null, key),
|
|
22
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return to;
|
|
26
|
-
};
|
|
27
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
30
|
-
}) : target, mod));
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
let collect_js = require("collect.js");
|
|
34
|
-
collect_js = __toESM(collect_js);
|
|
35
|
-
let radashi = require("radashi");
|
|
36
|
-
radashi = __toESM(radashi);
|
|
37
|
-
let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
|
|
38
|
-
dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js);
|
|
39
|
-
let dayjs = require("dayjs");
|
|
40
|
-
dayjs = __toESM(dayjs);
|
|
41
|
-
let pluralize = require("pluralize");
|
|
42
|
-
pluralize = __toESM(pluralize);
|
|
43
|
-
|
|
44
|
-
//#region src/casts/attribute.ts
|
|
45
|
-
var Attribute = class Attribute {
|
|
46
|
-
get;
|
|
47
|
-
set;
|
|
48
|
-
withCaching = false;
|
|
49
|
-
withObjectCaching = true;
|
|
50
|
-
constructor({ get = null, set = null }) {
|
|
51
|
-
this.get = get;
|
|
52
|
-
this.set = set;
|
|
53
|
-
}
|
|
54
|
-
static make({ get = null, set = null }) {
|
|
55
|
-
return new Attribute({
|
|
56
|
-
get,
|
|
57
|
-
set
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
static get(get) {
|
|
61
|
-
return new Attribute({ get });
|
|
62
|
-
}
|
|
63
|
-
static set(set) {
|
|
64
|
-
return new Attribute({ set });
|
|
65
|
-
}
|
|
66
|
-
withoutObjectCaching() {
|
|
67
|
-
this.withObjectCaching = false;
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
shouldCache() {
|
|
71
|
-
this.withCaching = true;
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
var attribute_default = Attribute;
|
|
76
|
-
|
|
77
|
-
//#endregion
|
|
78
|
-
//#region src/casts-attributes.ts
|
|
79
|
-
var CastsAttributes = class CastsAttributes {
|
|
80
|
-
constructor() {
|
|
81
|
-
if (this.constructor === CastsAttributes) throw new Error("CastsAttributes cannot be instantiated");
|
|
82
|
-
}
|
|
83
|
-
static get(_model, _key, _value, _attributes) {
|
|
84
|
-
throw new Error("get not implemented");
|
|
85
|
-
}
|
|
86
|
-
static set(_model, _key, _value, _attributes) {
|
|
87
|
-
throw new Error("set not implemented");
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
var casts_attributes_default = CastsAttributes;
|
|
91
|
-
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region src/mixin.ts
|
|
94
|
-
var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
95
|
-
/**
|
|
96
|
-
* Compose function that merges multiple classes and mixins
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* const SomePlugin = <TBase extends new (...args: any[]) => TGeneric> (Base: TBase) => {
|
|
100
|
-
* return class extends Base {
|
|
101
|
-
* pluginAttribtue = 'plugin'
|
|
102
|
-
* pluginMethod () {
|
|
103
|
-
* return this.pluginAttribtue
|
|
104
|
-
* }
|
|
105
|
-
* }
|
|
106
|
-
* }
|
|
107
|
-
*
|
|
108
|
-
* // Base class
|
|
109
|
-
* class Model {
|
|
110
|
-
* make () {
|
|
111
|
-
* console.log('make')
|
|
112
|
-
* }
|
|
113
|
-
* pluginMethod (id: string) {
|
|
114
|
-
* }
|
|
115
|
-
* }
|
|
116
|
-
*
|
|
117
|
-
* class User extends compose(
|
|
118
|
-
* Model,
|
|
119
|
-
* SomePlugin,
|
|
120
|
-
* ) {
|
|
121
|
-
* relationPosts () {
|
|
122
|
-
* return 'hasMany Posts'
|
|
123
|
-
* }
|
|
124
|
-
* }
|
|
125
|
-
*
|
|
126
|
-
* const user = new User()
|
|
127
|
-
* user.make() // from Model
|
|
128
|
-
* user.pluginMethod() // from SomePlugin
|
|
129
|
-
* user.relationPosts() // from User
|
|
130
|
-
*
|
|
131
|
-
* console.log(user.pluginMethod('w')) // "plugin"
|
|
132
|
-
* console.log(user.pluginMethod()) // "plugin"
|
|
133
|
-
* console.log(user.relationPosts()) // "hasMany Posts"
|
|
134
|
-
*
|
|
135
|
-
* @param Base
|
|
136
|
-
* @param mixins
|
|
137
|
-
* @returns
|
|
138
|
-
*/
|
|
139
|
-
function compose$1(Base, ...mixins) {
|
|
140
|
-
/**
|
|
141
|
-
* Apply each mixin or class in sequence
|
|
142
|
-
*/
|
|
143
|
-
return mixins.reduce((acc, mixin) => {
|
|
144
|
-
if (typeof mixin === "function" && mixin.prototype)
|
|
145
|
-
/**
|
|
146
|
-
* If it's a class constructor, extend it
|
|
147
|
-
*/
|
|
148
|
-
return class extends acc {
|
|
149
|
-
constructor(...args) {
|
|
150
|
-
super(...args);
|
|
151
|
-
/**
|
|
152
|
-
* Copy instance properties from mixin prototype
|
|
153
|
-
*/
|
|
154
|
-
Object.getOwnPropertyNames(mixin.prototype).forEach((name) => {
|
|
155
|
-
if (name !== "constructor") Object.defineProperty(this, name, Object.getOwnPropertyDescriptor(mixin.prototype, name));
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
else if (typeof mixin === "function")
|
|
160
|
-
/**
|
|
161
|
-
* If it's a mixin function, call it with current class
|
|
162
|
-
*/
|
|
163
|
-
return mixin(acc);
|
|
164
|
-
return acc;
|
|
165
|
-
}, Base);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
//#endregion
|
|
169
|
-
//#region src/utils.ts
|
|
170
|
-
dayjs.default.extend(dayjs_plugin_advancedFormat_js.default);
|
|
171
|
-
const now = (format = "YYYY-MM-DD HH:mm:ss") => (0, dayjs.default)().format(format);
|
|
172
|
-
const getRelationName = (relationMethod) => {
|
|
173
|
-
return (0, radashi.snake)(relationMethod.substring(8));
|
|
174
|
-
};
|
|
175
|
-
const getScopeName = (scopeMethod) => {
|
|
176
|
-
return (0, radashi.snake)(scopeMethod.substring(5));
|
|
177
|
-
};
|
|
178
|
-
const getRelationMethod = (relation) => {
|
|
179
|
-
return (0, radashi.camel)(`relation_${relation}`);
|
|
180
|
-
};
|
|
181
|
-
const getScopeMethod = (scope) => {
|
|
182
|
-
return (0, radashi.camel)(`scope_${scope}`);
|
|
183
|
-
};
|
|
184
|
-
const getAttrMethod = (attr) => {
|
|
185
|
-
return (0, radashi.camel)(`attribute_${attr}`);
|
|
186
|
-
};
|
|
187
|
-
const getGetterMethod = (attr) => {
|
|
188
|
-
return (0, radashi.camel)(`get_${attr}_attribute`);
|
|
189
|
-
};
|
|
190
|
-
const getSetterMethod = (attr) => {
|
|
191
|
-
return (0, radashi.camel)(`set_${attr}_attribute`);
|
|
192
|
-
};
|
|
193
|
-
const getAttrName = (attrMethod) => {
|
|
194
|
-
return attrMethod.substring(3, attrMethod.length - 9).toLowerCase();
|
|
195
|
-
};
|
|
196
|
-
/**
|
|
197
|
-
* Tap into a model a collection instance
|
|
198
|
-
*
|
|
199
|
-
* @param instance
|
|
200
|
-
* @param callback
|
|
201
|
-
* @returns
|
|
202
|
-
*/
|
|
203
|
-
const tap = (instance, callback) => {
|
|
204
|
-
const result = callback(instance);
|
|
205
|
-
return result instanceof Promise ? result.then(() => instance) : instance;
|
|
206
|
-
};
|
|
207
|
-
const { compose } = mixin_exports;
|
|
208
|
-
const flatten = (arr) => arr.flat();
|
|
209
|
-
const flattenDeep = (arr) => Array.isArray(arr) ? arr.reduce((a, b) => a.concat(flattenDeep(b)), []) : [arr];
|
|
210
|
-
const kebabCase = (str) => (0, radashi.trim)((0, radashi.dash)(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-");
|
|
211
|
-
const snakeCase = (str) => (0, radashi.trim)((0, radashi.snake)(str.replace(/[^a-zA-Z0-9_-]/g, "-")), "_-");
|
|
212
|
-
const defineConfig = (config) => {
|
|
213
|
-
return config;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
//#endregion
|
|
217
|
-
//#region src/browser/relations/relation.ts
|
|
218
|
-
var Relation = class {
|
|
219
|
-
parent;
|
|
220
|
-
related;
|
|
221
|
-
eagerKeysWereEmpty = false;
|
|
222
|
-
static constraints = true;
|
|
223
|
-
constructor(related, parent) {
|
|
224
|
-
this.parent = parent;
|
|
225
|
-
this.related = related;
|
|
226
|
-
}
|
|
227
|
-
asProxy() {
|
|
228
|
-
return new Proxy(this, { get: function(target, prop) {
|
|
229
|
-
if (typeof target[prop] !== "undefined") return target[prop];
|
|
230
|
-
if (typeof prop === "string") return () => target.asProxy();
|
|
231
|
-
} });
|
|
232
|
-
}
|
|
233
|
-
getRelated() {
|
|
234
|
-
return this.related;
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
var relation_default = Relation;
|
|
238
|
-
|
|
239
|
-
//#endregion
|
|
240
|
-
//#region src/browser/relations/belongs-to.ts
|
|
241
|
-
var BelongsTo = class extends relation_default {
|
|
242
|
-
foreignKey;
|
|
243
|
-
ownerKey;
|
|
244
|
-
child;
|
|
245
|
-
relationName;
|
|
246
|
-
constructor(related, child, foreignKey, ownerKey, relationName) {
|
|
247
|
-
super(related, child);
|
|
248
|
-
this.foreignKey = foreignKey;
|
|
249
|
-
this.ownerKey = ownerKey;
|
|
250
|
-
this.child = child;
|
|
251
|
-
this.relationName = relationName;
|
|
252
|
-
return this.asProxy();
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
var belongs_to_default = BelongsTo;
|
|
256
|
-
|
|
257
|
-
//#endregion
|
|
258
|
-
//#region src/browser/relations/belongs-to-many.ts
|
|
259
|
-
var BelongsToMany = class extends relation_default {
|
|
260
|
-
table;
|
|
261
|
-
foreignPivotKey;
|
|
262
|
-
relatedPivotKey;
|
|
263
|
-
parentKey;
|
|
264
|
-
relatedKey;
|
|
265
|
-
pivotColumns = [];
|
|
266
|
-
pivotValues = [];
|
|
267
|
-
pivotWheres = [];
|
|
268
|
-
pivotWhereIns = [];
|
|
269
|
-
pivotWhereNulls = [];
|
|
270
|
-
accessor = "pivot";
|
|
271
|
-
using;
|
|
272
|
-
pivotCreatedAt;
|
|
273
|
-
pivotUpdatedAt;
|
|
274
|
-
constructor(related, parent, table, foreignPivotKey, relatedPivotKey, parentKey, relatedKey) {
|
|
275
|
-
super(related, parent);
|
|
276
|
-
this.table = table;
|
|
277
|
-
this.foreignPivotKey = foreignPivotKey;
|
|
278
|
-
this.relatedPivotKey = relatedPivotKey;
|
|
279
|
-
this.parentKey = parentKey;
|
|
280
|
-
this.relatedKey = relatedKey;
|
|
281
|
-
return this.asProxy();
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
var belongs_to_many_default = BelongsToMany;
|
|
285
|
-
|
|
286
|
-
//#endregion
|
|
287
|
-
//#region src/concerns/has-attributes.ts
|
|
288
|
-
const HasAttributes = (Model$1) => {
|
|
289
|
-
return class extends Model$1 {
|
|
290
|
-
static castTypeCache = {};
|
|
291
|
-
attributes = {};
|
|
292
|
-
original = {};
|
|
293
|
-
casts = {};
|
|
294
|
-
changes = {};
|
|
295
|
-
appends = [];
|
|
296
|
-
setAppends(appends) {
|
|
297
|
-
this.appends = appends;
|
|
298
|
-
return this;
|
|
299
|
-
}
|
|
300
|
-
append(...keys) {
|
|
301
|
-
const appends = flattenDeep(keys);
|
|
302
|
-
this.appends = [...this.appends, ...appends];
|
|
303
|
-
return this;
|
|
304
|
-
}
|
|
305
|
-
normalizeCastClassResponse(key, value) {
|
|
306
|
-
var _value$constructor;
|
|
307
|
-
return (value === null || value === void 0 || (_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor.name) === "Object" ? value : { [key]: value };
|
|
308
|
-
}
|
|
309
|
-
syncOriginal() {
|
|
310
|
-
this.original = this.getAttributes();
|
|
311
|
-
return this;
|
|
312
|
-
}
|
|
313
|
-
syncChanges() {
|
|
314
|
-
this.changes = this.getDirty();
|
|
315
|
-
return this;
|
|
316
|
-
}
|
|
317
|
-
syncOriginalAttribute(attribute) {
|
|
318
|
-
this.syncOriginalAttributes(attribute);
|
|
319
|
-
}
|
|
320
|
-
syncOriginalAttributes(...attributes) {
|
|
321
|
-
attributes = flattenDeep(attributes);
|
|
322
|
-
const modelAttributes = this.getAttributes();
|
|
323
|
-
for (const attribute of attributes) this.original[attribute] = modelAttributes[attribute];
|
|
324
|
-
return this;
|
|
325
|
-
}
|
|
326
|
-
isDirty(...attributes) {
|
|
327
|
-
const changes = this.getDirty();
|
|
328
|
-
attributes = flattenDeep(attributes);
|
|
329
|
-
if (attributes.length === 0) return Object.keys(changes).length > 0;
|
|
330
|
-
for (const attribute of attributes) if (attribute in changes) return true;
|
|
331
|
-
return false;
|
|
332
|
-
}
|
|
333
|
-
getDirty() {
|
|
334
|
-
const dirty = {};
|
|
335
|
-
const attributes = this.getAttributes();
|
|
336
|
-
for (const key in attributes) {
|
|
337
|
-
const value = attributes[key];
|
|
338
|
-
if (!this.originalIsEquivalent(key)) dirty[key] = value;
|
|
339
|
-
}
|
|
340
|
-
return dirty;
|
|
341
|
-
}
|
|
342
|
-
originalIsEquivalent(key) {
|
|
343
|
-
if (this.original[key] === void 0) return false;
|
|
344
|
-
const attribute = this.attributes[key];
|
|
345
|
-
const original = this.original[key];
|
|
346
|
-
if (attribute === original) return true;
|
|
347
|
-
else return false;
|
|
348
|
-
}
|
|
349
|
-
setAttributes(attributes) {
|
|
350
|
-
this.attributes = { ...attributes };
|
|
351
|
-
}
|
|
352
|
-
setRawAttributes(attributes, sync = false) {
|
|
353
|
-
this.attributes = attributes;
|
|
354
|
-
if (sync) this.syncOriginal();
|
|
355
|
-
return this;
|
|
356
|
-
}
|
|
357
|
-
getAttributes() {
|
|
358
|
-
return { ...this.attributes };
|
|
359
|
-
}
|
|
360
|
-
setAttribute(key, value) {
|
|
361
|
-
const setterMethod = getSetterMethod(key);
|
|
362
|
-
if (typeof this[setterMethod] === "function") {
|
|
363
|
-
this[setterMethod](value);
|
|
364
|
-
return this;
|
|
365
|
-
}
|
|
366
|
-
const attrMethod = getAttrMethod(key);
|
|
367
|
-
if (typeof this[attrMethod] === "function") {
|
|
368
|
-
const callback = this[attrMethod]().set || ((value$1) => {
|
|
369
|
-
this.attributes[key] = value$1;
|
|
370
|
-
});
|
|
371
|
-
this.attributes = {
|
|
372
|
-
...this.attributes,
|
|
373
|
-
...this.normalizeCastClassResponse(key, callback(value, this.attributes))
|
|
374
|
-
};
|
|
375
|
-
return this;
|
|
376
|
-
}
|
|
377
|
-
const castType = this.getCasts()[key];
|
|
378
|
-
if (this.isCustomCast(castType) && typeof castType !== "string") value = castType.set(this, key, value, this.attributes) ?? "";
|
|
379
|
-
if (castType === "json") value = JSON.stringify(value);
|
|
380
|
-
if (castType === "collection") value = JSON.stringify(value);
|
|
381
|
-
if (value !== null && this.isDateAttribute(key)) value = this.fromDateTime(value);
|
|
382
|
-
this.attributes[key] = value;
|
|
383
|
-
return this;
|
|
384
|
-
}
|
|
385
|
-
getAttribute(key) {
|
|
386
|
-
if (!key) return;
|
|
387
|
-
const getterMethod = getGetterMethod(key);
|
|
388
|
-
if (typeof this[getterMethod] === "function") return this[getterMethod](this.attributes[key], this.attributes);
|
|
389
|
-
const attrMethod = getAttrMethod(key);
|
|
390
|
-
if (typeof this[attrMethod] === "function") return this[attrMethod]().get(this.attributes[key], this.attributes);
|
|
391
|
-
if (key in this.attributes) {
|
|
392
|
-
if (this.hasCast(key)) return this.castAttribute(key, this.attributes[key]);
|
|
393
|
-
if (this.getDates().includes(key)) return this.asDateTime(this.attributes[key]);
|
|
394
|
-
return this.attributes[key];
|
|
395
|
-
}
|
|
396
|
-
if (key in this.relations) return this.relations[key];
|
|
397
|
-
}
|
|
398
|
-
castAttribute(key, value) {
|
|
399
|
-
const castType = this.getCastType(key);
|
|
400
|
-
if (!castType) return value;
|
|
401
|
-
if (value === null) return value;
|
|
402
|
-
switch (castType) {
|
|
403
|
-
case "int":
|
|
404
|
-
case "integer": return parseInt(value);
|
|
405
|
-
case "real":
|
|
406
|
-
case "float":
|
|
407
|
-
case "double": return parseFloat(value);
|
|
408
|
-
case "decimal": return this.asDecimal(value, castType.split(":")[1]);
|
|
409
|
-
case "string": return String(value);
|
|
410
|
-
case "bool":
|
|
411
|
-
case "boolean": return Boolean(value);
|
|
412
|
-
case "object":
|
|
413
|
-
case "json": try {
|
|
414
|
-
return JSON.parse(value);
|
|
415
|
-
} catch {
|
|
416
|
-
return null;
|
|
417
|
-
}
|
|
418
|
-
case "collection": try {
|
|
419
|
-
return (0, collect_js.default)(JSON.parse(value));
|
|
420
|
-
} catch {
|
|
421
|
-
return (0, collect_js.default)([]);
|
|
422
|
-
}
|
|
423
|
-
case "date": return this.asDate(value);
|
|
424
|
-
case "datetime":
|
|
425
|
-
case "custom_datetime": return this.asDateTime(value);
|
|
426
|
-
case "timestamp": return this.asTimestamp(value);
|
|
427
|
-
}
|
|
428
|
-
if (this.isCustomCast(castType)) return castType.get(this, key, value, this.attributes);
|
|
429
|
-
return value;
|
|
430
|
-
}
|
|
431
|
-
attributesToData() {
|
|
432
|
-
let attributes = { ...this.attributes };
|
|
433
|
-
for (const key in attributes) {
|
|
434
|
-
if (this.hidden.includes(key)) attributes = (0, radashi.omit)(attributes, [key]);
|
|
435
|
-
if (this.visible.length > 0 && this.visible.includes(key) === false) attributes = (0, radashi.omit)(attributes, [key]);
|
|
436
|
-
}
|
|
437
|
-
for (const key of this.getDates()) {
|
|
438
|
-
if (attributes[key] === void 0) continue;
|
|
439
|
-
attributes[key] = this.serializeDate(this.asDateTime(attributes[key]));
|
|
440
|
-
}
|
|
441
|
-
const casts = this.getCasts();
|
|
442
|
-
for (const key in casts) {
|
|
443
|
-
const value = casts[key];
|
|
444
|
-
if (key in attributes === false) continue;
|
|
445
|
-
attributes[key] = this.castAttribute(key, attributes[key]);
|
|
446
|
-
if (key in attributes && ["date", "datetime"].includes(String(value))) attributes[key] = this.serializeDate(attributes[key]);
|
|
447
|
-
if (key in attributes && this.isCustomDateTimeCast(value)) attributes[key] = (0, dayjs.default)(attributes[key]).format(String(value).split(":")[1]);
|
|
448
|
-
}
|
|
449
|
-
for (const key of this.appends) attributes[key] = this.mutateAttribute(key, null);
|
|
450
|
-
return attributes;
|
|
451
|
-
}
|
|
452
|
-
mutateAttribute(key, value) {
|
|
453
|
-
if (typeof this[getGetterMethod(key)] === "function") return this[getGetterMethod(key)](value);
|
|
454
|
-
else if (typeof this[getAttrMethod(key)] === "function") return this[getAttrMethod(key)]().get(key, this.attributes);
|
|
455
|
-
else if (key in this) return this[key];
|
|
456
|
-
return value;
|
|
457
|
-
}
|
|
458
|
-
mutateAttributeForArray(_key, _value) {}
|
|
459
|
-
isDateAttribute(key) {
|
|
460
|
-
return this.getDates().includes(key) || this.isDateCastable(key);
|
|
461
|
-
}
|
|
462
|
-
serializeDate(date) {
|
|
463
|
-
return date ? (0, dayjs.default)(date).toISOString() : null;
|
|
464
|
-
}
|
|
465
|
-
getDates() {
|
|
466
|
-
return this.usesTimestamps() ? [this.getCreatedAtColumn(), this.getUpdatedAtColumn()] : [];
|
|
467
|
-
}
|
|
468
|
-
getCasts() {
|
|
469
|
-
if (this.getIncrementing()) return {
|
|
470
|
-
[this.getKeyName()]: this.getKeyType(),
|
|
471
|
-
...this.casts
|
|
472
|
-
};
|
|
473
|
-
return this.casts;
|
|
474
|
-
}
|
|
475
|
-
getCastType(key) {
|
|
476
|
-
const castType = this.getCasts()[key];
|
|
477
|
-
let castTypeCacheKey;
|
|
478
|
-
if (typeof castType === "string") castTypeCacheKey = castType;
|
|
479
|
-
else if (new castType() instanceof casts_attributes_default) castTypeCacheKey = castType.name;
|
|
480
|
-
if (castTypeCacheKey && this.getConstructor().castTypeCache[castTypeCacheKey] !== void 0) return this.getConstructor().castTypeCache[castTypeCacheKey];
|
|
481
|
-
let convertedCastType;
|
|
482
|
-
if (this.isCustomDateTimeCast(castType)) convertedCastType = "custom_datetime";
|
|
483
|
-
else if (this.isDecimalCast(castType)) convertedCastType = "decimal";
|
|
484
|
-
else if (this.isCustomCast(castType)) convertedCastType = castType;
|
|
485
|
-
else convertedCastType = String(castType).toLocaleLowerCase().trim();
|
|
486
|
-
return this.getConstructor()[castTypeCacheKey] = convertedCastType;
|
|
487
|
-
}
|
|
488
|
-
hasCast(key, types = []) {
|
|
489
|
-
if (key in this.casts) {
|
|
490
|
-
types = (0, radashi.flat)(types);
|
|
491
|
-
return types.length > 0 ? types.includes(this.getCastType(key)) : true;
|
|
492
|
-
}
|
|
493
|
-
return false;
|
|
494
|
-
}
|
|
495
|
-
withDayjs(date) {
|
|
496
|
-
return (0, dayjs.default)(date);
|
|
497
|
-
}
|
|
498
|
-
isCustomCast(cast) {
|
|
499
|
-
return typeof cast === "function" && new cast() instanceof casts_attributes_default;
|
|
500
|
-
}
|
|
501
|
-
isCustomDateTimeCast(cast) {
|
|
502
|
-
if (typeof cast !== "string") return false;
|
|
503
|
-
return cast.startsWith("date:") || cast.startsWith("datetime:");
|
|
504
|
-
}
|
|
505
|
-
isDecimalCast(cast) {
|
|
506
|
-
if (typeof cast !== "string") return false;
|
|
507
|
-
return cast.startsWith("decimal:");
|
|
508
|
-
}
|
|
509
|
-
isDateCastable(key) {
|
|
510
|
-
return this.hasCast(key, ["date", "datetime"]);
|
|
511
|
-
}
|
|
512
|
-
fromDateTime(value) {
|
|
513
|
-
return (0, dayjs.default)(this.asDateTime(value)).format(this.getDateFormat());
|
|
514
|
-
}
|
|
515
|
-
getDateFormat() {
|
|
516
|
-
return this.dateFormat || "YYYY-MM-DD HH:mm:ss";
|
|
517
|
-
}
|
|
518
|
-
asDecimal(value, decimals) {
|
|
519
|
-
return parseFloat(value).toFixed(decimals);
|
|
520
|
-
}
|
|
521
|
-
asDateTime(value) {
|
|
522
|
-
if (value === null) return null;
|
|
523
|
-
if (value instanceof Date) return value;
|
|
524
|
-
if (typeof value === "number") return /* @__PURE__ */ new Date(value * 1e3);
|
|
525
|
-
return new Date(value);
|
|
526
|
-
}
|
|
527
|
-
asDate(value) {
|
|
528
|
-
const date = this.asDateTime(value);
|
|
529
|
-
return (0, dayjs.default)(date).startOf("day").toDate();
|
|
530
|
-
}
|
|
531
|
-
};
|
|
532
|
-
};
|
|
533
|
-
var has_attributes_default = HasAttributes;
|
|
534
|
-
|
|
535
|
-
//#endregion
|
|
536
|
-
//#region src/browser/relations/has-many.ts
|
|
537
|
-
var HasMany = class extends relation_default {
|
|
538
|
-
foreignKey;
|
|
539
|
-
localKey;
|
|
540
|
-
constructor(related, parent, foreignKey, localKey) {
|
|
541
|
-
super(related, parent);
|
|
542
|
-
this.foreignKey = foreignKey;
|
|
543
|
-
this.localKey = localKey;
|
|
544
|
-
return this.asProxy();
|
|
545
|
-
}
|
|
546
|
-
};
|
|
547
|
-
var has_many_default = HasMany;
|
|
548
|
-
|
|
549
|
-
//#endregion
|
|
550
|
-
//#region src/browser/relations/has-one.ts
|
|
551
|
-
var HasOne = class extends relation_default {
|
|
552
|
-
foreignKey;
|
|
553
|
-
localKey;
|
|
554
|
-
constructor(related, parent, foreignKey, localKey) {
|
|
555
|
-
super(related, parent);
|
|
556
|
-
this.foreignKey = foreignKey;
|
|
557
|
-
this.localKey = localKey;
|
|
558
|
-
return this.asProxy();
|
|
559
|
-
}
|
|
560
|
-
};
|
|
561
|
-
var has_one_default = HasOne;
|
|
562
|
-
|
|
563
|
-
//#endregion
|
|
564
|
-
//#region src/browser/relations/has-many-through.ts
|
|
565
|
-
var HasManyThrough = class extends relation_default {
|
|
566
|
-
throughParent;
|
|
567
|
-
farParent;
|
|
568
|
-
firstKey;
|
|
569
|
-
secondKey;
|
|
570
|
-
localKey;
|
|
571
|
-
secondLocalKey;
|
|
572
|
-
constructor(query, farParent, throughParent, firstKey, secondKey, localKey, secondLocalKey) {
|
|
573
|
-
super(query, throughParent);
|
|
574
|
-
this.localKey = localKey;
|
|
575
|
-
this.firstKey = firstKey;
|
|
576
|
-
this.secondKey = secondKey;
|
|
577
|
-
this.farParent = farParent;
|
|
578
|
-
this.throughParent = throughParent;
|
|
579
|
-
this.secondLocalKey = secondLocalKey;
|
|
580
|
-
return this.asProxy();
|
|
581
|
-
}
|
|
582
|
-
};
|
|
583
|
-
var has_many_through_default = HasManyThrough;
|
|
584
|
-
|
|
585
|
-
//#endregion
|
|
586
|
-
//#region src/browser/relations/has-one-through.ts
|
|
587
|
-
var HasOneThrough = class extends has_many_through_default {};
|
|
588
|
-
var has_one_through_default = HasOneThrough;
|
|
589
|
-
|
|
590
|
-
//#endregion
|
|
591
|
-
//#region src/errors.ts
|
|
592
|
-
var BaseError = class extends Error {
|
|
593
|
-
constructor(message, _entity) {
|
|
594
|
-
super(message);
|
|
595
|
-
Error.captureStackTrace(this, this.constructor);
|
|
596
|
-
this.name = this.constructor.name;
|
|
597
|
-
this.message = message;
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
var ModelNotFoundError = class extends BaseError {
|
|
601
|
-
model;
|
|
602
|
-
ids = [];
|
|
603
|
-
constructor() {
|
|
604
|
-
super("");
|
|
605
|
-
}
|
|
606
|
-
setModel(model, ids = []) {
|
|
607
|
-
this.model = model;
|
|
608
|
-
this.ids = (0, radashi.isArray)(ids) ? ids : [ids];
|
|
609
|
-
this.message = `No query results for model [${model}]`;
|
|
610
|
-
if (this.ids.length > 0) this.message += " " + this.ids.join(", ");
|
|
611
|
-
else this.message += ".";
|
|
612
|
-
return this;
|
|
613
|
-
}
|
|
614
|
-
getModel() {
|
|
615
|
-
return this.model;
|
|
616
|
-
}
|
|
617
|
-
getIds() {
|
|
618
|
-
return this.ids;
|
|
619
|
-
}
|
|
620
|
-
};
|
|
621
|
-
var RelationNotFoundError = class extends BaseError {};
|
|
622
|
-
var InvalidArgumentError = class extends BaseError {};
|
|
623
|
-
|
|
624
|
-
//#endregion
|
|
625
|
-
//#region src/browser/concerns/has-relations.ts
|
|
626
|
-
const HasRelations = (Instance) => {
|
|
627
|
-
return class extends Instance {
|
|
628
|
-
relations = {};
|
|
629
|
-
getRelation(relation) {
|
|
630
|
-
return this.relations[relation];
|
|
631
|
-
}
|
|
632
|
-
setRelation(relation, value) {
|
|
633
|
-
this.relations[relation] = value;
|
|
634
|
-
return this;
|
|
635
|
-
}
|
|
636
|
-
unsetRelation(relation) {
|
|
637
|
-
this.relations = (0, radashi.omit)(this.relations, [relation]);
|
|
638
|
-
return this;
|
|
639
|
-
}
|
|
640
|
-
relationLoaded(relation) {
|
|
641
|
-
return this.relations[relation] !== void 0;
|
|
642
|
-
}
|
|
643
|
-
related(relation) {
|
|
644
|
-
if (typeof this[getRelationMethod(relation)] !== "function") {
|
|
645
|
-
const message = `Model [${this.constructor.name}]'s relation [${relation}] doesn't exist.`;
|
|
646
|
-
throw new RelationNotFoundError(message);
|
|
647
|
-
}
|
|
648
|
-
return this[getRelationMethod(relation)]();
|
|
649
|
-
}
|
|
650
|
-
async getRelated(relation) {
|
|
651
|
-
return await this.related(relation).getResults();
|
|
652
|
-
}
|
|
653
|
-
relationsToData() {
|
|
654
|
-
const data = {};
|
|
655
|
-
for (const key in this.relations) {
|
|
656
|
-
if (this.hidden.includes(key)) continue;
|
|
657
|
-
if (this.visible.length > 0 && this.visible.includes(key) === false) continue;
|
|
658
|
-
data[key] = this.relations[key] instanceof Array ? this.relations[key].map((item) => item.toData()) : this.relations[key] === null ? null : this.relations[key].toData();
|
|
659
|
-
}
|
|
660
|
-
return data;
|
|
661
|
-
}
|
|
662
|
-
guessBelongsToRelation() {
|
|
663
|
-
var _e$stack;
|
|
664
|
-
const frame = (_e$stack = (/* @__PURE__ */ new Error()).stack) === null || _e$stack === void 0 ? void 0 : _e$stack.split("\n")[2];
|
|
665
|
-
const functionName = frame === null || frame === void 0 ? void 0 : frame.split(" ")[5];
|
|
666
|
-
return getRelationName(functionName);
|
|
667
|
-
}
|
|
668
|
-
joiningTable(related, instance = null) {
|
|
669
|
-
return [instance ? instance.joiningTableSegment() : snakeCase(related.name), this.joiningTableSegment()].sort().join("_").toLocaleLowerCase();
|
|
670
|
-
}
|
|
671
|
-
joiningTableSegment() {
|
|
672
|
-
return snakeCase(this.constructor.name);
|
|
673
|
-
}
|
|
674
|
-
hasOne(related, foreignKey = null, localKey = null) {
|
|
675
|
-
const instance = new related();
|
|
676
|
-
foreignKey = foreignKey || this.getForeignKey();
|
|
677
|
-
localKey = localKey || this.getKeyName();
|
|
678
|
-
return new has_one_default(related, this, instance.getTable() + "." + foreignKey, localKey);
|
|
679
|
-
}
|
|
680
|
-
hasMany(related, foreignKey = null, localKey = null) {
|
|
681
|
-
const instance = new related();
|
|
682
|
-
foreignKey = foreignKey || this.getForeignKey();
|
|
683
|
-
localKey = localKey || this.getKeyName();
|
|
684
|
-
return new has_many_default(related, this, instance.getTable() + "." + foreignKey, localKey);
|
|
685
|
-
}
|
|
686
|
-
belongsTo(related, foreignKey = null, ownerKey = null, relation = null) {
|
|
687
|
-
const instance = new related();
|
|
688
|
-
foreignKey = foreignKey || instance.getForeignKey();
|
|
689
|
-
ownerKey = ownerKey || instance.getKeyName();
|
|
690
|
-
relation = relation || this.guessBelongsToRelation();
|
|
691
|
-
return new belongs_to_default(related, this, foreignKey, ownerKey, relation);
|
|
692
|
-
}
|
|
693
|
-
belongsToMany(related, table = null, foreignPivotKey = null, relatedPivotKey = null, parentKey = null, relatedKey = null) {
|
|
694
|
-
const instance = new related();
|
|
695
|
-
const query = related.query();
|
|
696
|
-
table = table || this.joiningTable(related, instance);
|
|
697
|
-
foreignPivotKey = foreignPivotKey || this.getForeignKey();
|
|
698
|
-
relatedPivotKey = relatedPivotKey || instance.getForeignKey();
|
|
699
|
-
parentKey = parentKey || this.getKeyName();
|
|
700
|
-
relatedKey = relatedKey || instance.getKeyName();
|
|
701
|
-
return new belongs_to_many_default(query, this, table, foreignPivotKey, relatedPivotKey, parentKey, relatedKey);
|
|
702
|
-
}
|
|
703
|
-
hasOneThrough(related, through, firstKey = null, secondKey = null, localKey = null, secondLocalKey = null) {
|
|
704
|
-
through = new through();
|
|
705
|
-
const query = related.query();
|
|
706
|
-
firstKey = firstKey || this.getForeignKey();
|
|
707
|
-
secondKey = secondKey || through.getForeignKey();
|
|
708
|
-
return new has_one_through_default(query, this, through, firstKey, secondKey, localKey || this.getKeyName(), secondLocalKey || through.getKeyName());
|
|
709
|
-
}
|
|
710
|
-
hasManyThrough(related, through, firstKey = null, secondKey = null, localKey = null, secondLocalKey = null) {
|
|
711
|
-
through = new through();
|
|
712
|
-
const query = related.query();
|
|
713
|
-
firstKey = firstKey || this.getForeignKey();
|
|
714
|
-
secondKey = secondKey || through.getForeignKey();
|
|
715
|
-
return new has_many_through_default(query, this, through, firstKey, secondKey, localKey || this.getKeyName(), secondLocalKey || through.getKeyName());
|
|
716
|
-
}
|
|
717
|
-
};
|
|
718
|
-
};
|
|
719
|
-
var has_relations_default = HasRelations;
|
|
720
|
-
|
|
721
|
-
//#endregion
|
|
722
|
-
//#region src/concerns/has-timestamps.ts
|
|
723
|
-
const HasTimestamps = (Model$1) => {
|
|
724
|
-
return class extends Model$1 {
|
|
725
|
-
static CREATED_AT = "created_at";
|
|
726
|
-
static UPDATED_AT = "updated_at";
|
|
727
|
-
static DELETED_AT = "deleted_at";
|
|
728
|
-
timestamps = true;
|
|
729
|
-
dateFormat = "YYYY-MM-DD HH:mm:ss";
|
|
730
|
-
usesTimestamps() {
|
|
731
|
-
return this.timestamps;
|
|
732
|
-
}
|
|
733
|
-
updateTimestamps() {
|
|
734
|
-
const time = this.freshTimestampString();
|
|
735
|
-
const updatedAtColumn = this.getUpdatedAtColumn();
|
|
736
|
-
if (updatedAtColumn && !this.isDirty(updatedAtColumn)) this.setUpdatedAt(time);
|
|
737
|
-
const createdAtColumn = this.getCreatedAtColumn();
|
|
738
|
-
if (!this.exists && createdAtColumn && !this.isDirty(createdAtColumn)) this.setCreatedAt(time);
|
|
739
|
-
return this;
|
|
740
|
-
}
|
|
741
|
-
getCreatedAtColumn() {
|
|
742
|
-
return this.constructor.CREATED_AT;
|
|
743
|
-
}
|
|
744
|
-
getUpdatedAtColumn() {
|
|
745
|
-
return this.constructor.UPDATED_AT;
|
|
746
|
-
}
|
|
747
|
-
setCreatedAt(value) {
|
|
748
|
-
this.attributes[this.getCreatedAtColumn()] = value;
|
|
749
|
-
return this;
|
|
750
|
-
}
|
|
751
|
-
setUpdatedAt(value) {
|
|
752
|
-
this.attributes[this.getUpdatedAtColumn()] = value;
|
|
753
|
-
return this;
|
|
754
|
-
}
|
|
755
|
-
freshTimestamp() {
|
|
756
|
-
const time = /* @__PURE__ */ new Date();
|
|
757
|
-
time.setMilliseconds(0);
|
|
758
|
-
return time;
|
|
759
|
-
}
|
|
760
|
-
freshTimestampString() {
|
|
761
|
-
return this.fromDateTime(this.freshTimestamp());
|
|
762
|
-
}
|
|
763
|
-
};
|
|
764
|
-
};
|
|
765
|
-
var has_timestamps_default = HasTimestamps;
|
|
766
|
-
|
|
767
|
-
//#endregion
|
|
768
|
-
//#region src/concerns/hides-attributes.ts
|
|
769
|
-
const HidesAttributes = (Model$1) => {
|
|
770
|
-
return class extends Model$1 {
|
|
771
|
-
hidden = [];
|
|
772
|
-
visible = [];
|
|
773
|
-
makeVisible(...keys) {
|
|
774
|
-
const visible = flattenDeep(keys);
|
|
775
|
-
if (this.visible.length > 0) this.visible = [...this.visible, ...visible];
|
|
776
|
-
this.hidden = (0, radashi.diff)(this.hidden, visible);
|
|
777
|
-
return this;
|
|
778
|
-
}
|
|
779
|
-
makeHidden(key, ...keys) {
|
|
780
|
-
const hidden = flattenDeep([...key, ...keys]);
|
|
781
|
-
if (this.hidden.length > 0) this.hidden = [...this.hidden, ...hidden];
|
|
782
|
-
return this;
|
|
783
|
-
}
|
|
784
|
-
getHidden() {
|
|
785
|
-
return this.hidden;
|
|
786
|
-
}
|
|
787
|
-
getVisible() {
|
|
788
|
-
return this.visible;
|
|
789
|
-
}
|
|
790
|
-
setHidden(hidden) {
|
|
791
|
-
this.hidden = hidden;
|
|
792
|
-
return this;
|
|
793
|
-
}
|
|
794
|
-
setVisible(visible) {
|
|
795
|
-
this.visible = visible;
|
|
796
|
-
return this;
|
|
797
|
-
}
|
|
798
|
-
};
|
|
799
|
-
};
|
|
800
|
-
var hides_attributes_default = HidesAttributes;
|
|
801
|
-
|
|
802
|
-
//#endregion
|
|
803
|
-
//#region src/browser/model.ts
|
|
804
|
-
const BaseModel = compose(class {}, has_attributes_default, hides_attributes_default, has_relations_default, has_timestamps_default);
|
|
805
|
-
var Model = class Model extends BaseModel {
|
|
806
|
-
primaryKey = "id";
|
|
807
|
-
perPage = 15;
|
|
808
|
-
static globalScopes = {};
|
|
809
|
-
static pluginInitializers = {};
|
|
810
|
-
static _booted = {};
|
|
811
|
-
static resolver;
|
|
812
|
-
static browser = true;
|
|
813
|
-
connection = null;
|
|
814
|
-
constructor(attributes = {}) {
|
|
815
|
-
super();
|
|
816
|
-
this.bootIfNotBooted();
|
|
817
|
-
this.initializePlugins();
|
|
818
|
-
this.syncOriginal();
|
|
819
|
-
this.fill(attributes);
|
|
820
|
-
return this.asProxy();
|
|
821
|
-
}
|
|
822
|
-
static init(attributes = {}) {
|
|
823
|
-
return new this(attributes);
|
|
824
|
-
}
|
|
825
|
-
static extend(plugin, options) {
|
|
826
|
-
plugin(this, options);
|
|
827
|
-
}
|
|
828
|
-
static make(attributes = {}) {
|
|
829
|
-
const instance = new this();
|
|
830
|
-
for (const attribute in attributes) if (typeof instance[getRelationMethod(attribute)] !== "function") instance.setAttribute(attribute, attributes[attribute]);
|
|
831
|
-
else {
|
|
832
|
-
const relation = instance[getRelationMethod(attribute)]();
|
|
833
|
-
if (relation instanceof has_one_default || relation instanceof belongs_to_default) instance.setRelation(attribute, relation.related.make(attributes[attribute]));
|
|
834
|
-
else if ((relation instanceof has_many_default || relation instanceof belongs_to_many_default) && Array.isArray(attributes[attribute])) instance.setRelation(attribute, new collection_default(attributes[attribute].map((item) => relation.related.make(item))));
|
|
835
|
-
}
|
|
836
|
-
return instance;
|
|
837
|
-
}
|
|
838
|
-
bootIfNotBooted() {
|
|
839
|
-
if (this.constructor._booted[this.constructor.name] === void 0) {
|
|
840
|
-
this.constructor._booted[this.constructor.name] = true;
|
|
841
|
-
this.constructor.booting();
|
|
842
|
-
this.initialize();
|
|
843
|
-
this.constructor.boot();
|
|
844
|
-
this.constructor.booted();
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
static booting() {}
|
|
848
|
-
static boot() {}
|
|
849
|
-
static booted() {}
|
|
850
|
-
static setConnectionResolver(resolver) {
|
|
851
|
-
this.resolver = resolver;
|
|
852
|
-
}
|
|
853
|
-
initialize() {}
|
|
854
|
-
initializePlugins() {
|
|
855
|
-
if (typeof this.constructor.pluginInitializers[this.constructor.name] === "undefined") return;
|
|
856
|
-
for (const method of this.constructor.pluginInitializers[this.constructor.name]) this[method]();
|
|
857
|
-
}
|
|
858
|
-
addPluginInitializer(method) {
|
|
859
|
-
if (!this.constructor.pluginInitializers[this.constructor.name]) this.constructor.pluginInitializers[this.constructor.name] = [];
|
|
860
|
-
this.constructor.pluginInitializers[this.constructor.name].push(method);
|
|
861
|
-
}
|
|
862
|
-
newInstance(attributes = {}, exists = false) {
|
|
863
|
-
const model = new this.constructor();
|
|
864
|
-
model.exists = exists;
|
|
865
|
-
model.setTable(this.getTable());
|
|
866
|
-
model.fill(attributes);
|
|
867
|
-
return model;
|
|
868
|
-
}
|
|
869
|
-
asProxy() {
|
|
870
|
-
return new Proxy(this, {
|
|
871
|
-
get: function(target, prop) {
|
|
872
|
-
if (target[prop] !== void 0) return target[prop];
|
|
873
|
-
if (typeof prop === "string") return target.getAttribute(prop);
|
|
874
|
-
},
|
|
875
|
-
set: function(target, prop, value) {
|
|
876
|
-
if (target[prop] !== void 0 && typeof target !== "function") {
|
|
877
|
-
target[prop] = value;
|
|
878
|
-
return target;
|
|
879
|
-
}
|
|
880
|
-
if (typeof prop === "string") return target.setAttribute(prop, value);
|
|
881
|
-
return target;
|
|
882
|
-
}
|
|
883
|
-
});
|
|
884
|
-
}
|
|
885
|
-
getKey() {
|
|
886
|
-
return this.getAttribute(this.getKeyName());
|
|
887
|
-
}
|
|
888
|
-
getKeyName() {
|
|
889
|
-
return this.primaryKey;
|
|
890
|
-
}
|
|
891
|
-
getForeignKey() {
|
|
892
|
-
return snakeCase(this.constructor.name) + "_" + this.getKeyName();
|
|
893
|
-
}
|
|
894
|
-
getConnectionName() {
|
|
895
|
-
return this.connection;
|
|
896
|
-
}
|
|
897
|
-
getTable() {
|
|
898
|
-
return this.table || (0, pluralize.default)(snakeCase(this.constructor.name));
|
|
899
|
-
}
|
|
900
|
-
setConnection(connection) {
|
|
901
|
-
this.connection = connection;
|
|
902
|
-
return this;
|
|
903
|
-
}
|
|
904
|
-
getKeyType() {
|
|
905
|
-
return this.keyType;
|
|
906
|
-
}
|
|
907
|
-
hasNamedScope(name) {
|
|
908
|
-
const scope = getScopeMethod(name);
|
|
909
|
-
return typeof this[scope] === "function";
|
|
910
|
-
}
|
|
911
|
-
callNamedScope(scope, parameters) {
|
|
912
|
-
const scopeMethod = getScopeMethod(scope);
|
|
913
|
-
return this[scopeMethod](...parameters);
|
|
914
|
-
}
|
|
915
|
-
setTable(table) {
|
|
916
|
-
this.table = table;
|
|
917
|
-
return this;
|
|
918
|
-
}
|
|
919
|
-
newCollection(models = []) {
|
|
920
|
-
return new collection_default(models);
|
|
921
|
-
}
|
|
922
|
-
getIncrementing() {
|
|
923
|
-
return this.incrementing;
|
|
924
|
-
}
|
|
925
|
-
setIncrementing(value) {
|
|
926
|
-
this.incrementing = value;
|
|
927
|
-
return this;
|
|
928
|
-
}
|
|
929
|
-
toData() {
|
|
930
|
-
return (0, radashi.assign)(this.attributesToData(), this.relationsToData());
|
|
931
|
-
}
|
|
932
|
-
toJSON() {
|
|
933
|
-
return this.toData();
|
|
934
|
-
}
|
|
935
|
-
toJson(...args) {
|
|
936
|
-
return JSON.stringify(this.toData(), ...args);
|
|
937
|
-
}
|
|
938
|
-
toString() {
|
|
939
|
-
return this.toJson();
|
|
940
|
-
}
|
|
941
|
-
fill(attributes) {
|
|
942
|
-
for (const key in attributes) this.setAttribute(key, attributes[key]);
|
|
943
|
-
return this;
|
|
944
|
-
}
|
|
945
|
-
transacting(trx) {
|
|
946
|
-
this.trx = trx;
|
|
947
|
-
return this;
|
|
948
|
-
}
|
|
949
|
-
trashed() {
|
|
950
|
-
return this[this.getDeletedAtColumn()] !== null;
|
|
951
|
-
}
|
|
952
|
-
newPivot(parent, attributes, table, exists, using = null) {
|
|
953
|
-
return using ? using.fromRawAttributes(parent, attributes, table, exists) : Pivot.fromAttributes(parent, attributes, table, exists);
|
|
954
|
-
}
|
|
955
|
-
qualifyColumn(column) {
|
|
956
|
-
if (column.includes(".")) return column;
|
|
957
|
-
return `${this.getTable()}.${column}`;
|
|
958
|
-
}
|
|
959
|
-
getQualifiedKeyName() {
|
|
960
|
-
return this.qualifyColumn(this.getKeyName());
|
|
961
|
-
}
|
|
962
|
-
is(model) {
|
|
963
|
-
return model && model instanceof Model && this.getKey() === model.getKey() && this.getTable() === model.getTable();
|
|
964
|
-
}
|
|
965
|
-
isNot(model) {
|
|
966
|
-
return !this.is(model);
|
|
967
|
-
}
|
|
968
|
-
};
|
|
969
|
-
var Pivot = class extends Model {
|
|
970
|
-
incrementing = false;
|
|
971
|
-
guarded = [];
|
|
972
|
-
pivotParent = null;
|
|
973
|
-
foreignKey = null;
|
|
974
|
-
relatedKey = null;
|
|
975
|
-
setPivotKeys(foreignKey, relatedKey) {
|
|
976
|
-
this.foreignKey = foreignKey;
|
|
977
|
-
this.relatedKey = relatedKey;
|
|
978
|
-
return this;
|
|
979
|
-
}
|
|
980
|
-
static fromRawAttributes(parent, attributes, table, exists = false) {
|
|
981
|
-
const instance = this.fromAttributes(parent, {}, table, exists);
|
|
982
|
-
instance.timestamps = instance.hasTimestampAttributes(attributes);
|
|
983
|
-
instance.attributes = attributes;
|
|
984
|
-
instance.exists = exists;
|
|
985
|
-
return instance;
|
|
986
|
-
}
|
|
987
|
-
static fromAttributes(parent, attributes, table, exists = false) {
|
|
988
|
-
const instance = new this();
|
|
989
|
-
instance.timestamps = instance.hasTimestampAttributes(attributes);
|
|
990
|
-
instance.setConnection(parent.connection).setTable(table).fill(attributes).syncOriginal();
|
|
991
|
-
instance.pivotParent = parent;
|
|
992
|
-
instance.exists = exists;
|
|
993
|
-
return instance;
|
|
994
|
-
}
|
|
995
|
-
hasTimestampAttributes(attributes = null) {
|
|
996
|
-
return (attributes || this.attributes)[this.constructor.CREATED_AT] !== void 0;
|
|
997
|
-
}
|
|
998
|
-
};
|
|
999
|
-
var model_default = Model;
|
|
1000
|
-
|
|
1001
|
-
//#endregion
|
|
1002
|
-
//#region src/browser/collection.ts
|
|
1003
|
-
var Collection = class Collection extends collect_js.Collection {
|
|
1004
|
-
mapThen(callback) {
|
|
1005
|
-
return Promise.all(this.map(callback));
|
|
1006
|
-
}
|
|
1007
|
-
modelKeys() {
|
|
1008
|
-
return this.all().map((item) => item.getKey());
|
|
1009
|
-
}
|
|
1010
|
-
contains(key, operator, value) {
|
|
1011
|
-
if (arguments.length > 1) return super.contains(key, value ?? operator);
|
|
1012
|
-
if (key instanceof model_default) return super.contains((model) => {
|
|
1013
|
-
return model.is(key);
|
|
1014
|
-
});
|
|
1015
|
-
return super.contains((model) => {
|
|
1016
|
-
return model.getKey() == key;
|
|
1017
|
-
});
|
|
1018
|
-
}
|
|
1019
|
-
diff(items) {
|
|
1020
|
-
const diff = new this.constructor();
|
|
1021
|
-
const dictionary = this.getDictionary(items);
|
|
1022
|
-
this.items.map((item) => {
|
|
1023
|
-
if (dictionary[item.getKey()] === void 0) diff.add(item);
|
|
1024
|
-
});
|
|
1025
|
-
return diff;
|
|
1026
|
-
}
|
|
1027
|
-
except(keys) {
|
|
1028
|
-
const dictionary = (0, radashi.omit)(this.getDictionary(), keys);
|
|
1029
|
-
return new this.constructor(Object.values(dictionary));
|
|
1030
|
-
}
|
|
1031
|
-
intersect(items) {
|
|
1032
|
-
const intersect = new this.constructor();
|
|
1033
|
-
if ((0, radashi.isEmpty)(items)) return intersect;
|
|
1034
|
-
const dictionary = this.getDictionary(items);
|
|
1035
|
-
for (const item of this.items) if (dictionary[item.getKey()] !== void 0) intersect.add(item);
|
|
1036
|
-
return intersect;
|
|
1037
|
-
}
|
|
1038
|
-
unique(key, _strict = false) {
|
|
1039
|
-
if (key) return super.unique(key);
|
|
1040
|
-
return new this.constructor(Object.values(this.getDictionary()));
|
|
1041
|
-
}
|
|
1042
|
-
find(key, defaultValue = null) {
|
|
1043
|
-
if (key instanceof model_default) key = key.getKey();
|
|
1044
|
-
if ((0, radashi.isArray)(key)) {
|
|
1045
|
-
if (this.isEmpty()) return new this.constructor();
|
|
1046
|
-
return this.whereIn(this.first().getKeyName(), key);
|
|
1047
|
-
}
|
|
1048
|
-
(0, collect_js.collect)(this.items).first((model) => {
|
|
1049
|
-
return model.getKey() == key;
|
|
1050
|
-
});
|
|
1051
|
-
return this.items.filter((model) => {
|
|
1052
|
-
return model.getKey() == key;
|
|
1053
|
-
})[0] || defaultValue;
|
|
1054
|
-
}
|
|
1055
|
-
makeVisible(attributes) {
|
|
1056
|
-
return this.each((item) => {
|
|
1057
|
-
item.makeVisible(attributes);
|
|
1058
|
-
});
|
|
1059
|
-
}
|
|
1060
|
-
makeHidden(attributes) {
|
|
1061
|
-
return this.each((item) => {
|
|
1062
|
-
item.makeHidden(attributes);
|
|
1063
|
-
});
|
|
1064
|
-
}
|
|
1065
|
-
append(attributes) {
|
|
1066
|
-
return this.each((item) => {
|
|
1067
|
-
item.append(attributes);
|
|
1068
|
-
});
|
|
1069
|
-
}
|
|
1070
|
-
only(keys) {
|
|
1071
|
-
if (keys === null) return new Collection(this.items);
|
|
1072
|
-
const dictionary = (0, radashi.pick)(this.getDictionary(), keys);
|
|
1073
|
-
return new this.constructor(Object.values(dictionary));
|
|
1074
|
-
}
|
|
1075
|
-
getDictionary(items) {
|
|
1076
|
-
items = !items ? this.items : items;
|
|
1077
|
-
const dictionary = {};
|
|
1078
|
-
items.map((value) => {
|
|
1079
|
-
dictionary[value.getKey()] = value;
|
|
1080
|
-
});
|
|
1081
|
-
return dictionary;
|
|
1082
|
-
}
|
|
1083
|
-
toData() {
|
|
1084
|
-
return this.all().map((item) => typeof item.toData == "function" ? item.toData() : item);
|
|
1085
|
-
}
|
|
1086
|
-
toJSON() {
|
|
1087
|
-
return this.toData();
|
|
1088
|
-
}
|
|
1089
|
-
toJson(...args) {
|
|
1090
|
-
return JSON.stringify(this.toData(), ...args);
|
|
1091
|
-
}
|
|
1092
|
-
[Symbol.iterator] = () => {
|
|
1093
|
-
const items = this.items;
|
|
1094
|
-
const length = this.items.length;
|
|
1095
|
-
let n = 0;
|
|
1096
|
-
return { next() {
|
|
1097
|
-
return n < length ? {
|
|
1098
|
-
value: items[n++],
|
|
1099
|
-
done: false
|
|
1100
|
-
} : { done: true };
|
|
1101
|
-
} };
|
|
1102
|
-
};
|
|
1103
|
-
};
|
|
1104
|
-
var collection_default = Collection;
|
|
1105
|
-
|
|
1106
|
-
//#endregion
|
|
1107
|
-
//#region src/concerns/has-unique-ids.ts
|
|
1108
|
-
const HasUniqueIds = (Model$1) => {
|
|
1109
|
-
return class extends Model$1 {
|
|
1110
|
-
useUniqueIds = true;
|
|
1111
|
-
uniqueIds() {
|
|
1112
|
-
return [this.getKeyName()];
|
|
1113
|
-
}
|
|
1114
|
-
getKeyType() {
|
|
1115
|
-
if (this.uniqueIds().includes(this.getKeyName())) return "string";
|
|
1116
|
-
return this.keyType;
|
|
1117
|
-
}
|
|
1118
|
-
getIncrementing() {
|
|
1119
|
-
if (this.uniqueIds().includes(this.getKeyName())) return false;
|
|
1120
|
-
return this.incrementing;
|
|
1121
|
-
}
|
|
1122
|
-
};
|
|
1123
|
-
};
|
|
1124
|
-
var has_unique_ids_default = HasUniqueIds;
|
|
1125
|
-
|
|
1126
|
-
//#endregion
|
|
1127
|
-
//#region src/browser/paginator.ts
|
|
1128
|
-
var Paginator = class {
|
|
1129
|
-
static formatter;
|
|
1130
|
-
_items;
|
|
1131
|
-
_total;
|
|
1132
|
-
_perPage;
|
|
1133
|
-
_lastPage;
|
|
1134
|
-
_currentPage;
|
|
1135
|
-
hasMore = false;
|
|
1136
|
-
options = {};
|
|
1137
|
-
constructor(items, total, perPage, currentPage = 1, options = {}) {
|
|
1138
|
-
this.options = options;
|
|
1139
|
-
for (const key in options) this[key] = options[key];
|
|
1140
|
-
this._items = new collection_default([]);
|
|
1141
|
-
this._total = total;
|
|
1142
|
-
this._perPage = parseInt(String(perPage));
|
|
1143
|
-
this._lastPage = Math.max(Math.ceil(total / perPage), 1);
|
|
1144
|
-
this._currentPage = currentPage;
|
|
1145
|
-
this.setItems(items);
|
|
1146
|
-
}
|
|
1147
|
-
static setFormatter(formatter) {
|
|
1148
|
-
if (typeof formatter !== "function" && formatter !== null && formatter !== void 0) throw new Error("Paginator formatter must be a function or null");
|
|
1149
|
-
this.formatter = formatter;
|
|
1150
|
-
}
|
|
1151
|
-
setItems(items) {
|
|
1152
|
-
this._items = items instanceof collection_default ? items : new collection_default(items);
|
|
1153
|
-
this.hasMore = this._items.count() > this._perPage;
|
|
1154
|
-
this._items = this._items.slice(0, this._perPage);
|
|
1155
|
-
}
|
|
1156
|
-
firstItem() {
|
|
1157
|
-
return this.count() > 0 ? (this._currentPage - 1) * this._perPage + 1 : null;
|
|
1158
|
-
}
|
|
1159
|
-
lastItem() {
|
|
1160
|
-
return this.count() > 0 ? (this.firstItem() ?? 0) + this.count() - 1 : null;
|
|
1161
|
-
}
|
|
1162
|
-
hasMorePages() {
|
|
1163
|
-
return this._currentPage < this._lastPage;
|
|
1164
|
-
}
|
|
1165
|
-
get(index) {
|
|
1166
|
-
return this._items.get(index);
|
|
1167
|
-
}
|
|
1168
|
-
count() {
|
|
1169
|
-
return this._items.count();
|
|
1170
|
-
}
|
|
1171
|
-
items() {
|
|
1172
|
-
return this._items;
|
|
1173
|
-
}
|
|
1174
|
-
map(callback) {
|
|
1175
|
-
return this._items.map(callback);
|
|
1176
|
-
}
|
|
1177
|
-
currentPage() {
|
|
1178
|
-
return this._currentPage;
|
|
1179
|
-
}
|
|
1180
|
-
onFirstPage() {
|
|
1181
|
-
return this._currentPage === 1;
|
|
1182
|
-
}
|
|
1183
|
-
perPage() {
|
|
1184
|
-
return this._perPage;
|
|
1185
|
-
}
|
|
1186
|
-
lastPage() {
|
|
1187
|
-
return this._lastPage;
|
|
1188
|
-
}
|
|
1189
|
-
total() {
|
|
1190
|
-
return this._total;
|
|
1191
|
-
}
|
|
1192
|
-
toData() {
|
|
1193
|
-
if (this.constructor.formatter && typeof this.constructor.formatter === "function") return this.constructor.formatter(this);
|
|
1194
|
-
return {
|
|
1195
|
-
current_page: this._currentPage,
|
|
1196
|
-
data: this._items.toData(),
|
|
1197
|
-
per_page: this._perPage,
|
|
1198
|
-
total: this._total,
|
|
1199
|
-
last_page: this._lastPage,
|
|
1200
|
-
count: this.count()
|
|
1201
|
-
};
|
|
1202
|
-
}
|
|
1203
|
-
toJSON() {
|
|
1204
|
-
return this.toData();
|
|
1205
|
-
}
|
|
1206
|
-
toJson(...args) {
|
|
1207
|
-
return JSON.stringify(this.toData(), ...args);
|
|
1208
|
-
}
|
|
1209
|
-
};
|
|
1210
|
-
var paginator_default = Paginator;
|
|
1211
|
-
|
|
1212
|
-
//#endregion
|
|
1213
|
-
//#region src/browser/pivot.ts
|
|
1214
|
-
var pivot_default = Pivot;
|
|
1215
|
-
|
|
1216
|
-
//#endregion
|
|
1217
|
-
//#region src/browser/index.ts
|
|
1218
|
-
const make = (model, data, options = {}) => {
|
|
1219
|
-
const { paginated } = options;
|
|
1220
|
-
if (paginated) return new paginator_default(data.data.map((item) => model.make(item)), data.total, data.per_page, data.current_page);
|
|
1221
|
-
if ((0, radashi.isArray)(data)) return new collection_default(data.map((item) => model.make(item)));
|
|
1222
|
-
return model.make(data);
|
|
1223
|
-
};
|
|
1224
|
-
const makeCollection = (model, data) => new collection_default(data.map((item) => model.make(item)));
|
|
1225
|
-
const makePaginator = (model, data) => new paginator_default(data.data.map((item) => model.make(item)), data.total, data.per_page, data.current_page);
|
|
1226
|
-
const isBrowser = true;
|
|
1227
|
-
var browser_default = {
|
|
1228
|
-
isBrowser,
|
|
1229
|
-
Paginator: paginator_default,
|
|
1230
|
-
Collection: collection_default,
|
|
1231
|
-
Model: model_default,
|
|
1232
|
-
Pivot: pivot_default,
|
|
1233
|
-
Attribute: attribute_default,
|
|
1234
|
-
CastsAttributes: casts_attributes_default,
|
|
1235
|
-
HasUniqueIds: has_unique_ids_default,
|
|
1236
|
-
make,
|
|
1237
|
-
makeCollection,
|
|
1238
|
-
makePaginator
|
|
1239
|
-
};
|
|
1240
|
-
|
|
1241
|
-
//#endregion
|
|
1242
|
-
exports.Attribute = attribute_default;
|
|
1243
|
-
exports.CastsAttributes = casts_attributes_default;
|
|
1244
|
-
exports.Collection = collection_default;
|
|
1245
|
-
exports.HasUniqueIds = has_unique_ids_default;
|
|
1246
|
-
exports.InvalidArgumentError = InvalidArgumentError;
|
|
1247
|
-
exports.Model = model_default;
|
|
1248
|
-
exports.ModelNotFoundError = ModelNotFoundError;
|
|
1249
|
-
exports.Paginator = paginator_default;
|
|
1250
|
-
exports.Pivot = pivot_default;
|
|
1251
|
-
exports.RelationNotFoundError = RelationNotFoundError;
|
|
1252
|
-
exports.compose = compose;
|
|
1253
|
-
exports.default = browser_default;
|
|
1254
|
-
exports.defineConfig = defineConfig;
|
|
1255
|
-
exports.flatten = flatten;
|
|
1256
|
-
exports.flattenDeep = flattenDeep;
|
|
1257
|
-
exports.getAttrMethod = getAttrMethod;
|
|
1258
|
-
exports.getAttrName = getAttrName;
|
|
1259
|
-
exports.getGetterMethod = getGetterMethod;
|
|
1260
|
-
exports.getRelationMethod = getRelationMethod;
|
|
1261
|
-
exports.getRelationName = getRelationName;
|
|
1262
|
-
exports.getScopeMethod = getScopeMethod;
|
|
1263
|
-
exports.getScopeName = getScopeName;
|
|
1264
|
-
exports.getSetterMethod = getSetterMethod;
|
|
1265
|
-
exports.isBrowser = isBrowser;
|
|
1266
|
-
exports.kebabCase = kebabCase;
|
|
1267
|
-
exports.make = make;
|
|
1268
|
-
exports.makeCollection = makeCollection;
|
|
1269
|
-
exports.now = now;
|
|
1270
|
-
exports.snakeCase = snakeCase;
|
|
1271
|
-
exports.tap = tap;
|