Skip to content

Commit 5c05698

Browse files
committed
chore: code comments
1 parent 4bfc061 commit 5c05698

File tree

23 files changed

+78
-77
lines changed

23 files changed

+78
-77
lines changed

src/connection/Connection.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class Connection<M extends Model> {
2222
}
2323

2424
/**
25-
* Get namespace for the modul
25+
* Get namespace for the module.
2626
*/
2727
private getNamespace(): { connection: string; entity: string } {
2828
const connection = this.store.$database.connection
@@ -41,7 +41,7 @@ export class Connection<M extends Model> {
4141
}
4242

4343
/**
44-
* Commit the store mutation.
44+
* Commit a namespaced store mutation.
4545
*/
4646
private commit(name: string, payload?: any): void {
4747
const { connection, entity } = this.getNamespace()
@@ -73,21 +73,22 @@ export class Connection<M extends Model> {
7373
}
7474

7575
/**
76-
* Commit `insert` change to the store.
76+
* Commit `insert` mutation to the store.
7777
*/
7878
insert(records: Element[]): void {
7979
this.commit('insert', this.mapElements(records))
8080
}
8181

8282
/**
83-
* Commit `update` change to the store.
83+
* Commit `update` mutation to the store.
8484
*/
8585
update(records: Element[]): void {
8686
this.commit('update', this.mapElements(records))
8787
}
8888

8989
/**
90-
* Convert the given array of records into records.
90+
* Convert the given array of records into a dictionary of records keyed by
91+
* it's primary key.
9192
*/
9293
private mapElements(records: Element[]): Elements {
9394
return records.reduce<Elements>((carry, record) => {
@@ -97,14 +98,14 @@ export class Connection<M extends Model> {
9798
}
9899

99100
/**
100-
* Commit `delete` change to the store.
101+
* Commit `delete` mutation to the store.
101102
*/
102103
delete(ids: string[]): void {
103104
this.commit('delete', ids)
104105
}
105106

106107
/**
107-
* Commit `deleteAll` change to the store.
108+
* Commit `deleteAll` mutation to the store.
108109
*/
109110
deleteAll(): void {
110111
this.commit('deleteAll')

src/database/Database.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class Database {
1616

1717
/**
1818
* The name of Vuex Module namespace. Vuex ORM will create Vuex Modules from
19-
* the registered models and modules and define them under this namespace.
19+
* the registered models, and modules, and define them under this namespace.
2020
*/
2121
connection!: string
2222

@@ -32,7 +32,7 @@ export class Database {
3232

3333
/**
3434
* Whether the database has already been installed to Vuex or not.
35-
* The model registration steps depend on its value.
35+
* The model registration procedure depends on this flag.
3636
*/
3737
started: boolean = false
3838

@@ -77,14 +77,14 @@ export class Database {
7777
}
7878

7979
/**
80-
* Get the model.
80+
* Get a model by the specified entity name.
8181
*/
8282
getModel<M extends Model>(name: string): M {
8383
return this.models[name] as any
8484
}
8585

8686
/**
87-
* Get the schema.
87+
* Get schema by the specified entity name.
8888
*/
8989
getSchema(name: string): Normalizr.Entity {
9090
return this.schemas[name]

src/model/Model.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export class Model {
4444

4545
/**
4646
* The registry for the model. It contains predefined model schema generated
47-
* by the decorators, and gets evaluated and stored at `schema` property
48-
* when registering models to the database
47+
* by the property decorators and gets evaluated, and stored, on the `schema`
48+
* property when registering models to the database.
4949
*/
5050
protected static registries: ModelRegistries = {}
5151

@@ -64,7 +64,7 @@ export class Model {
6464
}
6565

6666
/**
67-
* Build a schema by evaluating fields and registry.
67+
* Build the schema by evaluating fields and registry.
6868
*/
6969
static initializeSchema(): void {
7070
this.schemas[this.entity] = {}
@@ -90,43 +90,43 @@ export class Model {
9090
}
9191

9292
/**
93-
* Clear the list of booted models so they will be re-booted.
93+
* Clear the list of booted models so they can be re-booted.
9494
*/
9595
static clearBootedModels(): void {
9696
this.booted = {}
9797
this.schemas = {}
9898
}
9999

100100
/**
101-
* Create a new attr attribute instance.
101+
* Create a new Attr attribute instance.
102102
*/
103103
static attr(value: any): Attr {
104104
return new Attr(new this(), value)
105105
}
106106

107107
/**
108-
* Create a new string attribute instance.
108+
* Create a new String attribute instance.
109109
*/
110110
static string(value: string | null): Str {
111111
return new Str(new this(), value)
112112
}
113113

114114
/**
115-
* Create a new number attribute instance.
115+
* Create a new Number attribute instance.
116116
*/
117117
static number(value: number | null): Num {
118118
return new Num(new this(), value)
119119
}
120120

121121
/**
122-
* Create a new boolean attribute instance.
122+
* Create a new Boolean attribute instance.
123123
*/
124124
static boolean(value: boolean | null): Bool {
125125
return new Bool(new this(), value)
126126
}
127127

128128
/**
129-
* Create a new has one relation instance.
129+
* Create a new HasOne relation instance.
130130
*/
131131
static hasOne(
132132
related: typeof Model,
@@ -141,7 +141,7 @@ export class Model {
141141
}
142142

143143
/**
144-
* Create a new belongs to relation instance.
144+
* Create a new BelongsTo relation instance.
145145
*/
146146
static belongsTo(
147147
related: typeof Model,
@@ -156,7 +156,7 @@ export class Model {
156156
}
157157

158158
/**
159-
* Create a new has many relation instance.
159+
* Create a new HasMany relation instance.
160160
*/
161161
static hasMany(
162162
related: typeof Model,
@@ -171,7 +171,7 @@ export class Model {
171171
}
172172

173173
/**
174-
* Get the constructor for the model.
174+
* Get the constructor for this model.
175175
*/
176176
get $self(): typeof Model {
177177
return this.constructor as typeof Model
@@ -185,14 +185,14 @@ export class Model {
185185
}
186186

187187
/**
188-
* Get the entity for the model.
188+
* Get the entity for this model.
189189
*/
190190
get $entity(): string {
191191
return this.$self.entity
192192
}
193193

194194
/**
195-
* Get the primary key for the model.
195+
* Get the primary key for this model.
196196
*/
197197
get $primaryKey(): string {
198198
return this.$self.primaryKey
@@ -208,9 +208,9 @@ export class Model {
208208
}
209209

210210
/**
211-
* Create a new instance of the model. This method just provides a convenient
212-
* way for us to generate fresh model instances of this current model. It's
213-
* particularly useful during the hydration of new objects via the query.
211+
* Create a new instance of this model. This method provides a convenient way
212+
* to re-generate a fresh instance of this model. It's particularly useful
213+
* during hydration through Query operations.
214214
*/
215215
$newInstance(attributes?: Element, options?: ModelOptions): this {
216216
const model = new this.$self(attributes, options) as this
@@ -221,14 +221,14 @@ export class Model {
221221
}
222222

223223
/**
224-
* Get model fields for the model.
224+
* Get the model fields for this model.
225225
*/
226226
get $fields(): ModelFields {
227227
return this.$self.schemas[this.$entity]
228228
}
229229

230230
/**
231-
* Bootstrap the model.
231+
* Bootstrap this model.
232232
*/
233233
protected $boot(): void {
234234
if (!this.$self.booted[this.$entity]) {
@@ -239,15 +239,15 @@ export class Model {
239239
}
240240

241241
/**
242-
* Build a schema by evaluating fields and registry.
242+
* Build the schema by evaluating fields and registry.
243243
*/
244244
protected $initializeSchema(): void {
245245
this.$self.initializeSchema()
246246
}
247247

248248
/**
249-
* Fill the model by the given Its default values will fill any
250-
* missing field.
249+
* Fill this model by the given attributes. Missing fields will be populated
250+
* by the attributes default value.
251251
*/
252252
$fill(attributes: Element = {}, options: ModelOptions = {}): this {
253253
const fillRelation = options.relations ?? true
@@ -267,7 +267,7 @@ export class Model {
267267
}
268268

269269
/**
270-
* Fill the model filed.
270+
* Fill the given attribute with a given value specified by the given key.
271271
*/
272272
protected $fillField(key: string, attr: Attribute, value: any): void {
273273
if (value !== undefined) {
@@ -291,7 +291,7 @@ export class Model {
291291
}
292292

293293
/**
294-
* Get the index id for the model or the given record.
294+
* Get the index id of this model or for a given record.
295295
*/
296296
$getIndexId(record?: Element): string {
297297
const target = record ?? this
@@ -300,14 +300,14 @@ export class Model {
300300
}
301301

302302
/**
303-
* Get the local key for the model.
303+
* Get the local key for this model.
304304
*/
305305
$getLocalKey(): string {
306306
return this.$primaryKey
307307
}
308308

309309
/**
310-
* Check if the model has any relations defined in the schema.
310+
* Check if this model has any relations defined by the schema.
311311
*/
312312
$hasRelation(): boolean {
313313
let result = false
@@ -353,7 +353,7 @@ export class Model {
353353
}
354354

355355
/**
356-
* Serialize given model POJO.
356+
* Serialize this model, or the given model, as POJO.
357357
*/
358358
$toJson(model?: Model, options: ModelOptions = {}): Element {
359359
model = model ?? this
@@ -380,7 +380,7 @@ export class Model {
380380
}
381381

382382
/**
383-
* Serialize given value.
383+
* Serialize the given value.
384384
*/
385385
protected serializeValue(v: any): any {
386386
if (v === null) {
@@ -399,14 +399,14 @@ export class Model {
399399
}
400400

401401
/**
402-
* Serialize an array into json.
402+
* Serialize the given array to JSON.
403403
*/
404404
protected serializeArray(a: any[]): any[] {
405405
return a.map((v) => this.serializeValue(v))
406406
}
407407

408408
/**
409-
* Serialize an object into json.
409+
* Serialize the given object to JSON.
410410
*/
411411
protected serializeObject(o: object): object {
412412
const obj = {}
@@ -419,7 +419,7 @@ export class Model {
419419
}
420420

421421
/**
422-
* Serialize given relation into json.
422+
* Serialize the given relation to JSON.
423423
*/
424424
protected serializeRelation(relation: Item): Element | null
425425
protected serializeRelation(relation: Collection): Element[]

src/model/attributes/Attribute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export abstract class Attribute {
77
protected model: Model
88

99
/**
10-
* Create a new attribute instance.
10+
* Create a new Attribute instance.
1111
*/
1212
constructor(model: Model) {
1313
this.model = model

0 commit comments

Comments
 (0)