@orchestr-sh/orchestr 1.5.2 → 1.5.4

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.
Files changed (30) hide show
  1. package/README.md +119 -6
  2. package/dist/Database/Ensemble/Concerns/HasRelationships.d.ts +9 -0
  3. package/dist/Database/Ensemble/Concerns/HasRelationships.d.ts.map +1 -1
  4. package/dist/Database/Ensemble/Concerns/HasRelationships.js +32 -0
  5. package/dist/Database/Ensemble/Concerns/HasRelationships.js.map +1 -1
  6. package/dist/Database/Ensemble/EnsembleBuilder.d.ts +4 -0
  7. package/dist/Database/Ensemble/EnsembleBuilder.d.ts.map +1 -1
  8. package/dist/Database/Ensemble/EnsembleBuilder.js +10 -0
  9. package/dist/Database/Ensemble/EnsembleBuilder.js.map +1 -1
  10. package/dist/Database/Ensemble/Relations/BelongsTo.d.ts.map +1 -1
  11. package/dist/Database/Ensemble/Relations/BelongsTo.js +1 -0
  12. package/dist/Database/Ensemble/Relations/BelongsTo.js.map +1 -1
  13. package/dist/Database/Ensemble/Relations/BelongsToMany.d.ts +276 -0
  14. package/dist/Database/Ensemble/Relations/BelongsToMany.d.ts.map +1 -0
  15. package/dist/Database/Ensemble/Relations/BelongsToMany.js +541 -0
  16. package/dist/Database/Ensemble/Relations/BelongsToMany.js.map +1 -0
  17. package/dist/Database/Ensemble/Relations/HasMany.d.ts.map +1 -1
  18. package/dist/Database/Ensemble/Relations/HasMany.js +1 -0
  19. package/dist/Database/Ensemble/Relations/HasMany.js.map +1 -1
  20. package/dist/Database/Ensemble/Relations/HasOne.d.ts.map +1 -1
  21. package/dist/Database/Ensemble/Relations/HasOne.js +1 -0
  22. package/dist/Database/Ensemble/Relations/HasOne.js.map +1 -1
  23. package/dist/Database/Ensemble/Relations/Relation.d.ts.map +1 -1
  24. package/dist/Database/Ensemble/Relations/Relation.js +0 -1
  25. package/dist/Database/Ensemble/Relations/Relation.js.map +1 -1
  26. package/dist/Database/Ensemble/Relations/index.d.ts +1 -0
  27. package/dist/Database/Ensemble/Relations/index.d.ts.map +1 -1
  28. package/dist/Database/Ensemble/Relations/index.js +3 -1
  29. package/dist/Database/Ensemble/Relations/index.js.map +1 -1
  30. package/package.json +1 -1
