@h3ravel/arquebus 0.7.2 → 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 CHANGED
@@ -38,6 +38,8 @@ let resolve_from = require("resolve-from");
38
38
  resolve_from = __toESM(resolve_from);
39
39
  let node_fs_promises = require("node:fs/promises");
40
40
  node_fs_promises = __toESM(node_fs_promises);
41
+ let node_path = require("node:path");
42
+ let node_url = require("node:url");
41
43
  let radashi = require("radashi");
42
44
  let dayjs_plugin_advancedFormat_js = require("dayjs/plugin/advancedFormat.js");
43
45
  dayjs_plugin_advancedFormat_js = __toESM(dayjs_plugin_advancedFormat_js);
@@ -50,8 +52,6 @@ knex = __toESM(knex);
50
52
  let fs = require("fs");
51
53
  let pluralize = require("pluralize");
52
54
  pluralize = __toESM(pluralize);
53
- let node_path = require("node:path");
54
- let node_url = require("node:url");
55
55
  let __h3ravel_support = require("@h3ravel/support");
56
56
  let dotenv = require("dotenv");
57
57
 
@@ -1397,6 +1397,79 @@ function extractType(type) {
1397
1397
  return type.replace(/[^a-zA-Z]/g, "").toLowerCase();
1398
1398
  }
1399
1399
 
1400
+ //#endregion
1401
+ //#region src/seeders/runner.ts
1402
+ async function glob$1(folderPath) {
1403
+ const { default: escalade } = await import("escalade");
1404
+ const entries = [];
1405
+ await escalade(folderPath, async (dir, names) => {
1406
+ await Promise.all(names.map(async (name) => {
1407
+ const p = path.default.join(dir, name);
1408
+ try {
1409
+ await (0, node_fs_promises.access)(p);
1410
+ if (p.endsWith(".js") || p.endsWith(".ts")) entries.push(p);
1411
+ } catch {}
1412
+ }));
1413
+ return "";
1414
+ });
1415
+ return entries;
1416
+ }
1417
+ var SeederRunner = class {
1418
+ resolver;
1419
+ connection;
1420
+ paths = [];
1421
+ constructor(resolver) {
1422
+ this.resolver = resolver;
1423
+ }
1424
+ path(p) {
1425
+ this.paths = Array.from(new Set([...this.paths, p]));
1426
+ }
1427
+ getPaths() {
1428
+ return this.paths;
1429
+ }
1430
+ resolveConnection(connection) {
1431
+ var _getInstance, _ref, _instance$connections;
1432
+ const name = connection || this.connection || "default";
1433
+ const instance = ((_getInstance = (_ref = this.resolver).getInstance) === null || _getInstance === void 0 ? void 0 : _getInstance.call(_ref)) ?? null;
1434
+ if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
1435
+ /** noop */
1436
+ });
1437
+ return this.resolver.fire(name);
1438
+ }
1439
+ setConnection(connection) {
1440
+ this.connection = connection;
1441
+ return this;
1442
+ }
1443
+ async getSeederFiles(paths) {
1444
+ const files = [];
1445
+ for (const p of paths) {
1446
+ if (p.endsWith(".js") || p.endsWith(".ts")) {
1447
+ files.push(p);
1448
+ continue;
1449
+ }
1450
+ files.push(...await glob$1(p));
1451
+ }
1452
+ return files;
1453
+ }
1454
+ async resolvePath(filePath) {
1455
+ try {
1456
+ const mod = await import(filePath);
1457
+ return new (mod.default ?? mod.Seeder)();
1458
+ } catch {
1459
+ return null;
1460
+ }
1461
+ }
1462
+ async run(paths, connection) {
1463
+ const files = await this.getSeederFiles(paths);
1464
+ const conn = this.resolveConnection(connection);
1465
+ for (const file of files) {
1466
+ const seeder = await this.resolvePath(file);
1467
+ if (seeder && typeof seeder.run === "function") await seeder.run(conn);
1468
+ }
1469
+ }
1470
+ };
1471
+ var runner_default = SeederRunner;
1472
+
1400
1473
  //#endregion
