@relations-dil/relations 0.1.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/LICENSE +21 -0
- package/README.md +824 -0
- package/dist/dynamic.d.ts +122 -0
- package/dist/dynamic.js +164 -0
- package/dist/errors.d.ts +31 -0
- package/dist/errors.js +50 -0
- package/dist/field.d.ts +157 -0
- package/dist/field.js +660 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +75 -0
- package/dist/kinds.d.ts +99 -0
- package/dist/kinds.js +169 -0
- package/dist/migrations.d.ts +62 -0
- package/dist/migrations.js +293 -0
- package/dist/mock.d.ts +88 -0
- package/dist/mock.js +511 -0
- package/dist/model.d.ts +277 -0
- package/dist/model.js +1159 -0
- package/dist/overscore.d.ts +66 -0
- package/dist/overscore.js +226 -0
- package/dist/record.d.ts +58 -0
- package/dist/record.js +246 -0
- package/dist/registry.d.ts +24 -0
- package/dist/registry.js +27 -0
- package/dist/relation.d.ts +114 -0
- package/dist/relation.js +145 -0
- package/dist/source.d.ts +147 -0
- package/dist/source.js +409 -0
- package/dist/titles.d.ts +43 -0
- package/dist/titles.js +115 -0
- package/dist/typed.d.ts +99 -0
- package/dist/typed.js +44 -0
- package/dist/util.d.ts +16 -0
- package/dist/util.js +117 -0
- package/package.json +68 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Relations between models.
|
|
3
|
+
*
|
|
4
|
+
* Relations are declared outside the models, not inside them, so a model stays a plain
|
|
5
|
+
* description of its own shape and can be reused in a service that doesn't know about
|
|
6
|
+
* the other side.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* new OneToMany(Unit, Test) // unit.test, test.unit
|
|
10
|
+
* new OneToOne(Unit, Detail) // unit.detail, detail.unit
|
|
11
|
+
* new ManyToMany(Sister, Brother, Tie)
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import type { ModelClass, ModelIdentity } from './model.js';
|
|
15
|
+
/** Base for every relation, holding the convention used to find the joining field. */
|
|
16
|
+
export declare class Relation {
|
|
17
|
+
/** Whether the two sides can share an id field name. */
|
|
18
|
+
static SAME: boolean | null;
|
|
19
|
+
/**
|
|
20
|
+
* Work out which field on `relative` points at `model`, by convention:
|
|
21
|
+
* `<model>_id`, then `<model>_<model id field>`, then the model's own id field name.
|
|
22
|
+
*/
|
|
23
|
+
static relativeField(model: ModelIdentity, relative: ModelIdentity, same: boolean | null): string;
|
|
24
|
+
}
|
|
25
|
+
/** What you can spell out about a one-to-* relation instead of letting it be inferred. */
|
|
26
|
+
export interface OneToOptions {
|
|
27
|
+
/** Attribute on the parent that reaches the children. Defaults to the child's name. */
|
|
28
|
+
parentChildAttr?: string;
|
|
29
|
+
/** Attribute on the child that reaches the parent. Defaults to the parent's name. */
|
|
30
|
+
childParentAttr?: string;
|
|
31
|
+
/** Field on the parent the child points at. Defaults to the parent's id. */
|
|
32
|
+
parentId?: string | number;
|
|
33
|
+
/** Field on the child that points at the parent. Inferred by convention. */
|
|
34
|
+
childParentRef?: string | number;
|
|
35
|
+
}
|
|
36
|
+
/** One parent record to one or many child records. */
|
|
37
|
+
export declare class OneTo extends Relation {
|
|
38
|
+
/** Whether the child side holds one record or many. */
|
|
39
|
+
static MODE: 'one' | 'many';
|
|
40
|
+
/** The model with one record. */
|
|
41
|
+
Parent: ModelClass;
|
|
42
|
+
/** Field on the parent the child points at. */
|
|
43
|
+
parentId: string;
|
|
44
|
+
/** Attribute on the parent that reaches the children. */
|
|
45
|
+
parentChildAttr: string;
|
|
46
|
+
/** The model with the other record or records. */
|
|
47
|
+
Child: ModelClass;
|
|
48
|
+
/** Field on the child that points at the parent. */
|
|
49
|
+
childParentRef: string;
|
|
50
|
+
/** Attribute on the child that reaches the parent. */
|
|
51
|
+
childParentAttr: string;
|
|
52
|
+
/** Whether the child side holds one record or many. */
|
|
53
|
+
MODE: 'one' | 'many';
|
|
54
|
+
constructor(Parent: ModelClass, Child: ModelClass, options?: OneToOptions);
|
|
55
|
+
}
|
|
56
|
+
/** One parent record to many child records. */
|
|
57
|
+
export declare class OneToMany extends OneTo {
|
|
58
|
+
static MODE: "many";
|
|
59
|
+
static SAME: boolean;
|
|
60
|
+
}
|
|
61
|
+
/** One parent record to one child record. */
|
|
62
|
+
export declare class OneToOne extends OneTo {
|
|
63
|
+
static MODE: "one";
|
|
64
|
+
static SAME: boolean;
|
|
65
|
+
}
|
|
66
|
+
/** What you can spell out about a many-to-many relation instead of letting it be inferred. */
|
|
67
|
+
export interface ManyToManyOptions {
|
|
68
|
+
/** Attribute on the sister that reaches the brothers. Defaults to the brother's name. */
|
|
69
|
+
sisterBrotherAttr?: string;
|
|
70
|
+
/** Attribute on the brother that reaches the sisters. Defaults to the sister's name. */
|
|
71
|
+
brotherSisterAttr?: string;
|
|
72
|
+
/** Field on the sister listing brother ids. Inferred by convention. */
|
|
73
|
+
sisterBrotherRef?: string | number;
|
|
74
|
+
/** Field on the brother listing sister ids. Inferred by convention. */
|
|
75
|
+
brotherSisterRef?: string | number;
|
|
76
|
+
/** Field on the sister the tie points at. Defaults to the sister's id. */
|
|
77
|
+
sisterId?: string | number;
|
|
78
|
+
/** Field on the brother the tie points at. Defaults to the brother's id. */
|
|
79
|
+
brotherId?: string | number;
|
|
80
|
+
/** Field on the tie pointing at the sister. Inferred by convention. */
|
|
81
|
+
tieSisterRef?: string | number;
|
|
82
|
+
/** Field on the tie pointing at the brother. Inferred by convention. */
|
|
83
|
+
tieBrotherRef?: string | number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Many records on each side, joined through a tie model. The tie is a real model, so it
|
|
87
|
+
* lives in the same source and migrates like anything else.
|
|
88
|
+
*/
|
|
89
|
+
export declare class ManyToMany extends Relation {
|
|
90
|
+
/** The model with fewer records, by convention. */
|
|
91
|
+
Sister: ModelClass;
|
|
92
|
+
/** Field on the sister the tie points at. */
|
|
93
|
+
sisterId: string;
|
|
94
|
+
/** Field on the sister listing brother ids. */
|
|
95
|
+
sisterBrotherRef: string;
|
|
96
|
+
/** Attribute on the sister that reaches the brothers. */
|
|
97
|
+
sisterBrotherAttr: string;
|
|
98
|
+
/** The model with more records, by convention. */
|
|
99
|
+
Brother: ModelClass;
|
|
100
|
+
/** Field on the brother the tie points at. */
|
|
101
|
+
brotherId: string;
|
|
102
|
+
/** Field on the brother listing sister ids. */
|
|
103
|
+
brotherSisterRef: string;
|
|
104
|
+
/** Attribute on the brother that reaches the sisters. */
|
|
105
|
+
brotherSisterAttr: string;
|
|
106
|
+
/** The joining model. */
|
|
107
|
+
Tie: ModelClass;
|
|
108
|
+
/** Field on the tie pointing at the sister. */
|
|
109
|
+
tieSisterRef: string;
|
|
110
|
+
/** Field on the tie pointing at the brother. */
|
|
111
|
+
tieBrotherRef: string;
|
|
112
|
+
constructor(Sister: ModelClass, Brother: ModelClass, Tie: ModelClass, options?: ManyToManyOptions);
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=relation.d.ts.map
|
package/dist/relation.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Relations between models.
|
|
3
|
+
*
|
|
4
|
+
* Relations are declared outside the models, not inside them, so a model stays a plain
|
|
5
|
+
* description of its own shape and can be reused in a service that doesn't know about
|
|
6
|
+
* the other side.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* new OneToMany(Unit, Test) // unit.test, test.unit
|
|
10
|
+
* new OneToOne(Unit, Detail) // unit.detail, detail.unit
|
|
11
|
+
* new ManyToMany(Sister, Brother, Tie)
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import { ModelError } from './errors.js';
|
|
15
|
+
/** Base for every relation, holding the convention used to find the joining field. */
|
|
16
|
+
export class Relation {
|
|
17
|
+
/** Whether the two sides can share an id field name. */
|
|
18
|
+
static SAME = null;
|
|
19
|
+
/**
|
|
20
|
+
* Work out which field on `relative` points at `model`, by convention:
|
|
21
|
+
* `<model>_id`, then `<model>_<model id field>`, then the model's own id field name.
|
|
22
|
+
*/
|
|
23
|
+
static relativeField(model, relative, same) {
|
|
24
|
+
// The standard convention: unit_id on the test.
|
|
25
|
+
const standard = `${model.NAME}_id`;
|
|
26
|
+
if (relative._fields.has(standard)) {
|
|
27
|
+
return standard;
|
|
28
|
+
}
|
|
29
|
+
// The id field isn't called id: unit_uuid on the test.
|
|
30
|
+
const modelId = model._fieldName(model._id);
|
|
31
|
+
const simple = `${model.NAME}_${modelId}`;
|
|
32
|
+
if (relative._fields.has(simple)) {
|
|
33
|
+
return simple;
|
|
34
|
+
}
|
|
35
|
+
// Both sides use the same name for the field: unit_id on both.
|
|
36
|
+
if (relative._fields.has(modelId) && (same || modelId !== relative._fieldName(relative._id))) {
|
|
37
|
+
return modelId;
|
|
38
|
+
}
|
|
39
|
+
throw new ModelError(model, `cannot determine field for ${model.NAME} in ${relative.NAME}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** One parent record to one or many child records. */
|
|
43
|
+
export class OneTo extends Relation {
|
|
44
|
+
/** Whether the child side holds one record or many. */
|
|
45
|
+
static MODE = 'many';
|
|
46
|
+
/** The model with one record. */
|
|
47
|
+
Parent;
|
|
48
|
+
/** Field on the parent the child points at. */
|
|
49
|
+
parentId;
|
|
50
|
+
/** Attribute on the parent that reaches the children. */
|
|
51
|
+
parentChildAttr;
|
|
52
|
+
/** The model with the other record or records. */
|
|
53
|
+
Child;
|
|
54
|
+
/** Field on the child that points at the parent. */
|
|
55
|
+
childParentRef;
|
|
56
|
+
/** Attribute on the child that reaches the parent. */
|
|
57
|
+
childParentAttr;
|
|
58
|
+
/** Whether the child side holds one record or many. */
|
|
59
|
+
MODE;
|
|
60
|
+
constructor(Parent, Child, options = {}) {
|
|
61
|
+
super();
|
|
62
|
+
const kind = this.constructor;
|
|
63
|
+
this.Parent = Parent;
|
|
64
|
+
this.Child = Child;
|
|
65
|
+
this.MODE = kind.MODE;
|
|
66
|
+
const parent = Parent.thy();
|
|
67
|
+
const child = Child.thy();
|
|
68
|
+
this.parentId = parent._fieldName(options.parentId ?? parent._id);
|
|
69
|
+
this.parentChildAttr = options.parentChildAttr ?? child.NAME;
|
|
70
|
+
this.childParentAttr = options.childParentAttr ?? parent.NAME;
|
|
71
|
+
this.childParentRef =
|
|
72
|
+
options.childParentRef !== undefined
|
|
73
|
+
? child._fieldName(options.childParentRef)
|
|
74
|
+
: Relation.relativeField(parent, child, kind.SAME);
|
|
75
|
+
this.Parent._child(this);
|
|
76
|
+
this.Child._parent(this);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** One parent record to many child records. */
|
|
80
|
+
export class OneToMany extends OneTo {
|
|
81
|
+
static MODE = 'many';
|
|
82
|
+
static SAME = false;
|
|
83
|
+
}
|
|
84
|
+
/** One parent record to one child record. */
|
|
85
|
+
export class OneToOne extends OneTo {
|
|
86
|
+
static MODE = 'one';
|
|
87
|
+
static SAME = true;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Many records on each side, joined through a tie model. The tie is a real model, so it
|
|
91
|
+
* lives in the same source and migrates like anything else.
|
|
92
|
+
*/
|
|
93
|
+
export class ManyToMany extends Relation {
|
|
94
|
+
/** The model with fewer records, by convention. */
|
|
95
|
+
Sister;
|
|
96
|
+
/** Field on the sister the tie points at. */
|
|
97
|
+
sisterId;
|
|
98
|
+
/** Field on the sister listing brother ids. */
|
|
99
|
+
sisterBrotherRef;
|
|
100
|
+
/** Attribute on the sister that reaches the brothers. */
|
|
101
|
+
sisterBrotherAttr;
|
|
102
|
+
/** The model with more records, by convention. */
|
|
103
|
+
Brother;
|
|
104
|
+
/** Field on the brother the tie points at. */
|
|
105
|
+
brotherId;
|
|
106
|
+
/** Field on the brother listing sister ids. */
|
|
107
|
+
brotherSisterRef;
|
|
108
|
+
/** Attribute on the brother that reaches the sisters. */
|
|
109
|
+
brotherSisterAttr;
|
|
110
|
+
/** The joining model. */
|
|
111
|
+
Tie;
|
|
112
|
+
/** Field on the tie pointing at the sister. */
|
|
113
|
+
tieSisterRef;
|
|
114
|
+
/** Field on the tie pointing at the brother. */
|
|
115
|
+
tieBrotherRef;
|
|
116
|
+
constructor(Sister, Brother, Tie, options = {}) {
|
|
117
|
+
super();
|
|
118
|
+
this.Sister = Sister;
|
|
119
|
+
this.Brother = Brother;
|
|
120
|
+
this.Tie = Tie;
|
|
121
|
+
if (Tie.TIE === undefined || Tie.TIE === null) {
|
|
122
|
+
Tie.TIE = true;
|
|
123
|
+
}
|
|
124
|
+
const sister = Sister.thy();
|
|
125
|
+
const brother = Brother.thy();
|
|
126
|
+
const tie = Tie.thy();
|
|
127
|
+
this.sisterId = sister._fieldName(options.sisterId ?? sister._id);
|
|
128
|
+
this.sisterBrotherRef =
|
|
129
|
+
options.sisterBrotherRef !== undefined
|
|
130
|
+
? sister._fieldName(options.sisterBrotherRef)
|
|
131
|
+
: Relation.relativeField(brother, sister, null);
|
|
132
|
+
this.sisterBrotherAttr = options.sisterBrotherAttr ?? brother.NAME;
|
|
133
|
+
this.brotherId = brother._fieldName(options.brotherId ?? brother._id);
|
|
134
|
+
this.brotherSisterRef =
|
|
135
|
+
options.brotherSisterRef !== undefined
|
|
136
|
+
? brother._fieldName(options.brotherSisterRef)
|
|
137
|
+
: Relation.relativeField(sister, brother, null);
|
|
138
|
+
this.brotherSisterAttr = options.brotherSisterAttr ?? sister.NAME;
|
|
139
|
+
this.tieSisterRef = tie._fieldName(options.tieSisterRef ?? Relation.relativeField(sister, tie, null));
|
|
140
|
+
this.tieBrotherRef = tie._fieldName(options.tieBrotherRef ?? Relation.relativeField(brother, tie, null));
|
|
141
|
+
this.Sister._brother(this);
|
|
142
|
+
this.Brother._sister(this);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=relation.js.map
|
package/dist/source.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sources: the abstract backend.
|
|
3
|
+
*
|
|
4
|
+
* Everything that actually stores data implements this. The methods that touch storage
|
|
5
|
+
* are async, because in JavaScript anything that talks to a database, a socket, or a
|
|
6
|
+
* file has to be. Everything else - definitions, migrations, query building - is plain
|
|
7
|
+
* synchronous work on structures already in memory.
|
|
8
|
+
*/
|
|
9
|
+
import type { Field } from './field.js';
|
|
10
|
+
import type { Record as FieldRecord } from './record.js';
|
|
11
|
+
import type { ManyToMany } from './relation.js';
|
|
12
|
+
import type { Model, ModelClass, ModelIdentity } from './model.js';
|
|
13
|
+
/** A query a source built but hasn't run. */
|
|
14
|
+
export interface Query {
|
|
15
|
+
bind(model: Model): Query;
|
|
16
|
+
[member: string]: any;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Base source. Subclass it, give it a name, and register happens for you.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* class MySource extends Source {
|
|
23
|
+
* async create(model) { ... }
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* new MySource('example') // models with `static source = 'example'` now use it
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare class Source {
|
|
30
|
+
/** Anything the subclass was constructed with. */
|
|
31
|
+
[option: string]: any;
|
|
32
|
+
/** What kind of source this is, used to namespace migration files. */
|
|
33
|
+
static KIND: string | null;
|
|
34
|
+
/** The name models refer to this source by. */
|
|
35
|
+
name: string;
|
|
36
|
+
constructor(name: string, options?: globalThis.Record<string, any>);
|
|
37
|
+
/** What kind of source this is. */
|
|
38
|
+
get KIND(): string | null;
|
|
39
|
+
/** Give an object an attribute if it hasn't got one. */
|
|
40
|
+
ensureAttribute(item: any, attribute: string, value?: any): void;
|
|
41
|
+
/** Prepare a field for this source. */
|
|
42
|
+
fieldInit(field: Field): void;
|
|
43
|
+
/** Prepare every field in a record. */
|
|
44
|
+
recordInit(record: FieldRecord): void;
|
|
45
|
+
/** Prepare a model. Called once per model identity. */
|
|
46
|
+
init(model: ModelIdentity): void;
|
|
47
|
+
/** Turn a field definition into whatever this source needs. */
|
|
48
|
+
fieldDefine(field: globalThis.Record<string, any>, ...args: any[]): void;
|
|
49
|
+
/** Turn every field definition in a record. */
|
|
50
|
+
recordDefine(record: globalThis.Record<string, any>[], ...args: any[]): void;
|
|
51
|
+
/** Turn a model definition into whatever this source needs. */
|
|
52
|
+
define(model: globalThis.Record<string, any>, ...args: any[]): any;
|
|
53
|
+
/** Add a field. */
|
|
54
|
+
fieldAdd(migration: globalThis.Record<string, any>, ...args: any[]): void;
|
|
55
|
+
/** Remove a field. */
|
|
56
|
+
fieldRemove(definition: globalThis.Record<string, any>, ...args: any[]): void;
|
|
57
|
+
/** Change a field. */
|
|
58
|
+
fieldChange(definition: globalThis.Record<string, any>, migration: globalThis.Record<string, any>, ...args: any[]): void;
|
|
59
|
+
/** Apply a record's worth of field changes. */
|
|
60
|
+
recordChange(definition: globalThis.Record<string, any>[], migration: globalThis.Record<string, any>, ...args: any[]): void;
|
|
61
|
+
/** Add a model. */
|
|
62
|
+
modelAdd(migration: globalThis.Record<string, any>): any;
|
|
63
|
+
/** Remove a model. */
|
|
64
|
+
modelRemove(definition: globalThis.Record<string, any>): any;
|
|
65
|
+
/** Change a model. */
|
|
66
|
+
modelChange(definition: globalThis.Record<string, any>, migration: globalThis.Record<string, any>): any;
|
|
67
|
+
/** Prepare a field for a create. */
|
|
68
|
+
createField(field: Field, ...args: any[]): void;
|
|
69
|
+
/** Prepare every field in a record for a create. */
|
|
70
|
+
createRecord(record: FieldRecord, ...args: any[]): void;
|
|
71
|
+
/** The query that would create these records. */
|
|
72
|
+
createQuery(model: Model, ...args: any[]): Query | undefined;
|
|
73
|
+
/** Whether any tie records need writing. */
|
|
74
|
+
static hasTies(model: Model, data?: any): boolean;
|
|
75
|
+
/** Write the tie records for a many-to-many. */
|
|
76
|
+
static createTies(model: Model, data?: any, ids?: any): Promise<void>;
|
|
77
|
+
/** Write records. Subclasses do the actual storing and call this first. */
|
|
78
|
+
create(model: Model, ...args: any[]): Promise<any>;
|
|
79
|
+
/** Prepare a field for a retrieve. */
|
|
80
|
+
retrieveField(field: Field, ...args: any[]): void;
|
|
81
|
+
/** Prepare every field in a record for a retrieve. */
|
|
82
|
+
retrieveRecord(record: FieldRecord, ...args: any[]): void;
|
|
83
|
+
/** The ids on one side of a tie that match a set operator on the other. */
|
|
84
|
+
static tieIds(Tie: ModelClass, queryRef: string, resultRef: string, operator: string, values: any): Promise<Set<any>>;
|
|
85
|
+
/**
|
|
86
|
+
* The ids tied to a sibling matching field criteria, for filters like
|
|
87
|
+
* `{brother__name: 'Tom'}`. A model matches when it's tied to any such sibling.
|
|
88
|
+
*/
|
|
89
|
+
static attrIds(relation: ManyToMany, side: 'sister' | 'brother', criteria: globalThis.Record<string, any>): Promise<Set<any>>;
|
|
90
|
+
/**
|
|
91
|
+
* Resolve tie criteria into plain id filters by walking the tie model. Handles both
|
|
92
|
+
* tie-id criteria (`{brother_id__has: [...]}`) and sibling-attribute criteria
|
|
93
|
+
* (`{brother__name: 'Tom'}`).
|
|
94
|
+
*/
|
|
95
|
+
static collateTies(model: Model): Promise<void>;
|
|
96
|
+
/** Fill in the tie fields on retrieved records. */
|
|
97
|
+
static retrieveTies(model: Model): Promise<void>;
|
|
98
|
+
/** The query that would count matching records. */
|
|
99
|
+
countQuery(model: Model, ...args: any[]): Query | undefined;
|
|
100
|
+
/** Count matching records. Subclasses do the counting and call this first. */
|
|
101
|
+
count(model: Model, ...args: any[]): Promise<any>;
|
|
102
|
+
/** The query that would retrieve matching records. */
|
|
103
|
+
retrieveQuery(model: Model, ...args: any[]): Query | undefined;
|
|
104
|
+
/** Read records. Subclasses do the reading and call this first. */
|
|
105
|
+
retrieve(model: Model, verify?: boolean, ...args: any[]): Promise<any>;
|
|
106
|
+
/** The query that would retrieve titles. */
|
|
107
|
+
titlesQuery(model: Model, ...args: any[]): Query | undefined;
|
|
108
|
+
/** Titles for matching records. Subclasses build them and call this first. */
|
|
109
|
+
titles(model: Model, ...args: any[]): Promise<any>;
|
|
110
|
+
/** Prepare a field for an update. */
|
|
111
|
+
updateField(field: Field, ...args: any[]): void;
|
|
112
|
+
/** Prepare every field in a record for an update. */
|
|
113
|
+
updateRecord(record: FieldRecord, ...args: any[]): void;
|
|
114
|
+
/** Prepare a field for a mass update. */
|
|
115
|
+
fieldMass(field: Field, ...args: any[]): void;
|
|
116
|
+
/** Prepare every field in a record for a mass update. */
|
|
117
|
+
recordMass(record: FieldRecord, ...args: any[]): void;
|
|
118
|
+
/** The query that would update records. */
|
|
119
|
+
updateQuery(model: Model, ...args: any[]): Query | undefined;
|
|
120
|
+
/** Write changes. Resolves to how many records changed. */
|
|
121
|
+
update(model: Model, ...args: any[]): Promise<number>;
|
|
122
|
+
/** Prepare a field for a delete. */
|
|
123
|
+
deleteField(field: Field, ...args: any[]): void;
|
|
124
|
+
/** Prepare every field in a record for a delete. */
|
|
125
|
+
deleteRecord(record: FieldRecord, ...args: any[]): void;
|
|
126
|
+
/** The query that would delete records. */
|
|
127
|
+
deleteQuery(model: Model, ...args: any[]): Query | undefined;
|
|
128
|
+
/** Remove the tie records for a many-to-many. */
|
|
129
|
+
static deleteTies(model: Model, ids?: any): Promise<void>;
|
|
130
|
+
/** Remove records. Resolves to how many were removed. */
|
|
131
|
+
delete(model: Model, ...args: any[]): Promise<number>;
|
|
132
|
+
/** Convert a general definition file into a source-specific one. */
|
|
133
|
+
definition(filePath: string, sourcePath: string): Promise<void>;
|
|
134
|
+
/** Convert a general migration file into a source-specific one. */
|
|
135
|
+
migration(filePath: string, sourcePath: string): Promise<void>;
|
|
136
|
+
/** Run a command or commands against the source. */
|
|
137
|
+
execute(commands: any): Promise<void>;
|
|
138
|
+
/** The migration pairs available for this source. */
|
|
139
|
+
list(sourcePath: string): Promise<globalThis.Record<string, any>>;
|
|
140
|
+
/** Load a definition or migration file into the source. */
|
|
141
|
+
load(filePath: string): Promise<void>;
|
|
142
|
+
/** Bring the source up to date with everything in a migration directory. */
|
|
143
|
+
migrate(sourcePath: string): Promise<boolean>;
|
|
144
|
+
}
|
|
145
|
+
/** A field definition by name. */
|
|
146
|
+
export declare function lookup(name: string, fields: globalThis.Record<string, any>[]): globalThis.Record<string, any> | null;
|
|
147
|
+
//# sourceMappingURL=source.d.ts.map
|