@h3ravel/arquebus 0.7.1 → 0.7.3
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/bin/index.cjs +76 -76
- package/bin/index.js +76 -76
- package/dist/browser/index.cjs +14 -3
- package/dist/browser/index.d.ts +17 -10
- package/dist/browser/index.js +14 -3
- package/dist/concerns/index.cjs +35 -72
- package/dist/concerns/index.d.ts +214 -236
- package/dist/concerns/index.js +41 -26
- package/dist/index.cjs +116 -116
- package/dist/index.d.ts +51 -42
- package/dist/index.js +114 -114
- package/dist/inspector/index.cjs +5 -5
- package/dist/inspector/index.js +4 -4
- package/dist/migrations/index.cjs +6 -6
- package/dist/migrations/index.d.ts +5 -1
- package/dist/migrations/index.js +10 -10
- package/dist/relations/index.cjs +46 -93
- package/dist/relations/index.d.ts +98 -104
- package/dist/relations/index.js +50 -35
- package/dist/seeders/index.d.ts +5 -1
- package/package.json +1 -1
- package/types/modeling.ts +129 -126
- package/dist/concerns/chunk-Bop6jNiL.js +0 -15
- package/dist/relations/chunk-Bop6jNiL.js +0 -15
package/dist/concerns/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "node:module";
|
|
2
2
|
import { assign, camel, diff, flat, get, isArray, isEmpty, isEqual, isString, omit, pick, set, snake, trim } from "radashi";
|
|
3
3
|
import advancedFormat from "dayjs/plugin/advancedFormat.js";
|
|
4
4
|
import dayjs from "dayjs";
|
|
@@ -9,6 +9,18 @@ import { existsSync } from "fs";
|
|
|
9
9
|
import { FileSystem } from "@h3ravel/shared";
|
|
10
10
|
import pluralize from "pluralize";
|
|
11
11
|
|
|
12
|
+
//#region rolldown:runtime
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __export = (all) => {
|
|
15
|
+
let target = {};
|
|
16
|
+
for (var name in all) __defProp(target, name, {
|
|
17
|
+
get: all[name],
|
|
18
|
+
enumerable: true
|
|
19
|
+
});
|
|
20
|
+
return target;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
12
24
|
//#region src/mixin.ts
|
|
13
25
|
var mixin_exports = /* @__PURE__ */ __export({ compose: () => compose$1 });
|
|
14
26
|
/**
|
|
@@ -137,8 +149,7 @@ var casts_attributes_default = CastsAttributes;
|
|
|
137
149
|
|
|
138
150
|
//#endregion
|
|
139
151
|
//#region src/concerns/has-attributes.ts
|
|
140
|
-
|
|
141
|
-
const HasAttributes = (Model$1) => {
|
|
152
|
+
const HasAttributes$1 = (Model$1) => {
|
|
142
153
|
return class extends Model$1 {
|
|
143
154
|
static castTypeCache = {};
|
|
144
155
|
attributes = {};
|
|
@@ -380,7 +391,7 @@ const HasAttributes = (Model$1) => {
|
|
|
380
391
|
}
|
|
381
392
|
};
|
|
382
393
|
};
|
|
383
|
-
var has_attributes_default = HasAttributes;
|
|
394
|
+
var has_attributes_default = HasAttributes$1;
|
|
384
395
|
|
|
385
396
|
//#endregion
|
|
386
397
|
//#region src/errors.ts
|
|
@@ -430,8 +441,7 @@ var scope_default = Scope;
|
|
|
430
441
|
|
|
431
442
|
//#endregion
|
|
432
443
|
//#region src/concerns/has-global-scopes.ts
|
|
433
|
-
|
|
434
|
-
const HasGlobalScopes = (Model$1) => {
|
|
444
|
+
const HasGlobalScopes$1 = (Model$1) => {
|
|
435
445
|
return class extends Model$1 {
|
|
436
446
|
static globalScopes;
|
|
437
447
|
static addGlobalScope(scope, implementation = null) {
|
|
@@ -462,7 +472,7 @@ const HasGlobalScopes = (Model$1) => {
|
|
|
462
472
|
}
|
|
463
473
|
};
|
|
464
474
|
};
|
|
465
|
-
var has_global_scopes_default = HasGlobalScopes;
|
|
475
|
+
var has_global_scopes_default = HasGlobalScopes$1;
|
|
466
476
|
|
|
467
477
|
//#endregion
|
|
468
478
|
//#region src/hooks.ts
|
|
@@ -495,8 +505,7 @@ var hooks_default = Hooks;
|
|
|
495
505
|
|
|
496
506
|
//#endregion
|
|
497
507
|
//#region src/concerns/has-hooks.ts
|
|
498
|
-
|
|
499
|
-
const HasHooks = (Model$1) => {
|
|
508
|
+
const HasHooks$1 = (Model$1) => {
|
|
500
509
|
return class extends Model$1 {
|
|
501
510
|
static hooks = null;
|
|
502
511
|
static addHook(hook, callback) {
|
|
@@ -545,7 +554,7 @@ const HasHooks = (Model$1) => {
|
|
|
545
554
|
}
|
|
546
555
|
};
|
|
547
556
|
};
|
|
548
|
-
var has_hooks_default = HasHooks;
|
|
557
|
+
var has_hooks_default = HasHooks$1;
|
|
549
558
|
|
|
550
559
|
//#endregion
|
|
551
560
|
//#region src/collection.ts
|
|
@@ -2139,8 +2148,7 @@ var has_one_default = HasOne;
|
|
|
2139
2148
|
|
|
2140
2149
|
//#endregion
|
|
2141
2150
|
//#region src/concerns/has-timestamps.ts
|
|
2142
|
-
|
|
2143
|
-
const HasTimestamps = (Model$1) => {
|
|
2151
|
+
const HasTimestamps$1 = (Model$1) => {
|
|
2144
2152
|
return class extends Model$1 {
|
|
2145
2153
|
static CREATED_AT = "created_at";
|
|
2146
2154
|
static UPDATED_AT = "updated_at";
|
|
@@ -2182,12 +2190,11 @@ const HasTimestamps = (Model$1) => {
|
|
|
2182
2190
|
}
|
|
2183
2191
|
};
|
|
2184
2192
|
};
|
|
2185
|
-
var has_timestamps_default = HasTimestamps;
|
|
2193
|
+
var has_timestamps_default = HasTimestamps$1;
|
|
2186
2194
|
|
|
2187
2195
|
//#endregion
|
|
2188
2196
|
//#region src/concerns/hides-attributes.ts
|
|
2189
|
-
|
|
2190
|
-
const HidesAttributes = (Model$1) => {
|
|
2197
|
+
const HidesAttributes$1 = (Model$1) => {
|
|
2191
2198
|
return class extends Model$1 {
|
|
2192
2199
|
hidden = [];
|
|
2193
2200
|
visible = [];
|
|
@@ -2218,12 +2225,11 @@ const HidesAttributes = (Model$1) => {
|
|
|
2218
2225
|
}
|
|
2219
2226
|
};
|
|
2220
2227
|
};
|
|
2221
|
-
var hides_attributes_default = HidesAttributes;
|
|
2228
|
+
var hides_attributes_default = HidesAttributes$1;
|
|
2222
2229
|
|
|
2223
2230
|
//#endregion
|
|
2224
2231
|
//#region src/concerns/unique-ids.ts
|
|
2225
|
-
|
|
2226
|
-
const UniqueIds = (Model$1) => {
|
|
2232
|
+
const UniqueIds$1 = (Model$1) => {
|
|
2227
2233
|
return class extends Model$1 {
|
|
2228
2234
|
useUniqueIds = false;
|
|
2229
2235
|
usesUniqueIds() {
|
|
@@ -2238,7 +2244,7 @@ const UniqueIds = (Model$1) => {
|
|
|
2238
2244
|
}
|
|
2239
2245
|
};
|
|
2240
2246
|
};
|
|
2241
|
-
var unique_ids_default = UniqueIds;
|
|
2247
|
+
var unique_ids_default = UniqueIds$1;
|
|
2242
2248
|
|
|
2243
2249
|
//#endregion
|
|
2244
2250
|
//#region src/casts/attribute.ts
|
|
@@ -3337,8 +3343,7 @@ var has_one_through_default = HasOneThrough;
|
|
|
3337
3343
|
|
|
3338
3344
|
//#endregion
|
|
3339
3345
|
//#region src/concerns/has-relations.ts
|
|
3340
|
-
|
|
3341
|
-
const HasRelations = (Model$1) => {
|
|
3346
|
+
const HasRelations$1 = (Model$1) => {
|
|
3342
3347
|
return class extends Model$1 {
|
|
3343
3348
|
relations = {};
|
|
3344
3349
|
getRelation(relation) {
|
|
@@ -3430,12 +3435,11 @@ const HasRelations = (Model$1) => {
|
|
|
3430
3435
|
}
|
|
3431
3436
|
};
|
|
3432
3437
|
};
|
|
3433
|
-
var has_relations_default = HasRelations;
|
|
3438
|
+
var has_relations_default = HasRelations$1;
|
|
3434
3439
|
|
|
3435
3440
|
//#endregion
|
|
3436
3441
|
//#region src/concerns/has-unique-ids.ts
|
|
3437
|
-
|
|
3438
|
-
const HasUniqueIds = (Model$1) => {
|
|
3442
|
+
const HasUniqueIds$1 = (Model$1) => {
|
|
3439
3443
|
return class extends Model$1 {
|
|
3440
3444
|
useUniqueIds = true;
|
|
3441
3445
|
uniqueIds() {
|
|
@@ -3451,7 +3455,18 @@ const HasUniqueIds = (Model$1) => {
|
|
|
3451
3455
|
}
|
|
3452
3456
|
};
|
|
3453
3457
|
};
|
|
3454
|
-
var has_unique_ids_default = HasUniqueIds;
|
|
3458
|
+
var has_unique_ids_default = HasUniqueIds$1;
|
|
3459
|
+
|
|
3460
|
+
//#endregion
|
|
3461
|
+
//#region src/concerns/index.ts
|
|
3462
|
+
const HasAttributes = has_attributes_default;
|
|
3463
|
+
const HasGlobalScopes = has_global_scopes_default;
|
|
3464
|
+
const HasHooks = has_hooks_default;
|
|
3465
|
+
const HasRelations = has_relations_default;
|
|
3466
|
+
const HasTimestamps = has_timestamps_default;
|
|
3467
|
+
const HasUniqueIds = has_unique_ids_default;
|
|
3468
|
+
const HidesAttributes = hides_attributes_default;
|
|
3469
|
+
const UniqueIds = unique_ids_default;
|
|
3455
3470
|
|
|
3456
3471
|
//#endregion
|
|
3457
|
-
export {
|
|
3472
|
+
export { HasAttributes, HasGlobalScopes, HasHooks, HasRelations, HasTimestamps, HasUniqueIds, HidesAttributes, UniqueIds };
|
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
29
|
}) : target, mod));
|
|
30
30
|
|
|
31
31
|
//#endregion
|
|
32
|
+
let node_fs_promises = require("node:fs/promises");
|
|
33
|
+
node_fs_promises = __toESM(node_fs_promises);
|
|
34
|
+
let path = require("path");
|
|
35
|
+
path = __toESM(path);
|
|
36
|
+
let node_path = require("node:path");
|
|
37
|
+
let node_url = require("node:url");
|
|
32
38
|
let radashi = require("radashi");
|
|
33
39
|
let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
|
|
34
40
|
dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js);
|
|
@@ -38,19 +44,118 @@ let collect_js = require("collect.js");
|
|
|
38
44
|
collect_js = __toESM(collect_js);
|
|
39
45
|
let knex = require("knex");
|
|
40
46
|
knex = __toESM(knex);
|
|
41
|
-
let path = require("path");
|
|
42
|
-
path = __toESM(path);
|
|
43
47
|
let fs = require("fs");
|
|
44
48
|
let __h3ravel_shared = require("@h3ravel/shared");
|
|
45
49
|
let pluralize = require("pluralize");
|
|
46
50
|
pluralize = __toESM(pluralize);
|
|
47
|
-
let node_fs_promises = require("node:fs/promises");
|
|
48
|
-
node_fs_promises = __toESM(node_fs_promises);
|
|
49
51
|
let resolve_from = require("resolve-from");
|
|
50
52
|
resolve_from = __toESM(resolve_from);
|
|
51
|
-
let node_path = require("node:path");
|
|
52
|
-
let node_url = require("node:url");
|
|
53
53
|
|
|
54
|
+
//#region src/seeders/seeder.ts
|
|
55
|
+
var Seeder = class {};
|
|
56
|
+
var seeder_default = Seeder;
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/seeders/runner.ts
|
|
60
|
+
async function glob$1(folderPath) {
|
|
61
|
+
const { default: escalade } = await import("escalade");
|
|
62
|
+
const entries = [];
|
|
63
|
+
await escalade(folderPath, async (dir, names) => {
|
|
64
|
+
await Promise.all(names.map(async (name) => {
|
|
65
|
+
const p = path.default.join(dir, name);
|
|
66
|
+
try {
|
|
67
|
+
await (0, node_fs_promises.access)(p);
|
|
68
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) entries.push(p);
|
|
69
|
+
} catch {}
|
|
70
|
+
}));
|
|
71
|
+
return "";
|
|
72
|
+
});
|
|
73
|
+
return entries;
|
|
74
|
+
}
|
|
75
|
+
var SeederRunner = class {
|
|
76
|
+
resolver;
|
|
77
|
+
connection;
|
|
78
|
+
paths = [];
|
|
79
|
+
constructor(resolver) {
|
|
80
|
+
this.resolver = resolver;
|
|
81
|
+
}
|
|
82
|
+
path(p) {
|
|
83
|
+
this.paths = Array.from(new Set([...this.paths, p]));
|
|
84
|
+
}
|
|
85
|
+
getPaths() {
|
|
86
|
+
return this.paths;
|
|
87
|
+
}
|
|
88
|
+
resolveConnection(connection) {
|
|
89
|
+
var _getInstance, _ref, _instance$connections;
|
|
90
|
+
const name = connection || this.connection || "default";
|
|
91
|
+
const instance = ((_getInstance = (_ref = this.resolver).getInstance) === null || _getInstance === void 0 ? void 0 : _getInstance.call(_ref)) ?? null;
|
|
92
|
+
if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
|
|
93
|
+
/** noop */
|
|
94
|
+
});
|
|
95
|
+
return this.resolver.fire(name);
|
|
96
|
+
}
|
|
97
|
+
setConnection(connection) {
|
|
98
|
+
this.connection = connection;
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
async getSeederFiles(paths) {
|
|
102
|
+
const files = [];
|
|
103
|
+
for (const p of paths) {
|
|
104
|
+
if (p.endsWith(".js") || p.endsWith(".ts")) {
|
|
105
|
+
files.push(p);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
files.push(...await glob$1(p));
|
|
109
|
+
}
|
|
110
|
+
return files;
|
|
111
|
+
}
|
|
112
|
+
async resolvePath(filePath) {
|
|
113
|
+
try {
|
|
114
|
+
const mod = await import(filePath);
|
|
115
|
+
return new (mod.default ?? mod.Seeder)();
|
|
116
|
+
} catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async run(paths, connection) {
|
|
121
|
+
const files = await this.getSeederFiles(paths);
|
|
122
|
+
const conn = this.resolveConnection(connection);
|
|
123
|
+
for (const file of files) {
|
|
124
|
+
const seeder = await this.resolvePath(file);
|
|
125
|
+
if (seeder && typeof seeder.run === "function") await seeder.run(conn);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
var runner_default = SeederRunner;
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/seeders/seeder-creator.ts
|
|
133
|
+
var SeederCreator = class {
|
|
134
|
+
constructor(customStubPath) {
|
|
135
|
+
this.customStubPath = customStubPath;
|
|
136
|
+
}
|
|
137
|
+
async create(dir, name, type = "js") {
|
|
138
|
+
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
139
|
+
let stub = await (0, node_fs_promises.readFile)(this.getStubPath(type), "utf-8");
|
|
140
|
+
stub = stub.replace(/{{ name }}/g, name);
|
|
141
|
+
const filePath = path.default.join(dir, `${name}.${type}`);
|
|
142
|
+
await (0, node_fs_promises.writeFile)(filePath, stub);
|
|
143
|
+
return filePath;
|
|
144
|
+
}
|
|
145
|
+
getStubPath(type) {
|
|
146
|
+
if (this.customStubPath) return path.default.join(this.customStubPath, `seeder-${type}.stub`);
|
|
147
|
+
const __dirname$1 = this.getDirname({});
|
|
148
|
+
return path.default.join(__dirname$1, "stubs", `seeder-${type}.stub`);
|
|
149
|
+
}
|
|
150
|
+
getDirname(meta) {
|
|
151
|
+
if (typeof __dirname !== "undefined") return __dirname;
|
|
152
|
+
if (meta && meta.url) return (0, node_path.dirname)((0, node_url.fileURLToPath)(meta.url));
|
|
153
|
+
throw new Error("Unable to determine dirname");
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
var seeder_creator_default = SeederCreator;
|
|
157
|
+
|
|
158
|
+
//#endregion
|
|
54
159
|
//#region src/casts/attribute.ts
|
|
55
160
|
var Attribute = class Attribute {
|
|
56
161
|
get;
|
|
@@ -4974,7 +5079,7 @@ var SchemaInspector = class {
|
|
|
4974
5079
|
|
|
4975
5080
|
//#endregion
|
|
4976
5081
|
//#region src/migrations/migrator.ts
|
|
4977
|
-
async function glob
|
|
5082
|
+
async function glob(folderPath) {
|
|
4978
5083
|
const files = await node_fs_promises.default.readdir(folderPath);
|
|
4979
5084
|
const allFiles = [];
|
|
4980
5085
|
for (const file of files) {
|
|
@@ -4982,7 +5087,7 @@ async function glob$1(folderPath) {
|
|
|
4982
5087
|
const stats = await node_fs_promises.default.stat(filePath);
|
|
4983
5088
|
if (stats.isFile()) allFiles.push(filePath);
|
|
4984
5089
|
else if (stats.isDirectory()) {
|
|
4985
|
-
const subFiles = await glob
|
|
5090
|
+
const subFiles = await glob(filePath);
|
|
4986
5091
|
allFiles.push(...subFiles);
|
|
4987
5092
|
}
|
|
4988
5093
|
}
|
|
@@ -5125,7 +5230,7 @@ var Migrator = class {
|
|
|
5125
5230
|
files.push(p);
|
|
5126
5231
|
continue;
|
|
5127
5232
|
}
|
|
5128
|
-
files.push(...await glob
|
|
5233
|
+
files.push(...await glob(p));
|
|
5129
5234
|
}
|
|
5130
5235
|
return files.filter(Boolean).reduce((result, file) => {
|
|
5131
5236
|
result[this.getMigrationName(file)] = file;
|
|
@@ -5352,111 +5457,6 @@ var Migration = class extends Inference {
|
|
|
5352
5457
|
};
|
|
5353
5458
|
var migration_default = Migration;
|
|
5354
5459
|
|
|
5355
|
-
//#endregion
|
|
5356
|
-
//#region src/seeders/seeder.ts
|
|
5357
|
-
var Seeder = class {};
|
|
5358
|
-
var seeder_default = Seeder;
|
|
5359
|
-
|
|
5360
|
-
//#endregion
|
|
5361
|
-
//#region src/seeders/runner.ts
|
|
5362
|
-
async function glob(folderPath) {
|
|
5363
|
-
const { default: escalade } = await import("escalade");
|
|
5364
|
-
const entries = [];
|
|
5365
|
-
await escalade(folderPath, async (dir, names) => {
|
|
5366
|
-
await Promise.all(names.map(async (name) => {
|
|
5367
|
-
const p = path.default.join(dir, name);
|
|
5368
|
-
try {
|
|
5369
|
-
await (0, node_fs_promises.access)(p);
|
|
5370
|
-
if (p.endsWith(".js") || p.endsWith(".ts")) entries.push(p);
|
|
5371
|
-
} catch {}
|
|
5372
|
-
}));
|
|
5373
|
-
return "";
|
|
5374
|
-
});
|
|
5375
|
-
return entries;
|
|
5376
|
-
}
|
|
5377
|
-
var SeederRunner = class {
|
|
5378
|
-
resolver;
|
|
5379
|
-
connection;
|
|
5380
|
-
paths = [];
|
|
5381
|
-
constructor(resolver) {
|
|
5382
|
-
this.resolver = resolver;
|
|
5383
|
-
}
|
|
5384
|
-
path(p) {
|
|
5385
|
-
this.paths = Array.from(new Set([...this.paths, p]));
|
|
5386
|
-
}
|
|
5387
|
-
getPaths() {
|
|
5388
|
-
return this.paths;
|
|
5389
|
-
}
|
|
5390
|
-
resolveConnection(connection) {
|
|
5391
|
-
var _getInstance, _ref, _instance$connections;
|
|
5392
|
-
const name = connection || this.connection || "default";
|
|
5393
|
-
const instance = ((_getInstance = (_ref = this.resolver).getInstance) === null || _getInstance === void 0 ? void 0 : _getInstance.call(_ref)) ?? null;
|
|
5394
|
-
if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
|
|
5395
|
-
/** noop */
|
|
5396
|
-
});
|
|
5397
|
-
return this.resolver.fire(name);
|
|
5398
|
-
}
|
|
5399
|
-
setConnection(connection) {
|
|
5400
|
-
this.connection = connection;
|
|
5401
|
-
return this;
|
|
5402
|
-
}
|
|
5403
|
-
async getSeederFiles(paths) {
|
|
5404
|
-
const files = [];
|
|
5405
|
-
for (const p of paths) {
|
|
5406
|
-
if (p.endsWith(".js") || p.endsWith(".ts")) {
|
|
5407
|
-
files.push(p);
|
|
5408
|
-
continue;
|
|
5409
|
-
}
|
|
5410
|
-
files.push(...await glob(p));
|
|
5411
|
-
}
|
|
5412
|
-
return files;
|
|
5413
|
-
}
|
|
5414
|
-
async resolvePath(filePath) {
|
|
5415
|
-
try {
|
|
5416
|
-
const mod = await import(filePath);
|
|
5417
|
-
return new (mod.default ?? mod.Seeder)();
|
|
5418
|
-
} catch {
|
|
5419
|
-
return null;
|
|
5420
|
-
}
|
|
5421
|
-
}
|
|
5422
|
-
async run(paths, connection) {
|
|
5423
|
-
const files = await this.getSeederFiles(paths);
|
|
5424
|
-
const conn = this.resolveConnection(connection);
|
|
5425
|
-
for (const file of files) {
|
|
5426
|
-
const seeder = await this.resolvePath(file);
|
|
5427
|
-
if (seeder && typeof seeder.run === "function") await seeder.run(conn);
|
|
5428
|
-
}
|
|
5429
|
-
}
|
|
5430
|
-
};
|
|
5431
|
-
var runner_default = SeederRunner;
|
|
5432
|
-
|
|
5433
|
-
//#endregion
|
|
5434
|
-
//#region src/seeders/seeder-creator.ts
|
|
5435
|
-
var SeederCreator = class {
|
|
5436
|
-
constructor(customStubPath) {
|
|
5437
|
-
this.customStubPath = customStubPath;
|
|
5438
|
-
}
|
|
5439
|
-
async create(dir, name, type = "js") {
|
|
5440
|
-
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
5441
|
-
let stub = await (0, node_fs_promises.readFile)(this.getStubPath(type), "utf-8");
|
|
5442
|
-
stub = stub.replace(/{{ name }}/g, name);
|
|
5443
|
-
const filePath = path.default.join(dir, `${name}.${type}`);
|
|
5444
|
-
await (0, node_fs_promises.writeFile)(filePath, stub);
|
|
5445
|
-
return filePath;
|
|
5446
|
-
}
|
|
5447
|
-
getStubPath(type) {
|
|
5448
|
-
if (this.customStubPath) return path.default.join(this.customStubPath, `seeder-${type}.stub`);
|
|
5449
|
-
const __dirname$1 = this.getDirname({});
|
|
5450
|
-
return path.default.join(__dirname$1, "stubs", `seeder-${type}.stub`);
|
|
5451
|
-
}
|
|
5452
|
-
getDirname(meta) {
|
|
5453
|
-
if (typeof __dirname !== "undefined") return __dirname;
|
|
5454
|
-
if (meta && meta.url) return (0, node_path.dirname)((0, node_url.fileURLToPath)(meta.url));
|
|
5455
|
-
throw new Error("Unable to determine dirname");
|
|
5456
|
-
}
|
|
5457
|
-
};
|
|
5458
|
-
var seeder_creator_default = SeederCreator;
|
|
5459
|
-
|
|
5460
5460
|
//#endregion
|
|
5461
5461
|
//#region src/pivot.ts
|
|
5462
5462
|
var pivot_default = Pivot;
|
|
@@ -5628,11 +5628,11 @@ var soft_deletes_default = softDeletes;
|
|
|
5628
5628
|
const make = (model, data, options = {}) => {
|
|
5629
5629
|
const { paginated } = options;
|
|
5630
5630
|
if (paginated) return new paginator_default(data.data.map((item) => model.make(item)), data.total, data.per_page, data.current_page);
|
|
5631
|
-
if (
|
|
5631
|
+
if ((0, radashi.isArray)(data)) return new collection_default(data.map((item) => model.make(item)));
|
|
5632
5632
|
return model.make(data);
|
|
5633
5633
|
};
|
|
5634
5634
|
const makeCollection = (model, data) => new collection_default(data.map((item) => model.make(item)));
|
|
5635
|
-
const makePaginator = (model, data
|
|
5635
|
+
const makePaginator = (model, data) => new paginator_default(data.data.map((item) => model.make(item)), data.total, data.per_page, data.current_page);
|
|
5636
5636
|
|
|
5637
5637
|
//#endregion
|
|
5638
5638
|
exports.Attribute = attribute_default;
|
package/dist/index.d.ts
CHANGED
|
@@ -667,6 +667,7 @@ interface IModel {
|
|
|
667
667
|
setAppends(appends: string[]): this;
|
|
668
668
|
append(key: string | string[]): this;
|
|
669
669
|
getRelation<T$1 extends Model$1>(relation: string): T$1 | ICollection<T$1> | null | undefined;
|
|
670
|
+
getRelation<T$1 extends Model$1, IsCollection extends boolean = false>(relation: string): IsCollection extends true ? ICollection<T$1> | undefined : T$1 | null | undefined;
|
|
670
671
|
setRelation<T$1 extends Model$1>(relation: string, value: T$1 | ICollection<T$1> | null): this;
|
|
671
672
|
unsetRelation(relation: string): this;
|
|
672
673
|
relationLoaded(relation: string): boolean;
|
|
@@ -1939,7 +1940,10 @@ declare const BaseModel$1: (new (...args: any[]) => any) & {
|
|
|
1939
1940
|
uniqueIds(): never[];
|
|
1940
1941
|
setUniqueIds(): void;
|
|
1941
1942
|
});
|
|
1942
|
-
getRelation:
|
|
1943
|
+
getRelation: {
|
|
1944
|
+
<T$1 extends Model$1>(relation: string): T$1 | ICollection<T$1> | null | undefined;
|
|
1945
|
+
<T$1 extends Model$1, IsCollection extends boolean = false>(relation: string): IsCollection extends true ? ICollection<T$1> | undefined : T$1 | null | undefined;
|
|
1946
|
+
};
|
|
1943
1947
|
setRelation: <T$1 extends Model$1>(relation: string, value: T$1 | ICollection<T$1> | null) => (new () => IModel) & IModel & {
|
|
1944
1948
|
[x: string]: any;
|
|
1945
1949
|
timestamps: boolean;
|
|
@@ -4647,16 +4651,16 @@ declare class Collection$2<I$1 extends Model$2> extends Collection$1<I$1> {
|
|
|
4647
4651
|
append(attributes: any): this;
|
|
4648
4652
|
only(keys: any[]): any;
|
|
4649
4653
|
getDictionary(items?: ICollection<any> | any[]): TGeneric;
|
|
4650
|
-
toData(): (
|
|
4654
|
+
toData(): ({
|
|
4651
4655
|
[x: string]: any;
|
|
4652
4656
|
[x: number]: any;
|
|
4653
4657
|
[x: symbol]: any;
|
|
4654
|
-
})[];
|
|
4655
|
-
toJSON(): (
|
|
4658
|
+
} | I$1)[];
|
|
4659
|
+
toJSON(): ({
|
|
4656
4660
|
[x: string]: any;
|
|
4657
4661
|
[x: number]: any;
|
|
4658
4662
|
[x: symbol]: any;
|
|
4659
|
-
})[];
|
|
4663
|
+
} | I$1)[];
|
|
4660
4664
|
toJson(...args: any[]): string;
|
|
4661
4665
|
[Symbol.iterator]: () => Iterator<I$1>;
|
|
4662
4666
|
}
|
|
@@ -4734,6 +4738,38 @@ declare class Pivot$1 extends Model$2 {
|
|
|
4734
4738
|
hasTimestampAttributes(this: any, attributes?: TGeneric | null): boolean;
|
|
4735
4739
|
}
|
|
4736
4740
|
//#endregion
|
|
4741
|
+
//#region src/seeders/seeder.d.ts
|
|
4742
|
+
declare abstract class Seeder {
|
|
4743
|
+
/**
|
|
4744
|
+
* Run the database seeds
|
|
4745
|
+
*/
|
|
4746
|
+
abstract run(connection: QueryBuilder): Promise<void>;
|
|
4747
|
+
}
|
|
4748
|
+
//#endregion
|
|
4749
|
+
//#region src/seeders/runner.d.ts
|
|
4750
|
+
declare class SeederRunner {
|
|
4751
|
+
resolver: typeof arquebus;
|
|
4752
|
+
connection: TBaseConfig['client'];
|
|
4753
|
+
paths: string[];
|
|
4754
|
+
constructor(resolver: typeof arquebus);
|
|
4755
|
+
path(p: string): void;
|
|
4756
|
+
getPaths(): string[];
|
|
4757
|
+
resolveConnection(connection?: TBaseConfig['client']): QueryBuilder;
|
|
4758
|
+
setConnection(connection: TBaseConfig['client']): this;
|
|
4759
|
+
getSeederFiles(paths: string[]): Promise<string[]>;
|
|
4760
|
+
resolvePath(filePath: string): Promise<Seeder | null>;
|
|
4761
|
+
run(paths: string[], connection?: TBaseConfig['client']): Promise<void>;
|
|
4762
|
+
}
|
|
4763
|
+
//#endregion
|
|
4764
|
+
//#region src/seeders/seeder-creator.d.ts
|
|
4765
|
+
declare class SeederCreator {
|
|
4766
|
+
private customStubPath?;
|
|
4767
|
+
constructor(customStubPath?: string | undefined);
|
|
4768
|
+
create(dir: string, name: string, type?: 'js' | 'ts'): Promise<string>;
|
|
4769
|
+
getStubPath(type: 'js' | 'ts'): string;
|
|
4770
|
+
getDirname(meta: ImportMeta | null): string;
|
|
4771
|
+
}
|
|
4772
|
+
//#endregion
|
|
4737
4773
|
//#region src/casts/attribute.d.ts
|
|
4738
4774
|
interface IAttribute {
|
|
4739
4775
|
get?: null | (<A extends TGeneric>(value: string, attr: A) => string);
|
|
@@ -4961,38 +4997,6 @@ declare class Migrate {
|
|
|
4961
4997
|
}>;
|
|
4962
4998
|
}
|
|
4963
4999
|
//#endregion
|
|
4964
|
-
//#region src/seeders/seeder.d.ts
|
|
4965
|
-
declare abstract class Seeder {
|
|
4966
|
-
/**
|
|
4967
|
-
* Run the database seeds
|
|
4968
|
-
*/
|
|
4969
|
-
abstract run(connection: QueryBuilder): Promise<void>;
|
|
4970
|
-
}
|
|
4971
|
-
//#endregion
|
|
4972
|
-
//#region src/seeders/runner.d.ts
|
|
4973
|
-
declare class SeederRunner {
|
|
4974
|
-
resolver: typeof arquebus;
|
|
4975
|
-
connection: TBaseConfig['client'];
|
|
4976
|
-
paths: string[];
|
|
4977
|
-
constructor(resolver: typeof arquebus);
|
|
4978
|
-
path(p: string): void;
|
|
4979
|
-
getPaths(): string[];
|
|
4980
|
-
resolveConnection(connection?: TBaseConfig['client']): QueryBuilder;
|
|
4981
|
-
setConnection(connection: TBaseConfig['client']): this;
|
|
4982
|
-
getSeederFiles(paths: string[]): Promise<string[]>;
|
|
4983
|
-
resolvePath(filePath: string): Promise<Seeder | null>;
|
|
4984
|
-
run(paths: string[], connection?: TBaseConfig['client']): Promise<void>;
|
|
4985
|
-
}
|
|
4986
|
-
//#endregion
|
|
4987
|
-
//#region src/seeders/seeder-creator.d.ts
|
|
4988
|
-
declare class SeederCreator {
|
|
4989
|
-
private customStubPath?;
|
|
4990
|
-
constructor(customStubPath?: string | undefined);
|
|
4991
|
-
create(dir: string, name: string, type?: 'js' | 'ts'): Promise<string>;
|
|
4992
|
-
getStubPath(type: 'js' | 'ts'): string;
|
|
4993
|
-
getDirname(meta: ImportMeta | null): string;
|
|
4994
|
-
}
|
|
4995
|
-
//#endregion
|
|
4996
5000
|
//#region src/soft-deletes.d.ts
|
|
4997
5001
|
declare const softDeletes: <TBase extends MixinConstructor>(Model: TBase) => {
|
|
4998
5002
|
new (...args: any[]): {
|
|
@@ -5120,10 +5124,15 @@ declare const snakeCase: (str: string) => string;
|
|
|
5120
5124
|
declare const defineConfig: (config: TConfig) => XGeneric<TConfig>;
|
|
5121
5125
|
//#endregion
|
|
5122
5126
|
//#region src/index.d.ts
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5127
|
+
interface IMake {
|
|
5128
|
+
<T$1 extends Model$1>(model: T$1, data: TGeneric): T$1;
|
|
5129
|
+
<T$1 extends Model$1>(model: T$1, data: Array<TGeneric>): Collection<T$1>;
|
|
5130
|
+
<T$1 extends Model$1>(model: T$1, data: TGeneric, options: {
|
|
5131
|
+
paginated?: IPaginatorParams;
|
|
5132
|
+
}): Paginator<T$1>;
|
|
5133
|
+
}
|
|
5134
|
+
declare const make: IMake;
|
|
5135
|
+
declare const makeCollection: <T$1 extends Model$1>(model: T$1, data: TGeneric) => Collection<Model$1 | Model$2>;
|
|
5136
|
+
declare const makePaginator: <T$1 extends Model$1>(model: T$1, data: TGeneric) => Paginator<T$1, IPaginatorParams>;
|
|
5128
5137
|
//#endregion
|
|
5129
5138
|
export { Attribute, Builder, CastsAttributes, Collection, HasUniqueIds, InvalidArgumentError, Migrate, Migration, Model$1 as Model, ModelNotFoundError, Paginator, Pivot, QueryBuilder, RelationNotFoundError, Scope, Seeder, SeederCreator, SeederRunner, softDeletes as SoftDeletes, arquebus, compose, defineConfig, flatten, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, kebabCase, make, makeCollection, makePaginator, now, snakeCase, tap };
|