@bunyad/orm 0.1.0-alpha.0 → 0.2.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/concerns.d.ts +2 -2
- package/dist/factory.d.ts +3 -3
- package/dist/model-events.d.ts +2 -2
- package/dist/model-events.js +1 -1
- package/dist/model-query.d.ts +55 -55
- package/dist/model-query.js +51 -51
- package/dist/model-strictness.d.ts +2 -3
- package/dist/model-strictness.js +2 -3
- package/dist/model.d.ts +106 -106
- package/dist/model.js +103 -103
- package/dist/orm-collection.d.ts +1 -1
- package/dist/orm-collection.js +1 -1
- package/dist/relations.d.ts +4 -4
- package/dist/relations.js +3 -3
- package/dist/scopes.d.ts +1 -2
- package/dist/scopes.js +1 -2
- package/package.json +3 -3
package/dist/model-query.js
CHANGED
|
@@ -147,7 +147,7 @@ export class ModelQuery {
|
|
|
147
147
|
this.#asRows = true;
|
|
148
148
|
return this;
|
|
149
149
|
}
|
|
150
|
-
/**
|
|
150
|
+
/** `withoutGlobalScopes`. */
|
|
151
151
|
withoutGlobalScopes(names) {
|
|
152
152
|
if (!names)
|
|
153
153
|
this.#withoutGlobalScopes = true;
|
|
@@ -161,30 +161,30 @@ export class ModelQuery {
|
|
|
161
161
|
}
|
|
162
162
|
return this;
|
|
163
163
|
}
|
|
164
|
-
/**
|
|
164
|
+
/** `withoutGlobalScope`. */
|
|
165
165
|
withoutGlobalScope(name) {
|
|
166
166
|
return this.withoutGlobalScopes([name]);
|
|
167
167
|
}
|
|
168
|
-
/**
|
|
168
|
+
/** `withTrashed()`. */
|
|
169
169
|
withTrashed() {
|
|
170
170
|
this.#withTrashed = true;
|
|
171
171
|
this.#onlyTrashed = false;
|
|
172
172
|
return this;
|
|
173
173
|
}
|
|
174
|
-
/**
|
|
174
|
+
/** `onlyTrashed()`. */
|
|
175
175
|
onlyTrashed() {
|
|
176
176
|
this.#onlyTrashed = true;
|
|
177
177
|
this.#withTrashed = false;
|
|
178
178
|
return this;
|
|
179
179
|
}
|
|
180
|
-
/**
|
|
180
|
+
/** `withoutTrashed()`. */
|
|
181
181
|
withoutTrashed() {
|
|
182
182
|
this.#withTrashed = false;
|
|
183
183
|
this.#onlyTrashed = false;
|
|
184
184
|
return this;
|
|
185
185
|
}
|
|
186
186
|
/**
|
|
187
|
-
*
|
|
187
|
+
* `Builder::withAttributes` — pending attrs for `create()`, and
|
|
188
188
|
* matching `where` conditions when `asConditions` is true (default).
|
|
189
189
|
*/
|
|
190
190
|
withAttributes(attributes, valueOrAsConditions, asConditions = true) {
|
|
@@ -209,7 +209,7 @@ export class ModelQuery {
|
|
|
209
209
|
}
|
|
210
210
|
return this;
|
|
211
211
|
}
|
|
212
|
-
/**
|
|
212
|
+
/** `withCasts` — merge query-time casts for hydration. */
|
|
213
213
|
withCasts(casts) {
|
|
214
214
|
this.#casts = mqMutObj(this.#casts);
|
|
215
215
|
Object.assign(this.#casts, casts);
|
|
@@ -219,15 +219,15 @@ export class ModelQuery {
|
|
|
219
219
|
}
|
|
220
220
|
return this;
|
|
221
221
|
}
|
|
222
|
-
/**
|
|
222
|
+
/** `has`. */
|
|
223
223
|
has(relation) {
|
|
224
224
|
return this.whereHas(relation);
|
|
225
225
|
}
|
|
226
|
-
/**
|
|
226
|
+
/** `doesntHave`. */
|
|
227
227
|
doesntHave(relation) {
|
|
228
228
|
return this.whereDoesntHave(relation);
|
|
229
229
|
}
|
|
230
|
-
/**
|
|
230
|
+
/** `whereHas`. */
|
|
231
231
|
whereHas(relation, callback) {
|
|
232
232
|
this.#simple = false;
|
|
233
233
|
// BelongsTo AND: expand to INNER JOIN once (same SQL as join()), avoid re-resolve per get().
|
|
@@ -240,23 +240,23 @@ export class ModelQuery {
|
|
|
240
240
|
}
|
|
241
241
|
return this.#pushHasConstraint(relation, false, false, callback, meta);
|
|
242
242
|
}
|
|
243
|
-
/**
|
|
243
|
+
/** `orWhereHas`. */
|
|
244
244
|
orWhereHas(relation, callback) {
|
|
245
245
|
this.#simple = false;
|
|
246
246
|
return this.#pushHasConstraint(relation, false, true, callback);
|
|
247
247
|
}
|
|
248
|
-
/**
|
|
248
|
+
/** `whereDoesntHave`. */
|
|
249
249
|
whereDoesntHave(relation, callback) {
|
|
250
250
|
this.#simple = false;
|
|
251
251
|
return this.#pushHasConstraint(relation, true, false, callback);
|
|
252
252
|
}
|
|
253
|
-
/**
|
|
253
|
+
/** `orWhereDoesntHave`. */
|
|
254
254
|
orWhereDoesntHave(relation, callback) {
|
|
255
255
|
this.#simple = false;
|
|
256
256
|
return this.#pushHasConstraint(relation, true, true, callback);
|
|
257
257
|
}
|
|
258
258
|
/**
|
|
259
|
-
*
|
|
259
|
+
* `whereRelation($relation, $column, $operator = null, $value = null)`.
|
|
260
260
|
* Convenience wrapper around `whereHas` with a column constraint.
|
|
261
261
|
*/
|
|
262
262
|
whereRelation(relation, column, opOrValue, value) {
|
|
@@ -291,7 +291,7 @@ export class ModelQuery {
|
|
|
291
291
|
q.where(column, String(opOrValue), value);
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
|
-
/**
|
|
294
|
+
/** `orWhereRelation`. */
|
|
295
295
|
orWhereRelation(relation, column, opOrValue, value) {
|
|
296
296
|
this.#simple = false;
|
|
297
297
|
const meta = resolveRelation(this.model, relation);
|
|
@@ -312,22 +312,22 @@ export class ModelQuery {
|
|
|
312
312
|
q.where(column, String(opOrValue), value);
|
|
313
313
|
});
|
|
314
314
|
}
|
|
315
|
-
/**
|
|
315
|
+
/** `orHas`. */
|
|
316
316
|
orHas(relation) {
|
|
317
317
|
return this.orWhereHas(relation);
|
|
318
318
|
}
|
|
319
|
-
/**
|
|
319
|
+
/** `orDoesntHave`. */
|
|
320
320
|
orDoesntHave(relation) {
|
|
321
321
|
return this.orWhereDoesntHave(relation);
|
|
322
322
|
}
|
|
323
323
|
/**
|
|
324
|
-
*
|
|
324
|
+
* `whereBelongsTo($model, $relationshipName = null)`.
|
|
325
325
|
* Constrains by the foreign key of a belongsTo relation.
|
|
326
326
|
*/
|
|
327
327
|
whereBelongsTo(related, relationName) {
|
|
328
328
|
return this.#belongsToConstraint(related, relationName, false);
|
|
329
329
|
}
|
|
330
|
-
/**
|
|
330
|
+
/** `orWhereBelongsTo`. */
|
|
331
331
|
orWhereBelongsTo(related, relationName) {
|
|
332
332
|
return this.#belongsToConstraint(related, relationName, true);
|
|
333
333
|
}
|
|
@@ -347,7 +347,7 @@ export class ModelQuery {
|
|
|
347
347
|
return this;
|
|
348
348
|
}
|
|
349
349
|
/**
|
|
350
|
-
*
|
|
350
|
+
* `whereMorphedTo($relation, $model)`.
|
|
351
351
|
*/
|
|
352
352
|
whereMorphedTo(relation, model) {
|
|
353
353
|
return this.#morphToConstraint(relation, model, false, false);
|
|
@@ -400,7 +400,7 @@ export class ModelQuery {
|
|
|
400
400
|
return this;
|
|
401
401
|
}
|
|
402
402
|
/**
|
|
403
|
-
*
|
|
403
|
+
* `whereMorphRelation($relation, $types, $column, …)` — simplified:
|
|
404
404
|
* `whereMorphRelation('commentable', TypeModel, column, op?, value?)`.
|
|
405
405
|
*/
|
|
406
406
|
whereMorphRelation(relation, type, column, opOrValue, value) {
|
|
@@ -420,7 +420,7 @@ export class ModelQuery {
|
|
|
420
420
|
});
|
|
421
421
|
}
|
|
422
422
|
/**
|
|
423
|
-
*
|
|
423
|
+
* `whereHasMorph($relation, $types, $callback?)`.
|
|
424
424
|
* `$types` may be a single model class or an array.
|
|
425
425
|
*/
|
|
426
426
|
whereHasMorph(relation, types, callback) {
|
|
@@ -466,14 +466,14 @@ export class ModelQuery {
|
|
|
466
466
|
return this;
|
|
467
467
|
}
|
|
468
468
|
/**
|
|
469
|
-
*
|
|
469
|
+
* `withWhereHas($relation, $callback?)` — whereHas + eager with same constraint.
|
|
470
470
|
*/
|
|
471
471
|
withWhereHas(relation, callback) {
|
|
472
472
|
this.whereHas(relation, callback);
|
|
473
473
|
this.with(relation);
|
|
474
474
|
return this;
|
|
475
475
|
}
|
|
476
|
-
/**
|
|
476
|
+
/** `whereAny` (forwarded to query builder). */
|
|
477
477
|
whereAny(columns, opOrValue, value) {
|
|
478
478
|
this.#simple = false;
|
|
479
479
|
(this.#builderExtras = mqMut(this.#builderExtras)).push((q) => q.whereAny(columns, opOrValue, value));
|
|
@@ -504,29 +504,29 @@ export class ModelQuery {
|
|
|
504
504
|
(this.#builderExtras = mqMut(this.#builderExtras)).push((q) => q.orWhereNone(columns, opOrValue, value));
|
|
505
505
|
return this;
|
|
506
506
|
}
|
|
507
|
-
/**
|
|
507
|
+
/** `whereKey($id)` / `whereKey([$ids])`. */
|
|
508
508
|
whereKey(id) {
|
|
509
509
|
const key = this.model.primaryKey;
|
|
510
510
|
if (Array.isArray(id))
|
|
511
511
|
return this.whereIn(key, id);
|
|
512
512
|
return this.where(key, id);
|
|
513
513
|
}
|
|
514
|
-
/**
|
|
514
|
+
/** `whereKeyNot`. */
|
|
515
515
|
whereKeyNot(id) {
|
|
516
516
|
const key = this.model.primaryKey;
|
|
517
517
|
if (Array.isArray(id))
|
|
518
518
|
return this.whereNotIn(key, id);
|
|
519
519
|
return this.where(key, "!=", id);
|
|
520
520
|
}
|
|
521
|
-
/**
|
|
521
|
+
/** `whereUuid($column, $uuid)`. */
|
|
522
522
|
whereUuid(column, value) {
|
|
523
523
|
return this.where(column, value);
|
|
524
524
|
}
|
|
525
|
-
/**
|
|
525
|
+
/** `whereUlid($column, $ulid)`. */
|
|
526
526
|
whereUlid(column, value) {
|
|
527
527
|
return this.where(column, value);
|
|
528
528
|
}
|
|
529
|
-
/**
|
|
529
|
+
/** `whereNot(closure)` nested group. */
|
|
530
530
|
whereNot(callback) {
|
|
531
531
|
this.#simple = false;
|
|
532
532
|
(this.#nestedGroups = mqMut(this.#nestedGroups)).push({ boolean: "and", not: true, callback });
|
|
@@ -544,18 +544,18 @@ export class ModelQuery {
|
|
|
544
544
|
this.where(column, String(opOrValue), value);
|
|
545
545
|
return this.first();
|
|
546
546
|
}
|
|
547
|
-
/**
|
|
547
|
+
/** `findMany`. */
|
|
548
548
|
findMany(ids) {
|
|
549
549
|
return this.whereIn(this.model.primaryKey, ids).#fetchModels();
|
|
550
550
|
}
|
|
551
|
-
/**
|
|
551
|
+
/** `findOr($id, $callback)`. */
|
|
552
552
|
async findOr(id, callback) {
|
|
553
553
|
const model = await this.where(this.model.primaryKey, id).first();
|
|
554
554
|
if (model)
|
|
555
555
|
return model;
|
|
556
556
|
return callback();
|
|
557
557
|
}
|
|
558
|
-
/**
|
|
558
|
+
/** `findOrNew`. */
|
|
559
559
|
async findOrNew(id) {
|
|
560
560
|
const model = await this.where(this.model.primaryKey, id).first();
|
|
561
561
|
if (model)
|
|
@@ -564,19 +564,19 @@ export class ModelQuery {
|
|
|
564
564
|
fresh[this.model.primaryKey] = id;
|
|
565
565
|
return fresh;
|
|
566
566
|
}
|
|
567
|
-
/**
|
|
567
|
+
/** `firstOr($callback)`. */
|
|
568
568
|
async firstOr(callback) {
|
|
569
569
|
const model = await this.first();
|
|
570
570
|
if (model)
|
|
571
571
|
return model;
|
|
572
572
|
return callback();
|
|
573
573
|
}
|
|
574
|
-
/**
|
|
574
|
+
/** `valueOrFail`. */
|
|
575
575
|
async valueOrFail(column) {
|
|
576
576
|
const model = await this.firstOrFail();
|
|
577
577
|
return model[column];
|
|
578
578
|
}
|
|
579
|
-
/**
|
|
579
|
+
/** `soleValue`. */
|
|
580
580
|
async soleValue(column) {
|
|
581
581
|
const model = await this.sole();
|
|
582
582
|
return model[column];
|
|
@@ -620,7 +620,7 @@ export class ModelQuery {
|
|
|
620
620
|
}
|
|
621
621
|
return this;
|
|
622
622
|
}
|
|
623
|
-
/**
|
|
623
|
+
/** `withSum($relation, $column)`. */
|
|
624
624
|
withSum(relation, column) {
|
|
625
625
|
const parsed = parseRelationAlias(relation);
|
|
626
626
|
const base = parsed.relation;
|
|
@@ -669,7 +669,7 @@ export class ModelQuery {
|
|
|
669
669
|
});
|
|
670
670
|
return this;
|
|
671
671
|
}
|
|
672
|
-
/**
|
|
672
|
+
/** `withExists($relation)`. */
|
|
673
673
|
withExists(...relations) {
|
|
674
674
|
for (const raw of relations.flat()) {
|
|
675
675
|
const parsed = parseRelationAlias(raw);
|
|
@@ -682,7 +682,7 @@ export class ModelQuery {
|
|
|
682
682
|
}
|
|
683
683
|
return this;
|
|
684
684
|
}
|
|
685
|
-
/**
|
|
685
|
+
/** `withAggregate($relation, $column, $function)`. */
|
|
686
686
|
withAggregate(relation, column, fn) {
|
|
687
687
|
const parsed = parseRelationAlias(relation);
|
|
688
688
|
const base = parsed.relation;
|
|
@@ -695,19 +695,19 @@ export class ModelQuery {
|
|
|
695
695
|
});
|
|
696
696
|
return this;
|
|
697
697
|
}
|
|
698
|
-
/**
|
|
698
|
+
/** `join` (hydrated models still from the base table). */
|
|
699
699
|
join(table, first, op, second) {
|
|
700
700
|
this.#simple = false;
|
|
701
701
|
(this.#joins = mqMut(this.#joins)).push({ type: "inner", table, first, op, second });
|
|
702
702
|
return this;
|
|
703
703
|
}
|
|
704
|
-
/**
|
|
704
|
+
/** `leftJoin`. */
|
|
705
705
|
leftJoin(table, first, op, second) {
|
|
706
706
|
this.#simple = false;
|
|
707
707
|
(this.#joins = mqMut(this.#joins)).push({ type: "left", table, first, op, second });
|
|
708
708
|
return this;
|
|
709
709
|
}
|
|
710
|
-
/**
|
|
710
|
+
/** `rightJoin`. */
|
|
711
711
|
rightJoin(table, first, op, second) {
|
|
712
712
|
this.#simple = false;
|
|
713
713
|
(this.#joins = mqMut(this.#joins)).push({ type: "right", table, first, op, second });
|
|
@@ -2592,7 +2592,7 @@ export class ModelQuery {
|
|
|
2592
2592
|
return model;
|
|
2593
2593
|
})();
|
|
2594
2594
|
}
|
|
2595
|
-
/**
|
|
2595
|
+
/** `firstOrFail`. */
|
|
2596
2596
|
async firstOrFail() {
|
|
2597
2597
|
const model = await this.first();
|
|
2598
2598
|
if (!model)
|
|
@@ -2862,7 +2862,7 @@ export class ModelQuery {
|
|
|
2862
2862
|
}
|
|
2863
2863
|
return models;
|
|
2864
2864
|
}
|
|
2865
|
-
/**
|
|
2865
|
+
/** `Builder::create` — insert on this query's connection. */
|
|
2866
2866
|
async create(attributes) {
|
|
2867
2867
|
const merged = { ...this.#pendingAttributes, ...attributes };
|
|
2868
2868
|
const useAttrs = filterFillable(this.model, merged);
|
|
@@ -2901,7 +2901,7 @@ export class ModelQuery {
|
|
|
2901
2901
|
}
|
|
2902
2902
|
return new Paginator(items, size, currentPage, options);
|
|
2903
2903
|
}
|
|
2904
|
-
/**
|
|
2904
|
+
/** `chunk($count, $callback)`. */
|
|
2905
2905
|
async chunk(count, callback) {
|
|
2906
2906
|
let page = 1;
|
|
2907
2907
|
for (;;) {
|
|
@@ -2922,7 +2922,7 @@ export class ModelQuery {
|
|
|
2922
2922
|
page += 1;
|
|
2923
2923
|
}
|
|
2924
2924
|
}
|
|
2925
|
-
/**
|
|
2925
|
+
/** `lazy($chunkSize)`. */
|
|
2926
2926
|
async *lazy(chunkSize = 1000) {
|
|
2927
2927
|
let page = 1;
|
|
2928
2928
|
const fireRetrieved = hasModelEventListeners(this.model, "retrieved");
|
|
@@ -2949,7 +2949,7 @@ export class ModelQuery {
|
|
|
2949
2949
|
page += 1;
|
|
2950
2950
|
}
|
|
2951
2951
|
}
|
|
2952
|
-
/**
|
|
2952
|
+
/** `chunkById`. */
|
|
2953
2953
|
async chunkById(count, callback, column) {
|
|
2954
2954
|
return this.#chunkById(count, callback, column ?? this.model.primaryKey, "asc");
|
|
2955
2955
|
}
|
|
@@ -2975,7 +2975,7 @@ export class ModelQuery {
|
|
|
2975
2975
|
return true;
|
|
2976
2976
|
}
|
|
2977
2977
|
}
|
|
2978
|
-
/**
|
|
2978
|
+
/** `lazyById`. */
|
|
2979
2979
|
async *lazyById(chunkSize = 1000, column) {
|
|
2980
2980
|
yield* this.#lazyById(chunkSize, column ?? this.model.primaryKey, "asc");
|
|
2981
2981
|
}
|
|
@@ -3007,7 +3007,7 @@ export class ModelQuery {
|
|
|
3007
3007
|
async decrement(column, amount = 1) {
|
|
3008
3008
|
await this.#buildQuery().decrement(column, amount);
|
|
3009
3009
|
}
|
|
3010
|
-
/**
|
|
3010
|
+
/** `cursorPaginate`. */
|
|
3011
3011
|
async cursorPaginate(perPage = 15, cursor = null, options = {}) {
|
|
3012
3012
|
const page = await this.#buildQuery().cursorPaginate(perPage, cursor, options);
|
|
3013
3013
|
const items = await this.#hydrateRows(page.items);
|
|
@@ -3016,7 +3016,7 @@ export class ModelQuery {
|
|
|
3016
3016
|
}
|
|
3017
3017
|
return new CursorPaginator(items, page.perPage, page.options);
|
|
3018
3018
|
}
|
|
3019
|
-
/**
|
|
3019
|
+
/** `Builder::count($columns = '*')` — honors `distinct()` for non-`*`. */
|
|
3020
3020
|
async count(column = "*") {
|
|
3021
3021
|
let countQ = this.#countQuery();
|
|
3022
3022
|
if (this.#distinct) {
|
|
@@ -3124,8 +3124,8 @@ export class ModelQuery {
|
|
|
3124
3124
|
return this.#baseTable().insert(finalRows);
|
|
3125
3125
|
}
|
|
3126
3126
|
/**
|
|
3127
|
-
*
|
|
3128
|
-
* When the model uses timestamps, stamps `created_at`/`updated_at`
|
|
3127
|
+
* `Builder::upsert` — insert or update on unique conflict.
|
|
3128
|
+
* When the model uses timestamps, stamps `created_at`/`updated_at`
|
|
3129
3129
|
* (row values win; `updated_at` is always included in the update column list).
|
|
3130
3130
|
*/
|
|
3131
3131
|
async upsert(values, uniqueBy, update = null) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @see Illuminate\Database\Eloquent\Model::preventLazyLoading
|
|
2
|
+
* Model strictness + touching guards.
|
|
4
3
|
* @see Model::preventSilentlyDiscardingAttributes
|
|
5
4
|
* @see Model::preventAccessingMissingAttributes
|
|
6
5
|
* @see Model::shouldBeStrict
|
|
@@ -29,7 +28,7 @@ export declare function shouldBeStrict(should?: boolean): void;
|
|
|
29
28
|
export declare function resetModelStrictnessForTests(): void;
|
|
30
29
|
export declare function isIgnoringTouch(modelClass?: object): boolean;
|
|
31
30
|
/**
|
|
32
|
-
* Run without touching parent timestamps (
|
|
31
|
+
* Run without touching parent timestamps (`Model::withoutTouching`).
|
|
33
32
|
* Pass model classes to limit the ignore set; omit to ignore all models.
|
|
34
33
|
*/
|
|
35
34
|
export declare function withoutTouching<T>(modelsOrCallback: object[] | (() => T | Promise<T>), callback?: () => T | Promise<T>): Promise<T>;
|
package/dist/model-strictness.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @see Illuminate\Database\Eloquent\Model::preventLazyLoading
|
|
2
|
+
* Model strictness + touching guards.
|
|
4
3
|
* @see Model::preventSilentlyDiscardingAttributes
|
|
5
4
|
* @see Model::preventAccessingMissingAttributes
|
|
6
5
|
* @see Model::shouldBeStrict
|
|
@@ -83,7 +82,7 @@ export function isIgnoringTouch(modelClass) {
|
|
|
83
82
|
return ignoringTouchModels.has(modelClass);
|
|
84
83
|
}
|
|
85
84
|
/**
|
|
86
|
-
* Run without touching parent timestamps (
|
|
85
|
+
* Run without touching parent timestamps (`Model::withoutTouching`).
|
|
87
86
|
* Pass model classes to limit the ignore set; omit to ignore all models.
|
|
88
87
|
*/
|
|
89
88
|
export async function withoutTouching(modelsOrCallback, callback) {
|