@@ -0,0 +1,276 @@
1
+ /**
2
+ * BelongsToMany Relationship
3
+ *
4
+ * Represents a many-to-many relationship
5
+ */
6
+ import { Ensemble } from '../Ensemble';
7
+ import { EnsembleBuilder } from '../EnsembleBuilder';
8
+ import { EnsembleCollection } from '../EnsembleCollection';
9
+ import { Relation } from './Relation';
10
+ export declare class BelongsToMany<TRelated extends Ensemble, TParent extends Ensemble> extends Relation<TRelated, TParent> {
11
+ /**
12
+ * The intermediate table for the relation
13
+ */
14
+ protected table: string;
15
+ /**
16
+ * The foreign key of the parent model
17
+ */
18
+ protected foreignPivotKey: string;
19
+ /**
20
+ * The associated key of the relation
21
+ */
22
+ protected relatedPivotKey: string;
23
+ /**
24
+ * The parent key of the relationship
25
+ */
26
+ protected parentKey: string;
27
+ /**
28
+ * The related key of the relationship
29
+ */
30
+ protected relatedKey: string;
31
+ /**
32
+ * The name of the relationship
33
+ */
34
+ protected relationName: string;
35
+ /**
36
+ * The pivot table columns to retrieve
37
+ */
38
+ protected pivotColumns: string[];
39
+ /**
40
+ * Any pivot table restrictions
41
+ */
42
+ protected pivotWheres: Array<{
43
+ column: string;
44
+ operator?: string;
45
+ value?: any;
46
+ boolean: string;
47
+ }>;
48
+ /**
49
+ * The pivot table values to attach
50
+ */
51
+ protected pivotValues: Record<string, any>[];
52
+ /**
53
+ * Whether we are using timestamps on the pivot table
54
+ */
55
+ protected usingTimestamps: boolean;
56
+ /**
57
+ * The custom pivot table model
58
+ */
59
+ protected using?: any;
60
+ /**
61
+ * The name of the "created at" column
62
+ */
63
+ protected pivotCreatedAt?: string;
64
+ /**
65
+ * The name of the "updated at" column
66
+ */
67
+ protected pivotUpdatedAt?: string;
68
+ /**
69
+ * The name of the accessor to use for the pivot relationship
70
+ */
71
+ protected accessor: string;
72
+ /**
73
+ * Create a new belongs to many relationship instance
74
+ */
75
+ constructor(query: EnsembleBuilder<TRelated>, parent: TParent, table: string, foreignPivotKey: string, relatedPivotKey: string, parentKey: string, relatedKey: string, relationName?: string);
76
+ /**
77
+ * Set the base constraints on the relation query
78
+ */
79
+ addConstraints(): void;
80
+ /**
81
+ * Set the join clause for the relation query
82
+ */
83
+ protected performJoin(query?: EnsembleBuilder<TRelated>): void;
84
+ /**
85
+ * Set the where clause for the relation query
86
+ */
87
+ protected addWhereConstraints(): void;
88
+ /**
89
+ * Set the constraints for an eager load of the relation
90
+ */
91
+ addEagerConstraints(models: TParent[]): void;
92
+ /**
93
+ * Initialize the relation on a set of models
94
+ */
95
+ initRelation(models: TParent[], relation: string): TParent[];
96
+ /**
97
+ * Match the eagerly loaded results to their parents
98
+ */
99
+ match(models: TParent[], results: EnsembleCollection<TRelated>, relation: string): TParent[];
100
+ /**
101
+ * Build model dictionary keyed by the relation's foreign key
102
+ */
103
+ protected buildDictionary(results: EnsembleCollection<TRelated>): Record<any, TRelated[]>;
104
+ /**
105
+ * Get the results of the relationship
106
+ */
107
+ getResults(): Promise<TRelated[]>;
108
+ /**
109
+ * Execute the query and get the models
110
+ */
111
+ get(): Promise<TRelated[]>;
112
+ /**
113
+ * Get the select columns for the relation query
114
+ */
115
+ protected shouldSelect(columns?: string[]): string[];
116
+ /**
117
+ * Get the pivot columns for the relation
118
+ */
119
+ protected aliasedPivotColumns(): string[];
120
+ /**
121
+ * Hydrate the pivot relationship on the models
122
+ */
123
+ protected hydratePivotRelation(models: TRelated[]): void;
124
+ /**
125
+ * Migrate the pivot attributes from the model to a pivot model
126
+ */
127
+ protected migratePivotAttributes(model: TRelated): Record<string, any>;
128
+ /**
129
+ * Get the fully qualified foreign key for the relation
130
+ */
131
+ protected getQualifiedForeignPivotKeyName(): string;
132
+ /**
133
+ * Get the fully qualified "related key" for the relation
134
+ */
135
+ protected getQualifiedRelatedPivotKeyName(): string;
136
+ /**
137
+ * Get the fully qualified parent key name
138
+ */
139
+ protected getQualifiedParentKeyName(): string;
140
+ /**
141
+ * Get the fully qualified related key name
142
+ */
143
+ protected getQualifiedRelatedKeyName(): string;
144
+ /**
145
+ * Specify the pivot table columns to retrieve
146
+ */
147
+ withPivot(...columns: string[]): this;
148
+ /**
149
+ * Indicate that the pivot table has timestamps
150
+ */
151
+ withTimestamps(createdAt?: string, updatedAt?: string): this;
152
+ /**
153
+ * Set a where clause for the pivot table
154
+ */
155
+ wherePivot(column: string, operator?: any, value?: any): this;
156
+ /**
157
+ * Set a "where in" clause for the pivot table
158
+ */
159
+ wherePivotIn(column: string, values: any[]): this;
160
+ /**
161
+ * Set a "where not in" clause for the pivot table
162
+ */
163
+ wherePivotNotIn(column: string, values: any[]): this;
164
+ /**
165
+ * Set a "where null" clause for the pivot table
166
+ */
167
+ wherePivotNull(column: string): this;
168
+ /**
169
+ * Set a "where not null" clause for the pivot table
170
+ */
171
+ wherePivotNotNull(column: string): this;
172
+ /**
173
+ * Set an "or where" clause for the pivot table
174
+ */
175
+ orWherePivot(column: string, operator?: any, value?: any): this;
176
+ /**
177
+ * Attach models to the parent
178
+ */
179
+ attach(ids: any | any[], attributes?: Record<string, any>): Promise<void>;
180
+ /**
181
+ * Detach models from the parent
182
+ */
183
+ detach(ids?: any | any[]): Promise<number>;
184
+ /**
185
+ * Sync the intermediate tables with a list of IDs
186
+ */
187
+ sync(ids: any | any[] | Record<number | string, Record<string, any>>): Promise<{
188
+ attached: any[];
189
+ detached: any[];
190
+ updated: any[];
191
+ }>;
192
+ /**
193
+ * Sync without detaching
194
+ */
195
+ syncWithoutDetaching(ids: any | any[] | Record<number | string, Record<string, any>>): Promise<{
196
+ attached: any[];
197
+ updated: any[];
198
+ }>;
199
+ /**
200
+ * Toggle models from the parent
201
+ */
202
+ toggle(ids: any | any[]): Promise<{
203
+ attached: any[];
204
+ detached: any[];
205
+ }>;
206
+ /**
207
+ * Update an existing pivot record on the table
208
+ */
209
+ updateExistingPivot(id: any, attributes: Record<string, any>): Promise<number>;
210
+ /**
211
+ * Get the currently attached pivot IDs
212
+ */
213
+ protected getCurrentlyAttachedPivots(): Promise<any[]>;
214
+ /**
215
+ * Attach new records
216
+ */
217
+ protected attachNew(records: Array<{
218
+ id: any;
219
+ attributes: Record<string, any>;
220
+ }>, current: any[]): Promise<any[]>;
221
+ /**
222
+ * Update existing records
223
+ */
224
+ protected updateExisting(records: Array<{
225
+ id: any;
226
+ attributes: Record<string, any>;
227
+ }>, current: any[]): Promise<any[]>;
228
+ /**
229
+ * Format the records for attaching
230
+ */
231
+ protected formatAttachRecords(ids: any[], attributes: Record<string, any>): Record<string, any>[];
232
+ /**
233
+ * Format the sync records
234
+ */
235
+ protected formatRecordsList(ids: any[]): Array<{
236
+ id: any;
237
+ attributes: Record<string, any>;
238
+ }>;
239
+ /**
240
+ * Parse the IDs from the given value
241
+ */
242
+ protected parseIds(value: any): any[];
243
+ /**
244
+ * Get the name of the pivot accessor
245
+ */
246
+ getPivotAccessor(): string;
247
+ /**
248
+ * Set the name of the pivot accessor
249
+ */
250
+ as(accessor: string): this;
251
+ /**
252
+ * Get the pivot table name
253
+ */
254
+ getTable(): string;
255
+ /**
256
+ * Get the foreign pivot key name
257
+ */
258
+ getForeignPivotKeyName(): string;
259
+ /**
260
+ * Get the related pivot key name
261
+ */
262
+ getRelatedPivotKeyName(): string;
263
+ /**
264
+ * Get the parent key name
265
+ */
266
+ getParentKeyName(): string;
267
+ /**
268
+ * Get the related key name
269
+ */
270
+ getRelatedKeyName(): string;
271
+ /**
272
+ * Get the relationship name
273
+ */
274
+ getRelationName(): string;
275
+ }
276
+ //# sourceMappingURL=BelongsToMany.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BelongsToMany.d.ts","sourceRoot":"","sources":["../../../../src/Database/Ensemble/Relations/BelongsToMany.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CA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