@meridianjs/framework-utils 0.1.0 → 0.1.1
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/dist/index.js +59 -37
- package/dist/index.mjs +59 -37
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -190,48 +190,70 @@ function MeridianService(models) {
|
|
|
190
190
|
#container;
|
|
191
191
|
constructor(container) {
|
|
192
192
|
this.#container = container;
|
|
193
|
+
const hasCustomMethod = (name) => typeof this[name] === "function";
|
|
193
194
|
for (const [modelName, _modelDef] of Object.entries(models)) {
|
|
194
195
|
const pluralName = `${modelName}s`;
|
|
195
196
|
const repoToken = `${modelName.charAt(0).toLowerCase()}${modelName.slice(1)}Repository`;
|
|
196
197
|
const capitalized = `${modelName.charAt(0).toUpperCase()}${modelName.slice(1)}`;
|
|
197
198
|
const capitalizedPlural = `${pluralName.charAt(0).toUpperCase()}${pluralName.slice(1)}`;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
199
|
+
const listMethod = `list${capitalizedPlural}`;
|
|
200
|
+
if (!hasCustomMethod(listMethod)) {
|
|
201
|
+
this[listMethod] = async (filters = {}, options = {}) => {
|
|
202
|
+
const repo = this.#container.resolve(repoToken);
|
|
203
|
+
return repo.find(filters, options);
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const listAndCountMethod = `listAndCount${capitalizedPlural}`;
|
|
207
|
+
if (!hasCustomMethod(listAndCountMethod)) {
|
|
208
|
+
this[listAndCountMethod] = async (filters = {}, options = {}) => {
|
|
209
|
+
const repo = this.#container.resolve(repoToken);
|
|
210
|
+
return repo.findAndCount(filters, options);
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const retrieveMethod = `retrieve${capitalized}`;
|
|
214
|
+
if (!hasCustomMethod(retrieveMethod)) {
|
|
215
|
+
this[retrieveMethod] = async (id) => {
|
|
216
|
+
const repo = this.#container.resolve(repoToken);
|
|
217
|
+
return repo.findOneOrFail({ id });
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
const createMethod = `create${capitalized}`;
|
|
221
|
+
if (!hasCustomMethod(createMethod)) {
|
|
222
|
+
this[createMethod] = async (data) => {
|
|
223
|
+
const repo = this.#container.resolve(repoToken);
|
|
224
|
+
const entity = repo.create(data);
|
|
225
|
+
await repo.persistAndFlush(entity);
|
|
226
|
+
return entity;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
const updateMethod = `update${capitalized}`;
|
|
230
|
+
if (!hasCustomMethod(updateMethod)) {
|
|
231
|
+
this[updateMethod] = async (id, data) => {
|
|
232
|
+
const repo = this.#container.resolve(repoToken);
|
|
233
|
+
const entity = await repo.findOneOrFail({ id });
|
|
234
|
+
Object.assign(entity, data);
|
|
235
|
+
await repo.flush();
|
|
236
|
+
return entity;
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
const deleteMethod = `delete${capitalized}`;
|
|
240
|
+
if (!hasCustomMethod(deleteMethod)) {
|
|
241
|
+
this[deleteMethod] = async (id) => {
|
|
242
|
+
const repo = this.#container.resolve(repoToken);
|
|
243
|
+
const entity = await repo.findOneOrFail({ id });
|
|
244
|
+
await repo.removeAndFlush(entity);
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
const softDeleteMethod = `softDelete${capitalized}`;
|
|
248
|
+
if (!hasCustomMethod(softDeleteMethod)) {
|
|
249
|
+
this[softDeleteMethod] = async (id) => {
|
|
250
|
+
const repo = this.#container.resolve(repoToken);
|
|
251
|
+
const entity = await repo.findOneOrFail({ id });
|
|
252
|
+
entity.deleted_at = /* @__PURE__ */ new Date();
|
|
253
|
+
await repo.flush();
|
|
254
|
+
return entity;
|
|
255
|
+
};
|
|
256
|
+
}
|
|
235
257
|
}
|
|
236
258
|
}
|
|
237
259
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -140,48 +140,70 @@ function MeridianService(models) {
|
|
|
140
140
|
#container;
|
|
141
141
|
constructor(container) {
|
|
142
142
|
this.#container = container;
|
|
143
|
+
const hasCustomMethod = (name) => typeof this[name] === "function";
|
|
143
144
|
for (const [modelName, _modelDef] of Object.entries(models)) {
|
|
144
145
|
const pluralName = `${modelName}s`;
|
|
145
146
|
const repoToken = `${modelName.charAt(0).toLowerCase()}${modelName.slice(1)}Repository`;
|
|
146
147
|
const capitalized = `${modelName.charAt(0).toUpperCase()}${modelName.slice(1)}`;
|
|
147
148
|
const capitalizedPlural = `${pluralName.charAt(0).toUpperCase()}${pluralName.slice(1)}`;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
149
|
+
const listMethod = `list${capitalizedPlural}`;
|
|
150
|
+
if (!hasCustomMethod(listMethod)) {
|
|
151
|
+
this[listMethod] = async (filters = {}, options = {}) => {
|
|
152
|
+
const repo = this.#container.resolve(repoToken);
|
|
153
|
+
return repo.find(filters, options);
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const listAndCountMethod = `listAndCount${capitalizedPlural}`;
|
|
157
|
+
if (!hasCustomMethod(listAndCountMethod)) {
|
|
158
|
+
this[listAndCountMethod] = async (filters = {}, options = {}) => {
|
|
159
|
+
const repo = this.#container.resolve(repoToken);
|
|
160
|
+
return repo.findAndCount(filters, options);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const retrieveMethod = `retrieve${capitalized}`;
|
|
164
|
+
if (!hasCustomMethod(retrieveMethod)) {
|
|
165
|
+
this[retrieveMethod] = async (id) => {
|
|
166
|
+
const repo = this.#container.resolve(repoToken);
|
|
167
|
+
return repo.findOneOrFail({ id });
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const createMethod = `create${capitalized}`;
|
|
171
|
+
if (!hasCustomMethod(createMethod)) {
|
|
172
|
+
this[createMethod] = async (data) => {
|
|
173
|
+
const repo = this.#container.resolve(repoToken);
|
|
174
|
+
const entity = repo.create(data);
|
|
175
|
+
await repo.persistAndFlush(entity);
|
|
176
|
+
return entity;
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const updateMethod = `update${capitalized}`;
|
|
180
|
+
if (!hasCustomMethod(updateMethod)) {
|
|
181
|
+
this[updateMethod] = async (id, data) => {
|
|
182
|
+
const repo = this.#container.resolve(repoToken);
|
|
183
|
+
const entity = await repo.findOneOrFail({ id });
|
|
184
|
+
Object.assign(entity, data);
|
|
185
|
+
await repo.flush();
|
|
186
|
+
return entity;
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
const deleteMethod = `delete${capitalized}`;
|
|
190
|
+
if (!hasCustomMethod(deleteMethod)) {
|
|
191
|
+
this[deleteMethod] = async (id) => {
|
|
192
|
+
const repo = this.#container.resolve(repoToken);
|
|
193
|
+
const entity = await repo.findOneOrFail({ id });
|
|
194
|
+
await repo.removeAndFlush(entity);
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const softDeleteMethod = `softDelete${capitalized}`;
|
|
198
|
+
if (!hasCustomMethod(softDeleteMethod)) {
|
|
199
|
+
this[softDeleteMethod] = async (id) => {
|
|
200
|
+
const repo = this.#container.resolve(repoToken);
|
|
201
|
+
const entity = await repo.findOneOrFail({ id });
|
|
202
|
+
entity.deleted_at = /* @__PURE__ */ new Date();
|
|
203
|
+
await repo.flush();
|
|
204
|
+
return entity;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
185
207
|
}
|
|
186
208
|
}
|
|
187
209
|
}
|
package/package.json
CHANGED