1401
1474
  //#region src/casts/attribute.ts
1402
1475
  var Attribute = class Attribute {
@@ -4815,79 +4888,6 @@ var Builder = class Builder extends Inference {
4815
4888
  };
4816
4889
  var builder_default = Builder;
4817
4890
 
4818
- //#endregion
4819
- //#region src/seeders/runner.ts
4820
- async function glob$1(folderPath) {
4821
- const { default: escalade } = await import("escalade");
4822
- const entries = [];
4823
- await escalade(folderPath, async (dir, names) => {
4824
- await Promise.all(names.map(async (name) => {
4825
- const p = path.default.join(dir, name);
4826
- try {
4827
- await (0, node_fs_promises.access)(p);
4828
- if (p.endsWith(".js") || p.endsWith(".ts")) entries.push(p);
4829
- } catch {}
4830
- }));
4831
- return "";
4832
- });
4833
- return entries;
4834
- }
4835
- var SeederRunner = class {
4836
- resolver;
4837
- connection;
4838
- paths = [];
4839
- constructor(resolver) {
4840
- this.resolver = resolver;
4841
- }
4842
- path(p) {
4843
- this.paths = Array.from(new Set([...this.paths, p]));
4844
- }
4845
- getPaths() {
4846
- return this.paths;
4847
- }
4848
- resolveConnection(connection) {
4849
- var _getInstance, _ref, _instance$connections;
4850
- const name = connection || this.connection || "default";
4851
- const instance = ((_getInstance = (_ref = this.resolver).getInstance) === null || _getInstance === void 0 ? void 0 : _getInstance.call(_ref)) ?? null;
4852
- if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
4853
- /** noop */
4854
- });
4855
- return this.resolver.fire(name);
4856
- }
4857
- setConnection(connection) {
4858
- this.connection = connection;
4859
- return this;
4860
- }
4861
- async getSeederFiles(paths) {
4862
- const files = [];
4863
- for (const p of paths) {
4864
- if (p.endsWith(".js") || p.endsWith(".ts")) {
4865
- files.push(p);
4866
- continue;
4867
- }
4868
- files.push(...await glob$1(p));
4869
- }
4870
- return files;
4871
- }
4872
- async resolvePath(filePath) {
4873
- try {
4874
- const mod = await import(filePath);
4875
- return new (mod.default ?? mod.Seeder)();
4876
- } catch {
4877
- return null;
4878
- }
4879
- }
4880
- async run(paths, connection) {
4881
- const files = await this.getSeederFiles(paths);
4882
- const conn = this.resolveConnection(connection);
4883
- for (const file of files) {
4884
- const seeder = await this.resolvePath(file);
4885
- if (seeder && typeof seeder.run === "function") await seeder.run(conn);
4886
- }
4887
- }
4888
- };
4889
- var runner_default = SeederRunner;
4890
-
4891
4891
  //#endregion
4892
4892
  //#region src/inspector/dialects/sqlite.ts
