@getstrata/core 0.5.0 → 0.5.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.
@@ -28,10 +28,10 @@ declare class Model<TEntity extends object, PrimaryKey extends keyof TEntity & s
28
28
  get id(): TEntity[PrimaryKey];
29
29
  toObject(): TEntity;
30
30
  protected primaryKey(): PrimaryKey;
31
- protected static primaryKeyField(this: typeof Model): string;
32
- protected static hydrateAttributes<TEntity extends object>(this: typeof Model, attributes: TEntity): TEntity;
33
- protected static dehydrateAttributes(this: typeof Model, attributes: LoadedAttributes): LoadedAttributes;
34
- protected static fromRecord<TEntity extends object, PrimaryKey extends keyof TEntity & string>(this: typeof Model, record: TEntity, repository: BaseRepository<TEntity, PrimaryKey>, exists?: boolean): Model<TEntity, PrimaryKey>;
31
+ protected static primaryKeyField(this: object): string;
32
+ protected static hydrateAttributes<TEntity extends object>(this: object, attributes: TEntity): TEntity;
33
+ protected static dehydrateAttributes(this: object, attributes: LoadedAttributes): LoadedAttributes;
34
+ protected static fromRecord<TEntity extends object, PrimaryKey extends keyof TEntity & string>(this: object, record: TEntity, repository: BaseRepository<TEntity, PrimaryKey>, exists?: boolean): Model<TEntity, PrimaryKey>;
35
35
  static boot(): void;
36
36
  static addGlobalScope<TEntity extends object, PrimaryKey extends keyof TEntity & string>(this: object, _name: string, scope: GlobalScopeFn<TEntity, PrimaryKey>): void;
37
37
  static repository<TEntity extends object, PrimaryKey extends keyof TEntity & string>(this: object): BaseRepository<TEntity, PrimaryKey>;
@@ -1557,25 +1557,26 @@ class Model {
1557
1557
  throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
1558
1558
  }
1559
1559
  static primaryKeyField() {
1560
- return resolveModelRepository(Model).getTable().primaryKey;
1560
+ return resolveModelRepository(this).getTable().primaryKey;
1561
1561
  }
1562
1562
  static hydrateAttributes(attributes) {
1563
- const casts = Model.$casts ?? {};
1563
+ const casts = modelStatics(this).$casts ?? {};
1564
1564
  return applyCasts(attributes, casts, "hydrate");
1565
1565
  }
1566
1566
  static dehydrateAttributes(attributes) {
1567
- const casts = Model.$casts ?? {};
1567
+ const casts = modelStatics(this).$casts ?? {};
1568
1568
  return applyCasts(attributes, casts, "dehydrate");
1569
1569
  }
1570
1570
  static fromRecord(record, repository, exists = true) {
1571
- const hydrated = Model.hydrateAttributes(record);
1572
- return new Model(hydrated, repository, exists);
1571
+ const statics = modelStatics(this);
1572
+ const hydrated = statics.hydrateAttributes(record);
1573
+ return new statics(hydrated, repository, exists);
1573
1574
  }
1574
1575
  static boot() {}
