@sprucelabs/data-stores 26.2.4 → 26.2.6
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.
|
@@ -34,7 +34,7 @@ export default abstract class AbstractStore<FullSchema extends Schema, CreateSch
|
|
|
34
34
|
private mapCasing;
|
|
35
35
|
create<IncludePrivateFields extends boolean = true, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(values: CreateRecord[], options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Response<FullSchema, CreateEntityInstances, IncludePrivateFields, PF, F>[]>;
|
|
36
36
|
createOne<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(values: CreateRecord, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<SchemaValues<FullSchema, false, CreateEntityInstances, false, F, SchemaPublicFieldNames<FullSchema>> & {}>;
|
|
37
|
-
private
|
|
37
|
+
private normalizeBeforeCreate;
|
|
38
38
|
private handleWillCreatePlugins;
|
|
39
39
|
private handleDidCreateForPlugins;
|
|
40
40
|
private get primaryFieldName();
|
|
@@ -82,7 +82,7 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
82
82
|
//@ts-ignore
|
|
83
83
|
values.forEach((v) => validateSchemaValues(this.createSchema, v));
|
|
84
84
|
const cleanedValues = yield Promise.all(values.map((v) => __awaiter(this, void 0, void 0, function* () { return (this.willCreate ? this.willCreate(v) : v); })));
|
|
85
|
-
const toSave = cleanedValues.map((v) => this.
|
|
85
|
+
const toSave = cleanedValues.map((v) => this.normalizeBeforeCreate(v));
|
|
86
86
|
const records = yield this.db.create(this.collectionName, toSave);
|
|
87
87
|
return Promise.all(records.map((record) => __awaiter(this, void 0, void 0, function* () { return this.prepareAndNormalizeRecord(record, options); })));
|
|
88
88
|
}
|
|
@@ -108,7 +108,7 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
108
108
|
: values;
|
|
109
109
|
let { valuesToMixinBeforeCreate, values: nv } = yield this.handleWillCreatePlugins(cleanedValues);
|
|
110
110
|
const newValues = nv;
|
|
111
|
-
const toSave = this.
|
|
111
|
+
const toSave = this.normalizeBeforeCreate(newValues);
|
|
112
112
|
const record = yield this.db.createOne(this.collectionName, Object.assign(Object.assign({}, toSave), valuesToMixinBeforeCreate), {
|
|
113
113
|
primaryFieldNames: this.primaryFieldNames,
|
|
114
114
|
});
|
|
@@ -128,7 +128,7 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
128
128
|
}
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
|
-
|
|
131
|
+
normalizeBeforeCreate(cleanedValues) {
|
|
132
132
|
var _a, _b, _c, _d;
|
|
133
133
|
const shouldAutoGenerateId = (_b = (_a = this.db).getShouldAutoGenerateId) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
134
134
|
const databaseRecord = !shouldAutoGenerateId
|
|
@@ -136,7 +136,10 @@ export default class AbstractStore extends AbstractMutexer {
|
|
|
136
136
|
: Object.assign(Object.assign({}, cleanedValues), { [this.primaryFieldName]:
|
|
137
137
|
//@ts-ignore
|
|
138
138
|
(_c = cleanedValues[this.primaryFieldName]) !== null && _c !== void 0 ? _c : this.db.generateId() });
|
|
139
|
-
const
|
|
139
|
+
const shouldExcludePrimaryKeyField =
|
|
140
|
+
//@ts-ignore
|
|
141
|
+
shouldAutoGenerateId || cleanedValues[this.primaryFieldName];
|
|
142
|
+
const fields = shouldExcludePrimaryKeyField
|
|
140
143
|
? undefined
|
|
141
144
|
: Object.keys(dropFields((_d = this.databaseSchema.fields) !== null && _d !== void 0 ? _d : {}, this.primaryFieldNames));
|
|
142
145
|
const toSave = normalizeSchemaValues(this.databaseSchema,
|
|
@@ -34,7 +34,7 @@ export default abstract class AbstractStore<FullSchema extends Schema, CreateSch
|
|
|
34
34
|
private mapCasing;
|
|
35
35
|
create<IncludePrivateFields extends boolean = true, CreateEntityInstances extends boolean = false, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>, PF extends SchemaPublicFieldNames<FullSchema> = SchemaPublicFieldNames<FullSchema>>(values: CreateRecord[], options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<Response<FullSchema, CreateEntityInstances, IncludePrivateFields, PF, F>[]>;
|
|
36
36
|
createOne<CreateEntityInstances extends boolean, F extends SchemaFieldNames<FullSchema> = SchemaFieldNames<FullSchema>>(values: CreateRecord, options?: PrepareOptions<CreateEntityInstances, FullSchema, F>): Promise<SchemaValues<FullSchema, false, CreateEntityInstances, false, F, SchemaPublicFieldNames<FullSchema>> & {}>;
|
|
37
|
-
private
|
|
37
|
+
private normalizeBeforeCreate;
|
|
38
38
|
private handleWillCreatePlugins;
|
|
39
39
|
private handleDidCreateForPlugins;
|
|
40
40
|
private get primaryFieldName();
|
|
@@ -98,7 +98,7 @@ class AbstractStore extends AbstractMutexer_1.default {
|
|
|
98
98
|
//@ts-ignore
|
|
99
99
|
values.forEach((v) => (0, schema_1.validateSchemaValues)(this.createSchema, v));
|
|
100
100
|
const cleanedValues = await Promise.all(values.map(async (v) => (this.willCreate ? this.willCreate(v) : v)));
|
|
101
|
-
const toSave = cleanedValues.map((v) => this.
|
|
101
|
+
const toSave = cleanedValues.map((v) => this.normalizeBeforeCreate(v));
|
|
102
102
|
const records = await this.db.create(this.collectionName, toSave);
|
|
103
103
|
return Promise.all(records.map(async (record) => this.prepareAndNormalizeRecord(record, options)));
|
|
104
104
|
}
|
|
@@ -122,7 +122,7 @@ class AbstractStore extends AbstractMutexer_1.default {
|
|
|
122
122
|
: values;
|
|
123
123
|
let { valuesToMixinBeforeCreate, values: nv } = await this.handleWillCreatePlugins(cleanedValues);
|
|
124
124
|
const newValues = nv;
|
|
125
|
-
const toSave = this.
|
|
125
|
+
const toSave = this.normalizeBeforeCreate(newValues);
|
|
126
126
|
const record = await this.db.createOne(this.collectionName, Object.assign(Object.assign({}, toSave), valuesToMixinBeforeCreate), {
|
|
127
127
|
primaryFieldNames: this.primaryFieldNames,
|
|
128
128
|
});
|
|
@@ -141,7 +141,7 @@ class AbstractStore extends AbstractMutexer_1.default {
|
|
|
141
141
|
throw coded[0];
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
normalizeBeforeCreate(cleanedValues) {
|
|
145
145
|
var _a, _b, _c, _d;
|
|
146
146
|
const shouldAutoGenerateId = (_b = (_a = this.db).getShouldAutoGenerateId) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
147
147
|
const databaseRecord = !shouldAutoGenerateId
|
|
@@ -149,7 +149,10 @@ class AbstractStore extends AbstractMutexer_1.default {
|
|
|
149
149
|
: Object.assign(Object.assign({}, cleanedValues), { [this.primaryFieldName]:
|
|
150
150
|
//@ts-ignore
|
|
151
151
|
(_c = cleanedValues[this.primaryFieldName]) !== null && _c !== void 0 ? _c : this.db.generateId() });
|
|
152
|
-
const
|
|
152
|
+
const shouldExcludePrimaryKeyField =
|
|
153
|
+
//@ts-ignore
|
|
154
|
+
shouldAutoGenerateId || cleanedValues[this.primaryFieldName];
|
|
155
|
+
const fields = shouldExcludePrimaryKeyField
|
|
153
156
|
? undefined
|
|
154
157
|
: Object.keys((0, schema_1.dropFields)((_d = this.databaseSchema.fields) !== null && _d !== void 0 ? _d : {}, this.primaryFieldNames));
|
|
155
158
|
const toSave = (0, schema_1.normalizeSchemaValues)(this.databaseSchema,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "26.2.
|
|
6
|
+
"version": "26.2.6",
|
|
7
7
|
"files": [
|
|
8
8
|
"build/**/*",
|
|
9
9
|
"!build/__tests__",
|
|
@@ -70,21 +70,21 @@
|
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"@sprucelabs/error": "^5.1.52",
|
|
72
72
|
"@sprucelabs/globby": "^1.0.3",
|
|
73
|
-
"@sprucelabs/schema": "^29.2.
|
|
74
|
-
"@sprucelabs/spruce-skill-utils": "^30.1.
|
|
73
|
+
"@sprucelabs/schema": "^29.2.4",
|
|
74
|
+
"@sprucelabs/spruce-skill-utils": "^30.1.43",
|
|
75
75
|
"just-clone": "^6.2.0",
|
|
76
76
|
"lodash": "^4.17.21",
|
|
77
77
|
"mongodb": "^6.3.0",
|
|
78
78
|
"nedb": "^1.8.0"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@sprucelabs/esm-postbuild": "^5.0.
|
|
82
|
-
"@sprucelabs/jest-json-reporter": "^7.0.
|
|
81
|
+
"@sprucelabs/esm-postbuild": "^5.0.108",
|
|
82
|
+
"@sprucelabs/jest-json-reporter": "^7.0.133",
|
|
83
83
|
"@sprucelabs/jest-sheets-reporter": "^3.0.26",
|
|
84
|
-
"@sprucelabs/resolve-path-aliases": "^1.1.
|
|
84
|
+
"@sprucelabs/resolve-path-aliases": "^1.1.270",
|
|
85
85
|
"@sprucelabs/semantic-release": "^4.0.8",
|
|
86
86
|
"@sprucelabs/test": "^8.0.35",
|
|
87
|
-
"@sprucelabs/test-utils": "^4.0.
|
|
87
|
+
"@sprucelabs/test-utils": "^4.0.86",
|
|
88
88
|
"@types/lodash": "^4.14.202",
|
|
89
89
|
"@types/nedb": "^1.8.16",
|
|
90
90
|
"@types/node": "^20.10.4",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"jest": "^29.7.0",
|
|
97
97
|
"jest-circus": "^29.7.0",
|
|
98
98
|
"prettier": "^3.1.0",
|
|
99
|
-
"ts-node": "^10.9.
|
|
99
|
+
"ts-node": "^10.9.2",
|
|
100
100
|
"tsc-watch": "^6.0.4",
|
|
101
101
|
"tsconfig-paths": "^4.2.0",
|
|
102
102
|
"typescript": "^5.3.3"
|