4893
4893
  function parseDefaultValue(value) {
@@ -5490,7 +5490,7 @@ var MigrationCreator = class {
5490
5490
 
5491
5491
  //#endregion
5492
5492
  //#region package.json
5493
- var version = "0.7.1";
5493
+ var version = "0.7.3";
5494
5494
 
5495
5495
  //#endregion
5496
5496
  //#region src/cli/cli.ts
package/bin/index.js CHANGED
@@ -5,6 +5,8 @@ import { FileSystem, Logger, TaskManager } from "@h3ravel/shared";
5
5
  import path from "path";
6
6
  import resolveFrom from "resolve-from";
7
7
  import fs, { access, copyFile, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
8
+ import { dirname } from "node:path";
9
+ import { fileURLToPath } from "node:url";
8
10
  import { assign, camel, diff, flat, get, isArray, isEmpty, isEqual, isString, omit, pick, set, snake, trim } from "radashi";
9
11
  import advancedFormat from "dayjs/plugin/advancedFormat.js";
10
12
  import dayjs from "dayjs";
@@ -12,8 +14,6 @@ import collect, { Collection, collect as collect$1 } from "collect.js";
12
14
  import Knex from "knex";
13
15
  import { existsSync } from "fs";
14
16
  import pluralize from "pluralize";
15
- import { dirname } from "node:path";
16
- import { fileURLToPath } from "node:url";
17
17
  import { Str } from "@h3ravel/support";
18
18
  import { config } from "dotenv";
19
19
 
@@ -1371,6 +1371,79 @@ function extractType(type) {
1371
1371
  return type.replace(/[^a-zA-Z]/g, "").toLowerCase();
1372
1372
  }
1373
1373
 
1374
+ //#endregion
1375
+ //#region src/seeders/runner.ts
1376
+ async function glob$1(folderPath) {
1377
+ const { default: escalade } = await import("escalade");
1378
+ const entries = [];
1379
+ await escalade(folderPath, async (dir, names) => {
1380
+ await Promise.all(names.map(async (name) => {
1381
+ const p = path.join(dir, name);
1382
+ try {
1383
+ await access(p);
1384
+ if (p.endsWith(".js") || p.endsWith(".ts")) entries.push(p);
1385
+ } catch {}
1386
+ }));
1387
+ return "";
1388
+ });
1389
+ return entries;
1390
+ }
1391
+ var SeederRunner = class {
1392
+ resolver;
1393
+ connection;
1394
+ paths = [];
1395
+ constructor(resolver) {
1396
+ this.resolver = resolver;
1397
+ }
1398
+ path(p) {
1399
+ this.paths = Array.from(new Set([...this.paths, p]));
1400
+ }
1401
+ getPaths() {
1402
+ return this.paths;
1403
+ }
1404
+ resolveConnection(connection) {
1405
+ var _getInstance, _ref, _instance$connections;
1406
+ const name = connection || this.connection || "default";
1407
+ const instance = ((_getInstance = (_ref = this.resolver).getInstance) === null || _getInstance === void 0 ? void 0 : _getInstance.call(_ref)) ?? null;
1408
+ if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
1409
+ /** noop */
1410
+ });
1411
+ return this.resolver.fire(name);
1412
+ }
1413
+ setConnection(connection) {
1414
+ this.connection = connection;
1415
+ return this;
1416
+ }
1417
+ async getSeederFiles(paths) {
1418
+ const files = [];
1419
+ for (const p of paths) {
1420
+ if (p.endsWith(".js") || p.endsWith(".ts")) {
1421
+ files.push(p);
1422
+ continue;
1423
+ }
1424
+ files.push(...await glob$1(p));
1425
+ }
1426
+ return files;
1427
+ }
1428
+ async resolvePath(filePath) {
1429
+ try {
1430
+ const mod = await import(filePath);
1431
+ return new (mod.default ?? mod.Seeder)();
1432
+ } catch {
1433
+ return null;
1434
+ }
1435
+ }
1436
+ async run(paths, connection) {
1437
+ const files = await this.getSeederFiles(paths);
1438
+ const conn = this.resolveConnection(connection);
1439
+ for (const file of files) {
1440
+ const seeder = await this.resolvePath(file);
1441
+ if (seeder && typeof seeder.run === "function") await seeder.run(conn);
1442
+ }
1443
+ }
1444
+ };
1445
+ var runner_default = SeederRunner;
1446
+
1374
1447
  //#endregion
1375
1448
  //#region src/casts/attribute.ts
1376
1449
  var Attribute = class Attribute {
@@ -4789,79 +4862,6 @@ var Builder = class Builder extends Inference {
4789
4862
  };
4790
4863
  var builder_default = Builder;
4791
4864
 
4792
- //#endregion
4793
- //#region src/seeders/runner.ts
4794
- async function glob$1(folderPath) {
4795
- const { default: escalade } = await import("escalade");
4796
- const entries = [];
4797
- await escalade(folderPath, async (dir, names) => {
4798
- await Promise.all(names.map(async (name) => {
4799
- const p = path.join(dir, name);
4800
- try {
4801
- await access(p);
4802
- if (p.endsWith(".js") || p.endsWith(".ts")) entries.push(p);
4803
- } catch {}
4804
- }));
4805
- return "";
4806
- });
4807
- return entries;
4808
- }
4809
- var SeederRunner = class {
4810
- resolver;
4811
- connection;
4812
- paths = [];
4813
- constructor(resolver) {
4814
- this.resolver = resolver;
4815
- }
4816
- path(p) {
4817
- this.paths = Array.from(new Set([...this.paths, p]));
4818
- }
4819
- getPaths() {
4820
- return this.paths;
4821
- }
4822
- resolveConnection(connection) {
4823
- var _getInstance, _ref, _instance$connections;
4824
- const name = connection || this.connection || "default";
4825
- const instance = ((_getInstance = (_ref = this.resolver).getInstance) === null || _getInstance === void 0 ? void 0 : _getInstance.call(_ref)) ?? null;
4826
- if (!!!(instance === null || instance === void 0 || (_instance$connections = instance.connections) === null || _instance$connections === void 0 ? void 0 : _instance$connections[name])) this.resolver.autoLoad().catch(() => {
4827
- /** noop */
4828
- });
4829
- return this.resolver.fire(name);
4830
- }
4831
- setConnection(connection) {
4832
- this.connection = connection;
4833
- return this;
4834
- }
4835
- async getSeederFiles(paths) {
4836
- const files = [];
4837
- for (const p of paths) {
4838
- if (p.endsWith(".js") || p.endsWith(".ts")) {
4839
- files.push(p);
4840
- continue;
4841
- }
4842
- files.push(...await glob$1(p));
4843
- }
4844
- return files;
4845
- }
4846
- async resolvePath(filePath) {
4847
- try {
4848
- const mod = await import(filePath);
4849
- return new (mod.default ?? mod.Seeder)();
4850
- } catch {
4851
- return null;
4852
- }
4853
- }
4854
- async run(paths, connection) {
4855
- const files = await this.getSeederFiles(paths);
4856
- const conn = this.resolveConnection(connection);
4857
- for (const file of files) {
4858
- const seeder = await this.resolvePath(file);
4859
- if (seeder && typeof seeder.run === "function") await seeder.run(conn);
4860
- }
4861
- }
4862
- };
4863
- var runner_default = SeederRunner;
4864
-
4865
4865
  //#endregion
4866
4866
  //#region src/inspector/dialects/sqlite.ts
4867
4867
  function parseDefaultValue(value) {
@@ -5464,7 +5464,7 @@ var MigrationCreator = class {
5464
5464
 
5465
5465
  //#endregion
5466
5466
  //#region package.json
5467
- var version = "0.7.1";
5467
+ var version = "0.7.3";
5468
5468
 
5469
5469
  //#endregion
5470
5470
  //#region src/cli/cli.ts
@@ -653,9 +653,20 @@ const HasRelations = (Instance) => {
653
653
  return data;
654
654
  }
655
655
  guessBelongsToRelation() {
656
- var _e$stack;
657
- const frame = (_e$stack = (/* @__PURE__ */ new Error()).stack) === null || _e$stack === void 0 ? void 0 : _e$stack.split("\n")[2];
658
- return getRelationName(frame === null || frame === void 0 ? void 0 : frame.split(" ")[5]);
656
+ const e = /* @__PURE__ */ new Error();
657
+ const stack = e.stack || e.stackTrace;
658
+ if (!stack) return getRelationName("unknown");
659
+ const frames = stack.split("\n");
660
+ const frame = frames[2] || frames[1] || frames[0];
661
+ let functionName = "anonymous";
662
+ if (frame.includes("@")) functionName = frame.split("@")[0].trim();
663
+ else if (frame.includes("at ")) {
664
+ const match = frame.match(/at\s+([^(]+)\s*\(/);
665
+ functionName = match ? match[1].trim() : "anonymous";
666
+ if (functionName === null || functionName === void 0 ? void 0 : functionName.includes(".")) functionName = functionName.split(".").pop();
667
+ }
668
+ functionName = functionName === null || functionName === void 0 ? void 0 : functionName.replace(/^</, "").replace(/>$/, "").trim();
669
+ return getRelationName(functionName || "anonymous");
659
670
  }
660
671
  joiningTable(related, instance = null) {
661
672
  return [instance ? instance.joiningTableSegment() : snakeCase(related.name), this.joiningTableSegment()].sort().join("_").toLocaleLowerCase();
@@ -140,6 +140,7 @@ interface IModel {
140
140
  setAppends(appends: string[]): this;
141
141
  append(key: string | string[]): this;
142
142
  getRelation<T$1 extends Model$2>(relation: string): T$1 | ICollection<T$1> | null | undefined;
143
+ getRelation<T$1 extends Model$2, IsCollection extends boolean = false>(relation: string): IsCollection extends true ? ICollection<T$1> | undefined : T$1 | null | undefined;
143
144
  setRelation<T$1 extends Model$2>(relation: string, value: T$1 | ICollection<T$1> | null): this;
144
145
  unsetRelation(relation: string): this;
145
146
  relationLoaded(relation: string): boolean;
@@ -2176,7 +2177,10 @@ declare const BaseModel: (new (...args: any[]) => any) & {
2176
2177
  uniqueIds(): never[];
2177
2178
  setUniqueIds(): void;
2178
2179
  });
2179
- getRelation: <T$1 extends Model$2>(relation: string) => T$1 | ICollection<T$1> | null | undefined;
2180
+ getRelation: {
2181
+ <T$1 extends Model$2>(relation: string): T$1 | ICollection<T$1> | null | undefined;
2182
+ <T$1 extends Model$2, IsCollection extends boolean = false>(relation: string): IsCollection extends true ? ICollection<T$1> | undefined : T$1 | null | undefined;
2183
+ };
2180
2184
  setRelation: <T$1 extends Model$2>(relation: string, value: T$1 | ICollection<T$1> | null) => (new () => IModel) & IModel & {
2181
2185
  [x: string]: any;
2182
2186
  timestamps: boolean;
@@ -4900,10 +4904,15 @@ declare class Paginator<T$1 extends Model$1, K$1 extends IPaginatorParams = IPag
4900
4904
  }
4901
4905
  //#endregion
4902
4906
  //#region src/browser/index.d.ts
4903
- declare const make: (model: Model$1, data: TGeneric, options?: {
4904
- paginated: IPaginatorParams;
4905
- }) => any;
4906
- declare const makeCollection: (model: Model$1, data: TGeneric) => Collection<Model$1>;
4907
+ interface IMake {
4908
+ <T$1 extends Model$1>(model: T$1, data: TGeneric): T$1;
4909
+ <T$1 extends Model$1>(model: T$1, data: Array<TGeneric>): Collection<T$1>;
4910
+ <T$1 extends Model$1>(model: T$1, data: TGeneric, options: {
4911
+ paginated?: IPaginatorParams;
4912
+ }): Paginator<T$1>;
4913
+ }
4914
+ declare const make: IMake;
4915
+ declare const makeCollection: <T$1 extends Model$1>(model: T$1, data: TGeneric) => Collection<Model$1>;
4907
4916
  declare const isBrowser = true;
4908
4917
  declare const _default: {
4909
4918
  isBrowser: boolean;
@@ -4922,11 +4931,9 @@ declare const _default: {
4922
4931
  getIncrementing(): any;
4923
4932
  };
4924
4933
  } & TBase;
4925
- make: (model: Model$1, data: TGeneric, options?: {
4926
- paginated: IPaginatorParams;
4927
- }) => any;
4928
- makeCollection: (model: Model$1, data: TGeneric) => Collection<Model$1>;
4929
- makePaginator: (model: Model$1, data: TGeneric) => Paginator<Model$1, IPaginatorParams>;
4934
+ make: IMake;
4935
+ makeCollection: <T$1 extends Model$1>(model: T$1, data: TGeneric) => Collection<Model$1>;
4936
+ makePaginator: <T$1 extends Model$1>(model: T$1, data: TGeneric) => Paginator<T$1, IPaginatorParams>;
4930
4937
  };
4931
4938
  //#endregion
4932
4939
  export { Attribute, CastsAttributes, Collection, HasUniqueIds, InvalidArgumentError, Model$1 as Model, ModelNotFoundError, Paginator, Pivot, RelationNotFoundError, compose, _default as default, defineConfig, flatten, flattenDeep, getAttrMethod, getAttrName, getGetterMethod, getRelationMethod, getRelationName, getScopeMethod, getScopeName, getSetterMethod, isBrowser, kebabCase, make, makeCollection, now, snakeCase, tap };
@@ -630,9 +630,20 @@ const HasRelations = (Instance) => {
630
630
  return data;
631
631
  }
632
632
  guessBelongsToRelation() {
633
- var _e$stack;
634
- const frame = (_e$stack = (/* @__PURE__ */ new Error()).stack) === null || _e$stack === void 0 ? void 0 : _e$stack.split("\n")[2];
635
- return getRelationName(frame === null || frame === void 0 ? void 0 : frame.split(" ")[5]);
633
+ const e = /* @__PURE__ */ new Error();
634
+ const stack = e.stack || e.stackTrace;
635
+ if (!stack) return getRelationName("unknown");
636
+ const frames = stack.split("\n");
637
+ const frame = frames[2] || frames[1] || frames[0];
638
+ let functionName = "anonymous";
639
+ if (frame.includes("@")) functionName = frame.split("@")[0].trim();
640
+ else if (frame.includes("at ")) {
641
+ const match = frame.match(/at\s+([^(]+)\s*\(/);
642
+ functionName = match ? match[1].trim() : "anonymous";
643
+ if (functionName === null || functionName === void 0 ? void 0 : functionName.includes(".")) functionName = functionName.split(".").pop();
644
+ }
645
+ functionName = functionName === null || functionName === void 0 ? void 0 : functionName.replace(/^</, "").replace(/>$/, "").trim();
646
+ return getRelationName(functionName || "anonymous");
636
647
  }
637
648
  joiningTable(related, instance = null) {
638
649
  return [instance ? instance.joiningTableSegment() : snakeCase(related.name), this.joiningTableSegment()].sort().join("_").toLocaleLowerCase();
@@ -140,6 +140,7 @@ interface IModel {
140
140
  setAppends(appends: string[]): this;
141
141
  append(key: string | string[]): this;
142
142
  getRelation<T$1 extends Model$1>(relation: string): T$1 | ICollection<T$1> | null | undefined;
143
+ getRelation<T$1 extends Model$1, IsCollection extends boolean = false>(relation: string): IsCollection extends true ? ICollection<T$1> | undefined : T$1 | null | undefined;
143
144
  setRelation<T$1 extends Model$1>(relation: string, value: T$1 | ICollection<T$1> | null): this;
144
145
  unsetRelation(relation: string): this;
145
146
  relationLoaded(relation: string): boolean;
@@ -2041,7 +2042,10 @@ declare const BaseModel: (new (...args: any[]) => any) & {
2041
2042
  uniqueIds(): never[];
2042
2043
  setUniqueIds(): void;
2043
2044
  });
2044
- getRelation: <T$1 extends Model$1>(relation: string) => T$1 | ICollection<T$1> | null | undefined;
2045
+ getRelation: {
2046
+ <T$1 extends Model$1>(relation: string): T$1 | ICollection<T$1> | null | undefined;
2047
+ <T$1 extends Model$1, IsCollection extends boolean = false>(relation: string): IsCollection extends true ? ICollection<T$1> | undefined : T$1 | null | undefined;
2048
+ };
2045
2049
  setRelation: <T$1 extends Model$1>(relation: string, value: T$1 | ICollection<T$1> | null) => (new () => IModel) & IModel & {
2046
2050
  [x: string]: any;
2047
2051
  timestamps: boolean;