1575
1576
  static addGlobalScope(_name, scope) {
1576
- ensureBooted(Model);
1577
- const existing = modelGlobalScopes.get(Model) ?? [];
1578
- modelGlobalScopes.set(Model, [
1577
+ ensureBooted(this);
1578
+ const existing = modelGlobalScopes.get(this) ?? [];
1579
+ modelGlobalScopes.set(this, [
1579
1580
  ...existing,
1580
1581
  scope
1581
1582
  ]);
@@ -1585,17 +1586,17 @@ class Model {
1585
1586
  }
1586
1587
  static query() {
1587
1588
  ensureBooted(this);
1588
- const repository = resolveModelRepository(Model);
1589
+ const repository = resolveModelRepository(this);
1589
1590
  let query = repository.query();
1590
- for (const scope of getGlobalScopes(Model)) {
1591
+ for (const scope of getGlobalScopes(this)) {
1591
1592
  query = scope(query);
1592
1593
  }
1593
1594
  return query;
1594
1595
  }
1595
1596
  static async create(attributes) {
1596
1597
  const statics = modelStatics(this);
1597
- ensureBooted(Model);
1598
- const repository = resolveModelRepository(Model);
1598
+ ensureBooted(this);
1599
+ const repository = resolveModelRepository(this);
1599
1600
  const table = repository.getTable();
1600
1601
  const timestamps = statics.$timestamps ?? true;
1601
1602
  const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
@@ -1606,22 +1607,22 @@ class Model {
1606
1607
  }
1607
1608
  static async find(id) {
1608
1609
  const statics = modelStatics(this);
1609
- const repository = resolveModelRepository(Model);
1610
- const primaryKey = statics.primaryKeyField();
1611
- const record = await Model.query.call(Model).where({ [primaryKey]: id }).first();
1610
+ const repository = resolveModelRepository(this);
1611
+ const primaryKey = repository.getTable().primaryKey;
1612
+ const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
1612
1613
  return record ? statics.fromRecord(record, repository, true) : null;
1613
1614
  }
1614
1615
  static async findOrFail(id, errorFactory) {
1615
- const model = await Model.find.call(Model, id);
1616
+ const model = await Model.find.call(this, id);
1616
1617
  if (model) {
1617
1618
  return model;
1618
1619
  }
1619
- throw errorFactory?.(id) ?? new NotFoundError(`${Model.name} ${String(id)} not found.`);
1620
+ throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
1620
1621
  }
1621
1622
  static async all(options = {}) {
1622
1623
  const statics = modelStatics(this);
1623
- const repository = resolveModelRepository(Model);
1624
- let query = Model.query.call(Model);
1624
+ const repository = resolveModelRepository(this);
1625
+ let query = Model.query.call(this);
1625
1626
  if (options.orderBy) {
1626
1627
  query = query.orderBy(options.orderBy);
1627
1628
  }
@@ -1633,8 +1634,8 @@ class Model {
1633
1634
  }
1634
1635
  static async firstWhere(where, options = {}) {
1635
1636
  const statics = modelStatics(this);
1636
- const repository = resolveModelRepository(Model);
1637
- let query = Model.query.call(Model).where(where);
1637
+ const repository = resolveModelRepository(this);
1638
+ let query = Model.query.call(this).where(where);
1638
1639
  if (options.orderBy) {
1639
1640
  query = query.orderBy(options.orderBy);
1640
1641
  }
@@ -1355,25 +1355,26 @@ class Model {
1355
1355
  throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
1356
1356
  }
1357
1357
  static primaryKeyField() {
1358
- return resolveModelRepository(Model).getTable().primaryKey;
1358
+ return resolveModelRepository(this).getTable().primaryKey;
1359
1359
  }
1360
1360
  static hydrateAttributes(attributes) {
1361
- const casts = Model.$casts ?? {};
1361
+ const casts = modelStatics(this).$casts ?? {};
1362
1362
  return applyCasts(attributes, casts, "hydrate");
1363
1363
  }
1364
1364
  static dehydrateAttributes(attributes) {
1365
- const casts = Model.$casts ?? {};
1365
+ const casts = modelStatics(this).$casts ?? {};
1366
1366
  return applyCasts(attributes, casts, "dehydrate");
1367
1367
  }
1368
1368
  static fromRecord(record, repository, exists = true) {
1369
- const hydrated = Model.hydrateAttributes(record);
1370
- return new Model(hydrated, repository, exists);
1369
+ const statics = modelStatics(this);
1370
+ const hydrated = statics.hydrateAttributes(record);
1371
+ return new statics(hydrated, repository, exists);
1371
1372
  }
1372
1373
  static boot() {}
1373
1374
  static addGlobalScope(_name, scope) {
1374
- ensureBooted(Model);
1375
- const existing = modelGlobalScopes.get(Model) ?? [];
1376
- modelGlobalScopes.set(Model, [
1375
+ ensureBooted(this);
1376
+ const existing = modelGlobalScopes.get(this) ?? [];
1377
+ modelGlobalScopes.set(this, [
1377
1378
  ...existing,
1378
1379
  scope
1379
1380
  ]);
@@ -1383,17 +1384,17 @@ class Model {
1383
1384
  }
1384
1385
  static query() {
1385
1386
  ensureBooted(this);
1386
- const repository = resolveModelRepository(Model);
1387
+ const repository = resolveModelRepository(this);
1387
1388
  let query = repository.query();
1388
- for (const scope of getGlobalScopes(Model)) {
1389
+ for (const scope of getGlobalScopes(this)) {
1389
1390
  query = scope(query);
1390
1391
  }
1391
1392
  return query;
1392
1393
  }
1393
1394
  static async create(attributes) {
1394
1395
  const statics = modelStatics(this);
1395
- ensureBooted(Model);
1396
- const repository = resolveModelRepository(Model);
1396
+ ensureBooted(this);
1397
+ const repository = resolveModelRepository(this);
1397
1398
  const table = repository.getTable();
1398
1399
  const timestamps = statics.$timestamps ?? true;
1399
1400
  const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
@@ -1404,22 +1405,22 @@ class Model {
1404
1405
  }
1405
1406
  static async find(id) {
1406
1407
  const statics = modelStatics(this);
1407
- const repository = resolveModelRepository(Model);
1408
- const primaryKey = statics.primaryKeyField();
1409
- const record = await Model.query.call(Model).where({ [primaryKey]: id }).first();
1408
+ const repository = resolveModelRepository(this);
1409
+ const primaryKey = repository.getTable().primaryKey;
1410
+ const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
1410
1411
  return record ? statics.fromRecord(record, repository, true) : null;
1411
1412
  }
1412
1413
  static async findOrFail(id, errorFactory) {
1413
- const model = await Model.find.call(Model, id);
1414
+ const model = await Model.find.call(this, id);
1414
1415
  if (model) {
1415
1416
  return model;
1416
1417
  }
1417
- throw errorFactory?.(id) ?? new NotFoundError(`${Model.name} ${String(id)} not found.`);
1418
+ throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
1418
1419
  }
1419
1420
  static async all(options = {}) {
1420
1421
  const statics = modelStatics(this);
1421
- const repository = resolveModelRepository(Model);
1422
- let query = Model.query.call(Model);
1422
+ const repository = resolveModelRepository(this);
1423
+ let query = Model.query.call(this);
1423
1424
  if (options.orderBy) {
1424
1425
  query = query.orderBy(options.orderBy);
1425
1426
  }
@@ -1431,8 +1432,8 @@ class Model {
1431
1432
  }
1432
1433
  static async firstWhere(where, options = {}) {
1433
1434
  const statics = modelStatics(this);
1434
- const repository = resolveModelRepository(Model);
1435
- let query = Model.query.call(Model).where(where);
1435
+ const repository = resolveModelRepository(this);
1436
+ let query = Model.query.call(this).where(where);
1436
1437
  if (options.orderBy) {
1437
1438
  query = query.orderBy(options.orderBy);
1438
1439
  }
@@ -1579,25 +1579,26 @@ class Model {
1579
1579
  throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
1580
1580
  }
1581
1581
  static primaryKeyField() {
1582
- return resolveModelRepository(Model).getTable().primaryKey;
1582
+ return resolveModelRepository(this).getTable().primaryKey;
1583
1583
  }
1584
1584
  static hydrateAttributes(attributes) {
1585
- const casts = Model.$casts ?? {};
1585
+ const casts = modelStatics(this).$casts ?? {};
1586
1586
  return applyCasts(attributes, casts, "hydrate");
1587
1587
  }
1588
1588
  static dehydrateAttributes(attributes) {
1589
- const casts = Model.$casts ?? {};
1589
+ const casts = modelStatics(this).$casts ?? {};
1590
1590
  return applyCasts(attributes, casts, "dehydrate");
1591
1591
  }
1592
1592
  static fromRecord(record, repository, exists = true) {
1593
- const hydrated = Model.hydrateAttributes(record);
1594
- return new Model(hydrated, repository, exists);
1593
+ const statics = modelStatics(this);
1594
+ const hydrated = statics.hydrateAttributes(record);
1595
+ return new statics(hydrated, repository, exists);
1595
1596
  }
1596
1597
  static boot() {}
1597
1598
  static addGlobalScope(_name, scope) {
1598
- ensureBooted(Model);
1599
- const existing = modelGlobalScopes.get(Model) ?? [];
1600
- modelGlobalScopes.set(Model, [
1599
+ ensureBooted(this);
1600
+ const existing = modelGlobalScopes.get(this) ?? [];
1601
+ modelGlobalScopes.set(this, [
1601
1602
  ...existing,
1602
1603
  scope
1603
1604
  ]);
@@ -1607,17 +1608,17 @@ class Model {
1607
1608
  }
1608
1609
  static query() {
1609
1610
  ensureBooted(this);
1610
- const repository = resolveModelRepository(Model);
1611
+ const repository = resolveModelRepository(this);
1611
1612
  let query = repository.query();
1612
- for (const scope of getGlobalScopes(Model)) {
1613
+ for (const scope of getGlobalScopes(this)) {
1613
1614
  query = scope(query);
1614
1615
  }
1615
1616
  return query;
1616
1617
  }
1617
1618
  static async create(attributes) {
1618
1619
  const statics = modelStatics(this);
1619
- ensureBooted(Model);
1620
- const repository = resolveModelRepository(Model);
1620
+ ensureBooted(this);
1621
+ const repository = resolveModelRepository(this);
1621
1622
  const table = repository.getTable();
1622
1623
  const timestamps = statics.$timestamps ?? true;
1623
1624
  const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
@@ -1628,22 +1629,22 @@ class Model {
1628
1629
  }
1629
1630
  static async find(id) {
1630
1631
  const statics = modelStatics(this);
1631
- const repository = resolveModelRepository(Model);
1632
- const primaryKey = statics.primaryKeyField();
1633
- const record = await Model.query.call(Model).where({ [primaryKey]: id }).first();
1632
+ const repository = resolveModelRepository(this);
1633
+ const primaryKey = repository.getTable().primaryKey;
1634
+ const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
1634
1635
  return record ? statics.fromRecord(record, repository, true) : null;
1635
1636
  }
1636
1637
  static async findOrFail(id, errorFactory) {
1637
- const model = await Model.find.call(Model, id);
1638
+ const model = await Model.find.call(this, id);
1638
1639
  if (model) {
1639
1640
  return model;
1640
1641
  }
1641
- throw errorFactory?.(id) ?? new NotFoundError(`${Model.name} ${String(id)} not found.`);
1642
+ throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
1642
1643
  }
1643
1644
  static async all(options = {}) {
1644
1645
  const statics = modelStatics(this);
1645
- const repository = resolveModelRepository(Model);
1646
- let query = Model.query.call(Model);
1646
+ const repository = resolveModelRepository(this);
1647
+ let query = Model.query.call(this);
1647
1648
  if (options.orderBy) {
1648
1649
  query = query.orderBy(options.orderBy);
1649
1650
  }
@@ -1655,8 +1656,8 @@ class Model {
1655
1656
  }
1656
1657
  static async firstWhere(where, options = {}) {
1657
1658
  const statics = modelStatics(this);
1658
- const repository = resolveModelRepository(Model);
1659
- let query = Model.query.call(Model).where(where);
1659
+ const repository = resolveModelRepository(this);
1660
+ let query = Model.query.call(this).where(where);
1660
1661
  if (options.orderBy) {
1661
1662
  query = query.orderBy(options.orderBy);
1662
1663
  }
@@ -1579,25 +1579,26 @@ class Model {
1579
1579
  throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
1580
1580
  }
1581
1581
  static primaryKeyField() {
1582
- return resolveModelRepository(Model).getTable().primaryKey;
1582
+ return resolveModelRepository(this).getTable().primaryKey;
1583
1583
  }
1584
1584
  static hydrateAttributes(attributes) {
1585
- const casts = Model.$casts ?? {};
1585
+ const casts = modelStatics(this).$casts ?? {};
1586
1586
  return applyCasts(attributes, casts, "hydrate");
1587
1587
  }
1588
1588
  static dehydrateAttributes(attributes) {
1589
- const casts = Model.$casts ?? {};
1589
+ const casts = modelStatics(this).$casts ?? {};
1590
1590
  return applyCasts(attributes, casts, "dehydrate");
1591
1591
  }
1592
1592
  static fromRecord(record, repository, exists = true) {
1593
- const hydrated = Model.hydrateAttributes(record);
1594
- return new Model(hydrated, repository, exists);
1593
+ const statics = modelStatics(this);
1594
+ const hydrated = statics.hydrateAttributes(record);
1595
+ return new statics(hydrated, repository, exists);
1595
1596
  }
1596
1597
  static boot() {}
1597
1598
  static addGlobalScope(_name, scope) {
1598
- ensureBooted(Model);
1599
- const existing = modelGlobalScopes.get(Model) ?? [];
1600
- modelGlobalScopes.set(Model, [
1599
+ ensureBooted(this);
1600
+ const existing = modelGlobalScopes.get(this) ?? [];
1601
+ modelGlobalScopes.set(this, [
1601
1602
  ...existing,
1602
1603
  scope
1603
1604
  ]);
@@ -1607,17 +1608,17 @@ class Model {
1607
1608
  }
1608
1609
  static query() {
1609
1610
  ensureBooted(this);
1610
- const repository = resolveModelRepository(Model);
1611
+ const repository = resolveModelRepository(this);
1611
1612
  let query = repository.query();
1612
- for (const scope of getGlobalScopes(Model)) {
1613
+ for (const scope of getGlobalScopes(this)) {
1613
1614
  query = scope(query);
1614
1615
  }
1615
1616
  return query;
1616
1617
  }
1617
1618
  static async create(attributes) {
1618
1619
  const statics = modelStatics(this);
1619
- ensureBooted(Model);
1620
- const repository = resolveModelRepository(Model);
1620
+ ensureBooted(this);
1621
+ const repository = resolveModelRepository(this);
1621
1622
  const table = repository.getTable();
1622
1623
  const timestamps = statics.$timestamps ?? true;
1623
1624
  const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
@@ -1628,22 +1629,22 @@ class Model {
1628
1629
  }
1629
1630
  static async find(id) {
1630
1631
  const statics = modelStatics(this);
1631
- const repository = resolveModelRepository(Model);
1632
- const primaryKey = statics.primaryKeyField();
1633
- const record = await Model.query.call(Model).where({ [primaryKey]: id }).first();
1632
+ const repository = resolveModelRepository(this);
1633
+ const primaryKey = repository.getTable().primaryKey;
1634
+ const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
1634
1635
  return record ? statics.fromRecord(record, repository, true) : null;
1635
1636
  }
1636
1637
  static async findOrFail(id, errorFactory) {
1637
- const model = await Model.find.call(Model, id);
1638
+ const model = await Model.find.call(this, id);
1638
1639
  if (model) {
1639
1640
  return model;
1640
1641
  }
1641
- throw errorFactory?.(id) ?? new NotFoundError(`${Model.name} ${String(id)} not found.`);
1642
+ throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
1642
1643
  }
1643
1644
  static async all(options = {}) {
1644
1645
  const statics = modelStatics(this);
1645
- const repository = resolveModelRepository(Model);
1646
- let query = Model.query.call(Model);
1646
+ const repository = resolveModelRepository(this);
1647
+ let query = Model.query.call(this);
1647
1648
  if (options.orderBy) {
1648
1649
  query = query.orderBy(options.orderBy);
1649
1650
  }
@@ -1655,8 +1656,8 @@ class Model {
1655
1656
  }
1656
1657
  static async firstWhere(where, options = {}) {
1657
1658
  const statics = modelStatics(this);
1658
- const repository = resolveModelRepository(Model);
1659
- let query = Model.query.call(Model).where(where);
1659
+ const repository = resolveModelRepository(this);
1660
+ let query = Model.query.call(this).where(where);
1660
1661
  if (options.orderBy) {
1661
1662
  query = query.orderBy(options.orderBy);
1662
1663
  }
@@ -1750,25 +1750,26 @@ class Model {
1750
1750
  throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
1751
1751
  }
1752
1752
  static primaryKeyField() {
1753
- return resolveModelRepository(Model).getTable().primaryKey;
1753
+ return resolveModelRepository(this).getTable().primaryKey;
1754
1754
  }
1755
1755
  static hydrateAttributes(attributes) {
1756
- const casts = Model.$casts ?? {};
1756
+ const casts = modelStatics(this).$casts ?? {};
1757
1757
  return applyCasts(attributes, casts, "hydrate");
1758
1758
  }
1759
1759
  static dehydrateAttributes(attributes) {
1760
- const casts = Model.$casts ?? {};
1760
+ const casts = modelStatics(this).$casts ?? {};
1761
1761
  return applyCasts(attributes, casts, "dehydrate");
1762
1762
  }
1763
1763
  static fromRecord(record, repository, exists = true) {
1764
- const hydrated = Model.hydrateAttributes(record);
1765
- return new Model(hydrated, repository, exists);
1764
+ const statics = modelStatics(this);
1765
+ const hydrated = statics.hydrateAttributes(record);
1766
+ return new statics(hydrated, repository, exists);
1766
1767
  }
1767
1768
  static boot() {}
1768
1769
  static addGlobalScope(_name, scope) {
1769
- ensureBooted(Model);
1770
- const existing = modelGlobalScopes.get(Model) ?? [];
1771
- modelGlobalScopes.set(Model, [
1770
+ ensureBooted(this);
1771
+ const existing = modelGlobalScopes.get(this) ?? [];
1772
+ modelGlobalScopes.set(this, [
1772
1773
  ...existing,
1773
1774
  scope
1774
1775
  ]);
@@ -1778,17 +1779,17 @@ class Model {
1778
1779
  }
1779
1780
  static query() {
1780
1781
  ensureBooted(this);
1781
- const repository = resolveModelRepository(Model);
1782
+ const repository = resolveModelRepository(this);
1782
1783
  let query = repository.query();
1783
- for (const scope of getGlobalScopes(Model)) {
1784
+ for (const scope of getGlobalScopes(this)) {
1784
1785
  query = scope(query);
1785
1786
  }
1786
1787
  return query;
1787
1788
  }
1788
1789
  static async create(attributes) {
1789
1790
  const statics = modelStatics(this);
1790
- ensureBooted(Model);
1791
- const repository = resolveModelRepository(Model);
1791
+ ensureBooted(this);
1792
+ const repository = resolveModelRepository(this);
1792
1793
  const table = repository.getTable();
1793
1794
  const timestamps = statics.$timestamps ?? true;
1794
1795
  const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
@@ -1799,22 +1800,22 @@ class Model {
1799
1800
  }
1800
1801
  static async find(id) {
1801
1802
  const statics = modelStatics(this);
1802
- const repository = resolveModelRepository(Model);
1803
- const primaryKey = statics.primaryKeyField();
1804
- const record = await Model.query.call(Model).where({ [primaryKey]: id }).first();
1803
+ const repository = resolveModelRepository(this);
1804
+ const primaryKey = repository.getTable().primaryKey;
1805
+ const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
1805
1806
  return record ? statics.fromRecord(record, repository, true) : null;
1806
1807
  }
1807
1808
  static async findOrFail(id, errorFactory) {
1808
- const model = await Model.find.call(Model, id);
1809
+ const model = await Model.find.call(this, id);
1809
1810
  if (model) {
1810
1811
  return model;
1811
1812
  }
1812
- throw errorFactory?.(id) ?? new NotFoundError(`${Model.name} ${String(id)} not found.`);
1813
+ throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
1813
1814
  }
1814
1815
  static async all(options = {}) {
1815
1816
  const statics = modelStatics(this);
1816
- const repository = resolveModelRepository(Model);
1817
- let query = Model.query.call(Model);
1817
+ const repository = resolveModelRepository(this);
1818
+ let query = Model.query.call(this);
1818
1819
  if (options.orderBy) {
1819
1820
  query = query.orderBy(options.orderBy);
1820
1821
  }
@@ -1826,8 +1827,8 @@ class Model {
1826
1827
  }
1827
1828
  static async firstWhere(where, options = {}) {
1828
1829
  const statics = modelStatics(this);
1829
- const repository = resolveModelRepository(Model);
1830
- let query = Model.query.call(Model).where(where);
1830
+ const repository = resolveModelRepository(this);
1831
+ let query = Model.query.call(this).where(where);
1831
1832
  if (options.orderBy) {
1832
1833
  query = query.orderBy(options.orderBy);
1833
1834
  }
@@ -1355,25 +1355,26 @@ class Model {
1355
1355
  throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
1356
1356
  }
1357
1357
  static primaryKeyField() {
1358
- return resolveModelRepository(Model).getTable().primaryKey;
1358
+ return resolveModelRepository(this).getTable().primaryKey;
1359
1359
  }
1360
1360
  static hydrateAttributes(attributes) {
1361
- const casts = Model.$casts ?? {};
1361
+ const casts = modelStatics(this).$casts ?? {};
1362
1362
  return applyCasts(attributes, casts, "hydrate");
1363
1363
  }
1364
1364
  static dehydrateAttributes(attributes) {
1365
- const casts = Model.$casts ?? {};
1365
+ const casts = modelStatics(this).$casts ?? {};
1366
1366
  return applyCasts(attributes, casts, "dehydrate");
1367
1367
  }
1368
1368
  static fromRecord(record, repository, exists = true) {
1369
- const hydrated = Model.hydrateAttributes(record);
1370
- return new Model(hydrated, repository, exists);
1369
+ const statics = modelStatics(this);
1370
+ const hydrated = statics.hydrateAttributes(record);
1371
+ return new statics(hydrated, repository, exists);
1371
1372
  }
1372
1373
  static boot() {}
1373
1374
  static addGlobalScope(_name, scope) {
1374
- ensureBooted(Model);
1375
- const existing = modelGlobalScopes.get(Model) ?? [];
1376
- modelGlobalScopes.set(Model, [
1375
+ ensureBooted(this);
1376
+ const existing = modelGlobalScopes.get(this) ?? [];
1377
+ modelGlobalScopes.set(this, [
1377
1378
  ...existing,
1378
1379
  scope
1379
1380
  ]);
@@ -1383,17 +1384,17 @@ class Model {
1383
1384
  }
1384
1385
  static query() {
1385
1386
  ensureBooted(this);
1386
- const repository = resolveModelRepository(Model);
1387
+ const repository = resolveModelRepository(this);
1387
1388
  let query = repository.query();
1388
- for (const scope of getGlobalScopes(Model)) {
1389
+ for (const scope of getGlobalScopes(this)) {
1389
1390
  query = scope(query);
1390
1391
  }
1391
1392
  return query;
1392
1393
  }
1393
1394
  static async create(attributes) {
1394
1395
  const statics = modelStatics(this);
1395
- ensureBooted(Model);
1396
- const repository = resolveModelRepository(Model);
1396
+ ensureBooted(this);
1397
+ const repository = resolveModelRepository(this);
1397
1398
  const table = repository.getTable();
1398
1399
  const timestamps = statics.$timestamps ?? true;
1399
1400
  const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
@@ -1404,22 +1405,22 @@ class Model {
1404
1405
  }
1405
1406
  static async find(id) {
1406
1407
  const statics = modelStatics(this);
1407
- const repository = resolveModelRepository(Model);
1408
- const primaryKey = statics.primaryKeyField();
1409
- const record = await Model.query.call(Model).where({ [primaryKey]: id }).first();
1408
+ const repository = resolveModelRepository(this);
1409
+ const primaryKey = repository.getTable().primaryKey;
1410
+ const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
1410
1411
  return record ? statics.fromRecord(record, repository, true) : null;
1411
1412
  }
1412
1413
  static async findOrFail(id, errorFactory) {
1413
- const model = await Model.find.call(Model, id);
1414
+ const model = await Model.find.call(this, id);
1414
1415
  if (model) {
1415
1416
  return model;
1416
1417
  }
1417
- throw errorFactory?.(id) ?? new NotFoundError(`${Model.name} ${String(id)} not found.`);
1418
+ throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
1418
1419
  }
1419
1420
  static async all(options = {}) {
1420
1421
  const statics = modelStatics(this);
1421
- const repository = resolveModelRepository(Model);
1422
- let query = Model.query.call(Model);
1422
+ const repository = resolveModelRepository(this);
1423
+ let query = Model.query.call(this);
1423
1424
  if (options.orderBy) {
1424
1425
  query = query.orderBy(options.orderBy);
1425
1426
  }
@@ -1431,8 +1432,8 @@ class Model {
1431
1432
  }
1432
1433
  static async firstWhere(where, options = {}) {
1433
1434
  const statics = modelStatics(this);
1434
- const repository = resolveModelRepository(Model);
1435
- let query = Model.query.call(Model).where(where);
1435
+ const repository = resolveModelRepository(this);
1436
+ let query = Model.query.call(this).where(where);
1436
1437
  if (options.orderBy) {
1437
1438
  query = query.orderBy(options.orderBy);
1438
1439
  }
@@ -1760,25 +1760,26 @@ class Model {
1760
1760
  throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
1761
1761
  }
1762
1762
  static primaryKeyField() {
1763
- return resolveModelRepository(Model).getTable().primaryKey;
1763
+ return resolveModelRepository(this).getTable().primaryKey;
1764
1764
  }
1765
1765
  static hydrateAttributes(attributes) {
1766
- const casts = Model.$casts ?? {};
1766
+ const casts = modelStatics(this).$casts ?? {};
1767
1767
  return applyCasts(attributes, casts, "hydrate");
1768
1768
  }
1769
1769
  static dehydrateAttributes(attributes) {
1770
- const casts = Model.$casts ?? {};
1770
+ const casts = modelStatics(this).$casts ?? {};
1771
1771
  return applyCasts(attributes, casts, "dehydrate");
1772
1772
  }
1773
1773
  static fromRecord(record, repository, exists = true) {
1774
- const hydrated = Model.hydrateAttributes(record);
1775
- return new Model(hydrated, repository, exists);
1774
+ const statics = modelStatics(this);
1775
+ const hydrated = statics.hydrateAttributes(record);
1776
+ return new statics(hydrated, repository, exists);
1776
1777
  }
1777
1778
  static boot() {}
1778
1779
  static addGlobalScope(_name, scope) {
1779
- ensureBooted(Model);
1780
- const existing = modelGlobalScopes.get(Model) ?? [];
1781
- modelGlobalScopes.set(Model, [
1780
+ ensureBooted(this);
1781
+ const existing = modelGlobalScopes.get(this) ?? [];
1782
+ modelGlobalScopes.set(this, [
1782
1783
  ...existing,
1783
1784
  scope
1784
1785
  ]);
@@ -1788,17 +1789,17 @@ class Model {
1788
1789
  }
1789
1790
  static query() {
1790
1791
  ensureBooted(this);
1791
- const repository = resolveModelRepository(Model);
1792
+ const repository = resolveModelRepository(this);
1792
1793
  let query = repository.query();
1793
- for (const scope of getGlobalScopes(Model)) {
1794
+ for (const scope of getGlobalScopes(this)) {
1794
1795
  query = scope(query);
1795
1796
  }
1796
1797
  return query;
1797
1798
  }
1798
1799
  static async create(attributes) {
1799
1800
  const statics = modelStatics(this);
1800
- ensureBooted(Model);
1801
- const repository = resolveModelRepository(Model);
1801
+ ensureBooted(this);
1802
+ const repository = resolveModelRepository(this);
1802
1803
  const table = repository.getTable();
1803
1804
  const timestamps = statics.$timestamps ?? true;
1804
1805
  const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
@@ -1809,22 +1810,22 @@ class Model {
1809
1810
  }
1810
1811
  static async find(id) {
1811
1812
  const statics = modelStatics(this);
1812
- const repository = resolveModelRepository(Model);
1813
- const primaryKey = statics.primaryKeyField();
1814
- const record = await Model.query.call(Model).where({ [primaryKey]: id }).first();
1813
+ const repository = resolveModelRepository(this);
1814
+ const primaryKey = repository.getTable().primaryKey;
1815
+ const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
1815
1816
  return record ? statics.fromRecord(record, repository, true) : null;
1816
1817
  }
1817
1818
  static async findOrFail(id, errorFactory) {
1818
- const model = await Model.find.call(Model, id);
1819
+ const model = await Model.find.call(this, id);
1819
1820
  if (model) {
1820
1821
  return model;
1821
1822
  }
1822
- throw errorFactory?.(id) ?? new NotFoundError(`${Model.name} ${String(id)} not found.`);
1823
+ throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
1823
1824
  }
1824
1825
  static async all(options = {}) {
1825
1826
  const statics = modelStatics(this);
1826
- const repository = resolveModelRepository(Model);
1827
- let query = Model.query.call(Model);
1827
+ const repository = resolveModelRepository(this);
1828
+ let query = Model.query.call(this);
1828
1829
  if (options.orderBy) {
1829
1830
  query = query.orderBy(options.orderBy);
1830
1831
  }
@@ -1836,8 +1837,8 @@ class Model {
1836
1837
  }
1837
1838
  static async firstWhere(where, options = {}) {
1838
1839
  const statics = modelStatics(this);
1839
- const repository = resolveModelRepository(Model);
1840
- let query = Model.query.call(Model).where(where);
1840
+ const repository = resolveModelRepository(this);
1841
+ let query = Model.query.call(this).where(where);
1841
1842
  if (options.orderBy) {
1842
1843
  query = query.orderBy(options.orderBy);
1843
1844
  }
@@ -1,8 +1,8 @@
1
1
  // @bun
2
2
  // ../../src/core/storage/storage.ts
3
- var {S3Client } = globalThis.Bun;
4
3
  import { mkdir, readFile, unlink, writeFile } from "fs/promises";
5
4
  import { dirname, join } from "path";
5
+ var {S3Client } = globalThis.Bun;
6
6
 
7
7
  class LocalStorageDriver {
8
8
  rootDirectory;
@@ -1564,25 +1564,26 @@ class Model {
1564
1564
  throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
1565
1565
  }
1566
1566
  static primaryKeyField() {
1567
- return resolveModelRepository(Model).getTable().primaryKey;
1567
+ return resolveModelRepository(this).getTable().primaryKey;
1568
1568
  }
1569
1569
  static hydrateAttributes(attributes) {
1570
- const casts = Model.$casts ?? {};
1570
+ const casts = modelStatics(this).$casts ?? {};
1571
1571
  return applyCasts(attributes, casts, "hydrate");
1572
1572
  }
1573
1573
  static dehydrateAttributes(attributes) {
1574
- const casts = Model.$casts ?? {};
1574
+ const casts = modelStatics(this).$casts ?? {};
1575
1575
  return applyCasts(attributes, casts, "dehydrate");
1576
1576
  }
1577
1577
  static fromRecord(record, repository, exists = true) {
1578
- const hydrated = Model.hydrateAttributes(record);
1579
- return new Model(hydrated, repository, exists);
1578
+ const statics = modelStatics(this);
1579
+ const hydrated = statics.hydrateAttributes(record);
1580
+ return new statics(hydrated, repository, exists);
1580
1581
  }
1581
1582
  static boot() {}
1582
1583
  static addGlobalScope(_name, scope) {
1583
- ensureBooted(Model);
1584
- const existing = modelGlobalScopes.get(Model) ?? [];
1585
- modelGlobalScopes.set(Model, [
1584
+ ensureBooted(this);
1585
+ const existing = modelGlobalScopes.get(this) ?? [];
1586
+ modelGlobalScopes.set(this, [
1586
1587
  ...existing,
1587
1588
  scope
1588
1589
  ]);
@@ -1592,17 +1593,17 @@ class Model {
1592
1593
  }
1593
1594
  static query() {
1594
1595
  ensureBooted(this);
1595
- const repository = resolveModelRepository(Model);
1596
+ const repository = resolveModelRepository(this);
1596
1597
  let query = repository.query();
1597
- for (const scope of getGlobalScopes(Model)) {
1598
+ for (const scope of getGlobalScopes(this)) {
1598
1599
  query = scope(query);
1599
1600
  }
1600
1601
  return query;
1601
1602
  }
1602
1603
  static async create(attributes) {
1603
1604
  const statics = modelStatics(this);
1604
- ensureBooted(Model);
1605
- const repository = resolveModelRepository(Model);
1605
+ ensureBooted(this);
1606
+ const repository = resolveModelRepository(this);
1606
1607
  const table = repository.getTable();
1607
1608
  const timestamps = statics.$timestamps ?? true;
1608
1609
  const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
@@ -1613,22 +1614,22 @@ class Model {
1613
1614
  }
1614
1615
  static async find(id) {
1615
1616
  const statics = modelStatics(this);
1616
- const repository = resolveModelRepository(Model);
1617
- const primaryKey = statics.primaryKeyField();
1618
- const record = await Model.query.call(Model).where({ [primaryKey]: id }).first();
1617
+ const repository = resolveModelRepository(this);
1618
+ const primaryKey = repository.getTable().primaryKey;
1619
+ const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
1619
1620
  return record ? statics.fromRecord(record, repository, true) : null;
1620
1621
  }
1621
1622
  static async findOrFail(id, errorFactory) {
1622
- const model = await Model.find.call(Model, id);
1623
+ const model = await Model.find.call(this, id);
1623
1624
  if (model) {
1624
1625
  return model;
1625
1626
  }
1626
- throw errorFactory?.(id) ?? new NotFoundError(`${Model.name} ${String(id)} not found.`);
1627
+ throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
1627
1628
  }
1628
1629
  static async all(options = {}) {
1629
1630
  const statics = modelStatics(this);
1630
- const repository = resolveModelRepository(Model);
1631
- let query = Model.query.call(Model);
1631
+ const repository = resolveModelRepository(this);
1632
+ let query = Model.query.call(this);
1632
1633
  if (options.orderBy) {
1633
1634
  query = query.orderBy(options.orderBy);
1634
1635
  }
@@ -1640,8 +1641,8 @@ class Model {
1640
1641
  }
1641
1642
  static async firstWhere(where, options = {}) {
1642
1643
  const statics = modelStatics(this);
1643
- const repository = resolveModelRepository(Model);
1644
- let query = Model.query.call(Model).where(where);
1644
+ const repository = resolveModelRepository(this);
1645
+ let query = Model.query.call(this).where(where);
1645
1646
  if (options.orderBy) {
1646
1647
  query = query.orderBy(options.orderBy);
1647
1648
  }
package/dist/index.js CHANGED
@@ -1665,25 +1665,26 @@ class Model {
1665
1665
  throw new Error(`${this.constructor.name}.primaryKey() is not implemented.`);
1666
1666
  }
1667
1667
  static primaryKeyField() {
1668
- return resolveModelRepository(Model).getTable().primaryKey;
1668
+ return resolveModelRepository(this).getTable().primaryKey;
1669
1669
  }
1670
1670
  static hydrateAttributes(attributes) {
1671
- const casts = Model.$casts ?? {};
1671
+ const casts = modelStatics(this).$casts ?? {};
1672
1672
  return applyCasts(attributes, casts, "hydrate");
1673
1673
  }
1674
1674
  static dehydrateAttributes(attributes) {
1675
- const casts = Model.$casts ?? {};
1675
+ const casts = modelStatics(this).$casts ?? {};
1676
1676
  return applyCasts(attributes, casts, "dehydrate");
1677
1677
  }
1678
1678
  static fromRecord(record, repository, exists = true) {
1679
- const hydrated = Model.hydrateAttributes(record);
1680
- return new Model(hydrated, repository, exists);
1679
+ const statics = modelStatics(this);
1680
+ const hydrated = statics.hydrateAttributes(record);
1681
+ return new statics(hydrated, repository, exists);
1681
1682
  }
1682
1683
  static boot() {}
1683
1684
  static addGlobalScope(_name, scope) {
1684
- ensureBooted(Model);
1685
- const existing = modelGlobalScopes.get(Model) ?? [];
1686
- modelGlobalScopes.set(Model, [
1685
+ ensureBooted(this);
1686
+ const existing = modelGlobalScopes.get(this) ?? [];
1687
+ modelGlobalScopes.set(this, [
1687
1688
  ...existing,
1688
1689
  scope
1689
1690
  ]);
@@ -1693,17 +1694,17 @@ class Model {
1693
1694
  }
1694
1695
  static query() {
1695
1696
  ensureBooted(this);
1696
- const repository = resolveModelRepository(Model);
1697
+ const repository = resolveModelRepository(this);
1697
1698
  let query = repository.query();
1698
- for (const scope of getGlobalScopes(Model)) {
1699
+ for (const scope of getGlobalScopes(this)) {
1699
1700
  query = scope(query);
1700
1701
  }
1701
1702
  return query;
1702
1703
  }
1703
1704
  static async create(attributes) {
1704
1705
  const statics = modelStatics(this);
1705
- ensureBooted(Model);
1706
- const repository = resolveModelRepository(Model);
1706
+ ensureBooted(this);
1707
+ const repository = resolveModelRepository(this);
1707
1708
  const table = repository.getTable();
1708
1709
  const timestamps = statics.$timestamps ?? true;
1709
1710
  const assignable = filterMassAssignable(statics.$fillable, statics.$guarded, attributes);
@@ -1714,22 +1715,22 @@ class Model {
1714
1715
  }
1715
1716
  static async find(id) {
1716
1717
  const statics = modelStatics(this);
1717
- const repository = resolveModelRepository(Model);
1718
- const primaryKey = statics.primaryKeyField();
1719
- const record = await Model.query.call(Model).where({ [primaryKey]: id }).first();
1718
+ const repository = resolveModelRepository(this);
1719
+ const primaryKey = repository.getTable().primaryKey;
1720
+ const record = await Model.query.call(this).where({ [primaryKey]: id }).first();
1720
1721
  return record ? statics.fromRecord(record, repository, true) : null;
1721
1722
  }
1722
1723
  static async findOrFail(id, errorFactory) {
1723
- const model = await Model.find.call(Model, id);
1724
+ const model = await Model.find.call(this, id);
1724
1725
  if (model) {
1725
1726
  return model;
1726
1727
  }
1727
- throw errorFactory?.(id) ?? new NotFoundError(`${Model.name} ${String(id)} not found.`);
1728
+ throw errorFactory?.(id) ?? new NotFoundError(`${this.name} ${String(id)} not found.`);
1728
1729
  }
1729
1730
  static async all(options = {}) {
1730
1731
  const statics = modelStatics(this);
1731
- const repository = resolveModelRepository(Model);
1732
- let query = Model.query.call(Model);
1732
+ const repository = resolveModelRepository(this);
1733
+ let query = Model.query.call(this);
1733
1734
  if (options.orderBy) {
1734
1735
  query = query.orderBy(options.orderBy);
1735
1736
  }
@@ -1741,8 +1742,8 @@ class Model {
1741
1742
  }
1742
1743
  static async firstWhere(where, options = {}) {
1743
1744
  const statics = modelStatics(this);
1744
- const repository = resolveModelRepository(Model);
1745
- let query = Model.query.call(Model).where(where);
1745
+ const repository = resolveModelRepository(this);
1746
+ let query = Model.query.call(this).where(where);
1746
1747
  if (options.orderBy) {
1747
1748
  query = query.orderBy(options.orderBy);
1748
1749
  }
@@ -2758,9 +2759,9 @@ function mailer() {
2758
2759
  }
2759
2760
 
2760
2761
  // ../../src/core/storage/storage.ts
2761
- var {S3Client } = globalThis.Bun;
2762
2762
  import { mkdir, readFile, unlink, writeFile } from "fs/promises";
2763
2763
  import { dirname, join as join3 } from "path";
2764
+ var {S3Client } = globalThis.Bun;
2764
2765
 
2765
2766
  class LocalStorageDriver {
2766
2767
  rootDirectory;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getstrata/core",
3
- "version": "0.5.0",
3
+ "version": "0.5.3",
4
4
  "description": "Strata — Laravel-inspired Bun framework public API",
5
5
  "type": "module",
6
6
  "license": "MIT",