@zintrust/core 0.4.41 → 0.4.43
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/package.json +3 -2
- package/src/boot/registry/runtime.d.ts.map +1 -1
- package/src/boot/registry/runtime.js +122 -0
- package/src/cache/Cache.d.ts.map +1 -1
- package/src/cache/Cache.js +25 -2
- package/src/cli/BaseCommand.d.ts.map +1 -1
- package/src/cli/BaseCommand.js +8 -0
- package/src/cli/CLI.d.ts.map +1 -1
- package/src/cli/CLI.js +2 -0
- package/src/cli/OptionalCliExtensions.d.ts.map +1 -1
- package/src/cli/OptionalCliExtensions.js +12 -0
- package/src/cli/cloudflare/CloudflareWranglerDevEnv.d.ts +24 -0
- package/src/cli/cloudflare/CloudflareWranglerDevEnv.d.ts.map +1 -0
- package/src/cli/cloudflare/CloudflareWranglerDevEnv.js +174 -0
- package/src/cli/commands/DebuggerCommand.d.ts +18 -0
- package/src/cli/commands/DebuggerCommand.d.ts.map +1 -0
- package/src/cli/commands/DebuggerCommand.js +6 -0
- package/src/cli/commands/DebuggerCommands.d.ts +25 -0
- package/src/cli/commands/DebuggerCommands.d.ts.map +1 -0
- package/src/cli/commands/DebuggerCommands.js +500 -0
- package/src/cli/commands/PrepareCommand.d.ts.map +1 -1
- package/src/cli/commands/PrepareCommand.js +56 -20
- package/src/cli/commands/StartCommand.d.ts.map +1 -1
- package/src/cli/commands/StartCommand.js +12 -94
- package/src/cli/commands/WranglerDevVarsCommand.d.ts +6 -0
- package/src/cli/commands/WranglerDevVarsCommand.d.ts.map +1 -0
- package/src/cli/commands/WranglerDevVarsCommand.js +52 -0
- package/src/cli/commands/index.d.ts +2 -0
- package/src/cli/commands/index.d.ts.map +1 -1
- package/src/cli/commands/index.js +2 -0
- package/src/cli/index.d.ts +1 -0
- package/src/cli/index.d.ts.map +1 -1
- package/src/cli/index.js +1 -0
- package/src/cli.d.ts +1 -0
- package/src/cli.d.ts.map +1 -1
- package/src/cli.js +1 -0
- package/src/config/database.d.ts.map +1 -1
- package/src/config/database.js +7 -1
- package/src/config/logger.d.ts +7 -0
- package/src/config/logger.d.ts.map +1 -1
- package/src/config/logger.js +37 -0
- package/src/debugger/SystemDebuggerBridge.d.ts +15 -0
- package/src/debugger/SystemDebuggerBridge.d.ts.map +1 -0
- package/src/debugger/SystemDebuggerBridge.js +109 -0
- package/src/events/EventDispatcher.d.ts.map +1 -1
- package/src/events/EventDispatcher.js +3 -0
- package/src/functions/cloudflare.d.ts.map +1 -1
- package/src/http/Kernel.d.ts.map +1 -1
- package/src/http/Kernel.js +8 -0
- package/src/http/RequestContext.d.ts +1 -0
- package/src/http/RequestContext.d.ts.map +1 -1
- package/src/http/RequestContext.js +9 -1
- package/src/index.d.ts +4 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +5 -3
- package/src/migrations/schema/SchemaCompiler.d.ts.map +1 -1
- package/src/migrations/schema/SchemaCompiler.js +2 -2
- package/src/orm/Database.d.ts +1 -0
- package/src/orm/Database.d.ts.map +1 -1
- package/src/orm/Database.js +11 -16
- package/src/orm/DatabaseRuntimeRegistration.d.ts.map +1 -1
- package/src/orm/DatabaseRuntimeRegistration.js +9 -3
- package/src/orm/Model.d.ts +8 -2
- package/src/orm/Model.d.ts.map +1 -1
- package/src/orm/Model.js +193 -109
- package/src/orm/QueryBuilder.d.ts.map +1 -1
- package/src/orm/QueryBuilder.js +85 -1
- package/src/runtime/WorkerAdapterImports.d.ts.map +1 -1
- package/src/runtime/WorkerAdapterImports.js +1 -6
- package/src/runtime/WorkerProjectPlugins.d.ts +6 -0
- package/src/runtime/WorkerProjectPlugins.d.ts.map +1 -0
- package/src/runtime/WorkerProjectPlugins.js +5 -0
- package/src/runtime/plugins/system-debugger-runtime.d.ts +19 -0
- package/src/runtime/plugins/system-debugger-runtime.d.ts.map +1 -0
- package/src/runtime/plugins/system-debugger-runtime.js +19 -0
- package/src/runtime/plugins/system-debugger.d.ts +2 -0
- package/src/runtime/plugins/system-debugger.d.ts.map +1 -0
- package/src/runtime/plugins/system-debugger.js +14 -0
- package/src/security/JwtManager.d.ts.map +1 -1
- package/src/security/JwtManager.js +29 -0
- package/src/tools/http/Http.d.ts.map +1 -1
- package/src/tools/http/Http.js +2 -0
- package/src/tools/mail/index.d.ts.map +1 -1
- package/src/tools/mail/index.js +7 -1
- package/src/tools/notification/Service.d.ts.map +1 -1
- package/src/tools/notification/Service.js +18 -6
- package/src/tools/queue/Queue.d.ts.map +1 -1
- package/src/tools/queue/Queue.js +2 -0
- package/src/zintrust.plugins.d.ts +1 -0
- package/src/zintrust.plugins.d.ts.map +1 -1
- package/src/zintrust.plugins.js +3 -21
- package/src/zintrust.plugins.wg.d.ts +1 -0
- package/src/zintrust.plugins.wg.d.ts.map +1 -1
- package/src/zintrust.plugins.wg.js +3 -0
package/src/orm/Model.js
CHANGED
|
@@ -48,17 +48,25 @@ const castAttribute = (config, key, value) => {
|
|
|
48
48
|
return value;
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
+
const assignAttributes = (config, attrs, newAttrs, options) => {
|
|
52
|
+
for (const [key, value] of Object.entries(newAttrs)) {
|
|
53
|
+
if (options.respectFillable && config.fillable.length > 0 && !config.fillable.includes(key)) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const nextValue = options.applyMutators
|
|
57
|
+
? (config.mutators?.[key]?.(value, attrs) ?? value)
|
|
58
|
+
: value;
|
|
59
|
+
attrs[key] = castAttribute(config, key, nextValue);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
51
62
|
/**
|
|
52
63
|
* Fill attributes based on fillable config
|
|
53
64
|
*/
|
|
54
65
|
const fillAttributes = (config, attrs, newAttrs) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
attrs[key] = castAttribute(config, key, nextValue);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
66
|
+
assignAttributes(config, attrs, newAttrs, { applyMutators: true, respectFillable: true });
|
|
67
|
+
};
|
|
68
|
+
const hydrateAttributes = (config, attrs, storedAttrs) => {
|
|
69
|
+
assignAttributes(config, attrs, storedAttrs, { applyMutators: false, respectFillable: false });
|
|
62
70
|
};
|
|
63
71
|
const applyAccessor = (config, key, attrs) => {
|
|
64
72
|
const raw = attrs[key];
|
|
@@ -137,6 +145,47 @@ const createModelRelationships = (config) => {
|
|
|
137
145
|
hasManyThrough: createHasManyThroughFactory(),
|
|
138
146
|
};
|
|
139
147
|
};
|
|
148
|
+
const applySaveTimestamps = (config, attrs, isCreate) => {
|
|
149
|
+
if ((config.timestamps ?? false) === false)
|
|
150
|
+
return;
|
|
151
|
+
const now = new Date().toISOString();
|
|
152
|
+
attrs['updated_at'] = now;
|
|
153
|
+
if (isCreate) {
|
|
154
|
+
attrs['created_at'] = attrs['created_at'] ?? now;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const persistNewModel = async (config, db, attrs) => {
|
|
158
|
+
const builder = QueryBuilder.create(config.table, db, buildSoftDeleteOptions(config));
|
|
159
|
+
const result = await builder.insert({ ...attrs });
|
|
160
|
+
if (attrs['id'] === undefined && result.id !== null) {
|
|
161
|
+
attrs['id'] = result.id;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const collectDirtyValues = (config, attrs, dirtyFields) => {
|
|
165
|
+
const keys = new Set(dirtyFields);
|
|
166
|
+
if (config.timestamps ?? false) {
|
|
167
|
+
keys.add('updated_at');
|
|
168
|
+
}
|
|
169
|
+
return Object.fromEntries([...keys].filter((key) => key in attrs).map((key) => [key, attrs[key]]));
|
|
170
|
+
};
|
|
171
|
+
const persistExistingModel = async (config, db, attrs, dirtyFields) => {
|
|
172
|
+
const values = collectDirtyValues(config, attrs, dirtyFields);
|
|
173
|
+
if (Object.keys(values).length === 0)
|
|
174
|
+
return;
|
|
175
|
+
const primaryKey = attrs['id'];
|
|
176
|
+
if (primaryKey === undefined || primaryKey === null || primaryKey === '') {
|
|
177
|
+
throw ErrorFactory.createDatabaseError('Cannot update a persisted model without an id');
|
|
178
|
+
}
|
|
179
|
+
const builder = QueryBuilder.create(config.table, db, buildSoftDeleteOptions(config));
|
|
180
|
+
await builder.where('id', '=', primaryKey).update(values);
|
|
181
|
+
};
|
|
182
|
+
const persistModelState = async (config, db, attrs, isCreate, dirtyFields) => {
|
|
183
|
+
if (isCreate) {
|
|
184
|
+
await persistNewModel(config, db, attrs);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
await persistExistingModel(config, db, attrs, dirtyFields);
|
|
188
|
+
};
|
|
140
189
|
const performModelSave = async (model, config, attrs, getDb, context) => {
|
|
141
190
|
const db = getDb();
|
|
142
191
|
if (db === undefined)
|
|
@@ -144,10 +193,8 @@ const performModelSave = async (model, config, attrs, getDb, context) => {
|
|
|
144
193
|
const isCreate = context.isExists === false;
|
|
145
194
|
await runObservers(config, 'saving', model);
|
|
146
195
|
await runObservers(config, isCreate ? 'creating' : 'updating', model);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
attrs['updated_at'] = new Date().toISOString();
|
|
150
|
-
}
|
|
196
|
+
applySaveTimestamps(config, attrs, isCreate);
|
|
197
|
+
await persistModelState(config, db, attrs, isCreate, context.getDirtyFields());
|
|
151
198
|
context.setExists(true);
|
|
152
199
|
context.updateOriginal({ ...attrs });
|
|
153
200
|
context.clearDirty();
|
|
@@ -163,108 +210,130 @@ const performModelDelete = async (model, config, getDb, isExists) => {
|
|
|
163
210
|
await runObservers(config, 'deleted', model);
|
|
164
211
|
return true;
|
|
165
212
|
};
|
|
213
|
+
const createAttributeApi = (config, attrs, relations, context) => ({
|
|
214
|
+
fill: (newAttrs) => {
|
|
215
|
+
fillAttributes(config, attrs, newAttrs);
|
|
216
|
+
const original = context.getOriginal();
|
|
217
|
+
for (const key of Object.keys(newAttrs)) {
|
|
218
|
+
if (attrs[key] !== original[key]) {
|
|
219
|
+
context.dirtyFields.add(key);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return context.getModel();
|
|
223
|
+
},
|
|
224
|
+
setAttribute: (key, value) => {
|
|
225
|
+
const mutator = config.mutators?.[key];
|
|
226
|
+
const nextValue = mutator ? mutator(value, attrs) : value;
|
|
227
|
+
const castedValue = castAttribute(config, key, nextValue);
|
|
228
|
+
attrs[key] = castedValue;
|
|
229
|
+
const original = context.getOriginal();
|
|
230
|
+
if (original[key] === castedValue) {
|
|
231
|
+
context.dirtyFields.delete(key);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
context.dirtyFields.add(key);
|
|
235
|
+
}
|
|
236
|
+
return context.getModel();
|
|
237
|
+
},
|
|
238
|
+
getAttribute: (key) => {
|
|
239
|
+
if (relations[key] !== undefined)
|
|
240
|
+
return relations[key];
|
|
241
|
+
return applyAccessor(config, key, attrs);
|
|
242
|
+
},
|
|
243
|
+
getAttributes: () => ({ ...attrs }),
|
|
244
|
+
setRelation: (name, value) => {
|
|
245
|
+
relations[name] = value;
|
|
246
|
+
},
|
|
247
|
+
getRelation: (name) => relations[name],
|
|
248
|
+
toJSON: () => createModelJSON(config, attrs),
|
|
249
|
+
isDirty: (key) => {
|
|
250
|
+
if (key !== undefined)
|
|
251
|
+
return context.dirtyFields.has(key);
|
|
252
|
+
return context.dirtyFields.size > 0;
|
|
253
|
+
},
|
|
254
|
+
getTable: () => config.table,
|
|
255
|
+
exists: () => context.exists(),
|
|
256
|
+
setExists: (nextExists) => {
|
|
257
|
+
context.setExists(nextExists);
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
const createLifecycleApi = (config, attrs, getDb, context) => ({
|
|
261
|
+
save: async () => performModelSave(context.getModel(), config, attrs, getDb, {
|
|
262
|
+
isExists: context.exists(),
|
|
263
|
+
setExists: context.setExists,
|
|
264
|
+
updateOriginal: context.setOriginal,
|
|
265
|
+
clearDirty: () => context.dirtyFields.clear(),
|
|
266
|
+
getDirtyFields: () => [...context.dirtyFields],
|
|
267
|
+
}),
|
|
268
|
+
delete: async () => performModelDelete(context.getModel(), config, getDb, context.exists()),
|
|
269
|
+
restore: async () => {
|
|
270
|
+
if (config.softDeletes !== true || !context.exists())
|
|
271
|
+
return false;
|
|
272
|
+
await Promise.resolve();
|
|
273
|
+
const deleteAtColumn = config.deleteAtColumn ?? 'deleted_at';
|
|
274
|
+
attrs[deleteAtColumn] = null;
|
|
275
|
+
context.dirtyFields.add(deleteAtColumn);
|
|
276
|
+
return true;
|
|
277
|
+
},
|
|
278
|
+
forceDelete: async () => {
|
|
279
|
+
if (!context.exists())
|
|
280
|
+
return false;
|
|
281
|
+
const model = context.getModel();
|
|
282
|
+
await runObservers(config, 'deleting', model);
|
|
283
|
+
await runObservers(config, 'deleted', model);
|
|
284
|
+
return true;
|
|
285
|
+
},
|
|
286
|
+
isDeleted: () => {
|
|
287
|
+
if (config.softDeletes !== true)
|
|
288
|
+
return false;
|
|
289
|
+
const deleteAtColumn = config.deleteAtColumn ?? 'deleted_at';
|
|
290
|
+
const deletedValue = attrs[deleteAtColumn];
|
|
291
|
+
return deletedValue !== null && deletedValue !== undefined;
|
|
292
|
+
},
|
|
293
|
+
});
|
|
166
294
|
/**
|
|
167
295
|
* Create a new model instance
|
|
168
296
|
*/
|
|
169
|
-
|
|
170
|
-
export const createModel = (config, attributes = {}) => {
|
|
297
|
+
export const createModel = (config, attributes = {}, options) => {
|
|
171
298
|
const connection = config.connection ?? DEFAULTS.CONNECTION;
|
|
172
299
|
const getDb = () => useDatabase(undefined, connection);
|
|
173
300
|
const attrs = {};
|
|
174
301
|
const relations = {}; // Store eager loaded relations
|
|
175
302
|
let original = {};
|
|
176
|
-
let isExists =
|
|
303
|
+
let isExists = options?.exists === true;
|
|
177
304
|
const dirtyFields = new Set();
|
|
178
|
-
|
|
305
|
+
if (options?.hydrate === true) {
|
|
306
|
+
hydrateAttributes(config, attrs, attributes);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
fillAttributes(config, attrs, attributes);
|
|
310
|
+
}
|
|
179
311
|
original = { ...attrs };
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
},
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (original[key] === castedValue) {
|
|
198
|
-
dirtyFields.delete(key);
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
dirtyFields.add(key);
|
|
202
|
-
}
|
|
203
|
-
return model;
|
|
204
|
-
},
|
|
205
|
-
getAttribute: (key) => {
|
|
206
|
-
// Check relations first if it's a relation name
|
|
207
|
-
if (relations[key] !== undefined)
|
|
208
|
-
return relations[key];
|
|
209
|
-
return applyAccessor(config, key, attrs);
|
|
210
|
-
},
|
|
211
|
-
getAttributes: () => ({ ...attrs }),
|
|
212
|
-
// Relationship helpers
|
|
213
|
-
setRelation: (name, value) => {
|
|
214
|
-
relations[name] = value;
|
|
215
|
-
},
|
|
216
|
-
getRelation: (name) => relations[name],
|
|
217
|
-
// remove in production - use saveChanges pattern
|
|
218
|
-
save: async () => performModelSave(model, config, attrs, getDb, {
|
|
219
|
-
isExists,
|
|
220
|
-
setExists: (v) => {
|
|
221
|
-
isExists = v;
|
|
312
|
+
let modelApi = {};
|
|
313
|
+
modelApi = {
|
|
314
|
+
...createAttributeApi(config, attrs, relations, {
|
|
315
|
+
dirtyFields,
|
|
316
|
+
getModel: () => modelApi,
|
|
317
|
+
getOriginal: () => original,
|
|
318
|
+
exists: () => isExists,
|
|
319
|
+
setExists: (exists) => {
|
|
320
|
+
isExists = exists;
|
|
321
|
+
},
|
|
322
|
+
}),
|
|
323
|
+
...createLifecycleApi(config, attrs, getDb, {
|
|
324
|
+
dirtyFields,
|
|
325
|
+
getModel: () => modelApi,
|
|
326
|
+
exists: () => isExists,
|
|
327
|
+
setExists: (exists) => {
|
|
328
|
+
isExists = exists;
|
|
222
329
|
},
|
|
223
|
-
|
|
224
|
-
original =
|
|
330
|
+
setOriginal: (value) => {
|
|
331
|
+
original = value;
|
|
225
332
|
},
|
|
226
|
-
clearDirty: () => dirtyFields.clear(),
|
|
227
333
|
}),
|
|
228
|
-
// remove in production - use delete pattern
|
|
229
|
-
delete: async () => performModelDelete(model, config, getDb, isExists),
|
|
230
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
231
|
-
restore: async () => {
|
|
232
|
-
if (config.softDeletes !== true || !isExists)
|
|
233
|
-
return false;
|
|
234
|
-
const deleteAtColumn = config.deleteAtColumn ?? 'deleted_at';
|
|
235
|
-
attrs[deleteAtColumn] = null;
|
|
236
|
-
dirtyFields.add(deleteAtColumn);
|
|
237
|
-
return true;
|
|
238
|
-
},
|
|
239
|
-
forceDelete: async () => {
|
|
240
|
-
if (!isExists)
|
|
241
|
-
return false;
|
|
242
|
-
await runObservers(config, 'deleting', model);
|
|
243
|
-
await runObservers(config, 'deleted', model);
|
|
244
|
-
return true;
|
|
245
|
-
},
|
|
246
|
-
isDeleted: () => {
|
|
247
|
-
if (config.softDeletes !== true)
|
|
248
|
-
return false;
|
|
249
|
-
const deleteAtColumn = config.deleteAtColumn ?? 'deleted_at';
|
|
250
|
-
const deletedValue = attrs[deleteAtColumn];
|
|
251
|
-
return deletedValue !== null && deletedValue !== undefined;
|
|
252
|
-
},
|
|
253
|
-
toJSON: () => createModelJSON(config, attrs),
|
|
254
|
-
isDirty: (key) => {
|
|
255
|
-
if (key !== undefined) {
|
|
256
|
-
return dirtyFields.has(key);
|
|
257
|
-
}
|
|
258
|
-
return dirtyFields.size > 0;
|
|
259
|
-
},
|
|
260
|
-
getTable: () => config.table,
|
|
261
|
-
exists: () => isExists,
|
|
262
|
-
setExists: (exists) => {
|
|
263
|
-
isExists = exists;
|
|
264
|
-
},
|
|
265
334
|
};
|
|
266
|
-
Object.assign(
|
|
267
|
-
return
|
|
335
|
+
Object.assign(modelApi, createModelRelationships(config));
|
|
336
|
+
return modelApi;
|
|
268
337
|
};
|
|
269
338
|
/**
|
|
270
339
|
* Get a query builder for a table
|
|
@@ -288,9 +357,7 @@ export const find = async (config, id) => {
|
|
|
288
357
|
const result = await builder.first();
|
|
289
358
|
if (result === null)
|
|
290
359
|
return null;
|
|
291
|
-
|
|
292
|
-
model.setExists(true);
|
|
293
|
-
return model;
|
|
360
|
+
return createModel(config, result, { hydrate: true, exists: true });
|
|
294
361
|
};
|
|
295
362
|
/**
|
|
296
363
|
* Get all records for a model
|
|
@@ -299,11 +366,7 @@ export const all = async (config) => {
|
|
|
299
366
|
const db = useDatabase(undefined, config.connection ?? DEFAULTS.CONNECTION);
|
|
300
367
|
const builder = QueryBuilder.create(config.table, db, buildSoftDeleteOptions(config));
|
|
301
368
|
const results = await builder.get();
|
|
302
|
-
return results.map((result) => {
|
|
303
|
-
const model = createModel(config, result);
|
|
304
|
-
model.setExists(true);
|
|
305
|
-
return model;
|
|
306
|
-
});
|
|
369
|
+
return results.map((result) => createModel(config, result, { hydrate: true, exists: true }));
|
|
307
370
|
};
|
|
308
371
|
const bindUnboundMethods = (model, methods) => {
|
|
309
372
|
const bound = {};
|
|
@@ -333,8 +396,7 @@ const createModelBuilder = (cfg) => {
|
|
|
333
396
|
};
|
|
334
397
|
const createHydrator = (cfg, attach) => {
|
|
335
398
|
return (attributes) => {
|
|
336
|
-
const model = createModel(cfg, attributes);
|
|
337
|
-
model.setExists(true);
|
|
399
|
+
const model = createModel(cfg, attributes, { hydrate: true, exists: true });
|
|
338
400
|
return attach(model);
|
|
339
401
|
};
|
|
340
402
|
};
|
|
@@ -397,8 +459,30 @@ const hydrateAndLoadRelations = async (raw, eagerBuilder, hydrateModel) => {
|
|
|
397
459
|
await loadEagerCounts(eagerBuilder, models);
|
|
398
460
|
return models;
|
|
399
461
|
};
|
|
462
|
+
const hydrateOneAndLoadRelations = async (raw, eagerBuilder, hydrateModel) => {
|
|
463
|
+
if (!isRecord(raw))
|
|
464
|
+
return raw;
|
|
465
|
+
const model = hydrateModel(raw);
|
|
466
|
+
await loadEagerRelations(eagerBuilder, [model]);
|
|
467
|
+
await loadEagerCounts(eagerBuilder, [model]);
|
|
468
|
+
return model;
|
|
469
|
+
};
|
|
400
470
|
const wrapBuilderGetForEagerLoading = (builder, hydrateModel) => {
|
|
401
471
|
const eagerBuilder = builder;
|
|
472
|
+
if (typeof eagerBuilder.first === 'function') {
|
|
473
|
+
const originalFirst = eagerBuilder.first.bind(builder);
|
|
474
|
+
eagerBuilder.first = async () => {
|
|
475
|
+
const raw = await originalFirst();
|
|
476
|
+
return hydrateOneAndLoadRelations(raw, eagerBuilder, hydrateModel);
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
if (typeof eagerBuilder.firstOrFail === 'function') {
|
|
480
|
+
const originalFirstOrFail = eagerBuilder.firstOrFail.bind(builder);
|
|
481
|
+
eagerBuilder.firstOrFail = async (message) => {
|
|
482
|
+
const raw = await originalFirstOrFail(message);
|
|
483
|
+
return hydrateOneAndLoadRelations(raw, eagerBuilder, hydrateModel);
|
|
484
|
+
};
|
|
485
|
+
}
|
|
402
486
|
const originalGet = eagerBuilder.get.bind(builder);
|
|
403
487
|
eagerBuilder.get = async () => {
|
|
404
488
|
const raw = await originalGet();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryBuilder.d.ts","sourceRoot":"","sources":["../../../src/orm/QueryBuilder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGtE,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGzC,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B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CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAChG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAi+CD;;;;;GAKG;AACH,eAAO,MAAM,YAAY;IACvB;;OAEG;sBAEU,MAAM,GAAG,SAAS,OACxB,SAAS,YACL,mBAAmB,GAC3B,aAAa;IA8BhB;;;;;OAKG;aACY,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;EAIxC,CAAC"}
|
package/src/orm/QueryBuilder.js
CHANGED
|
@@ -718,6 +718,16 @@ const setRelationsFromBuckets = (models, relation, localKey, buckets, isMany) =>
|
|
|
718
718
|
}
|
|
719
719
|
}
|
|
720
720
|
};
|
|
721
|
+
const setBelongsToRelations = (models, relation, foreignKey, relatedMap) => {
|
|
722
|
+
for (const model of models) {
|
|
723
|
+
const relatedId = model.getAttribute(foreignKey);
|
|
724
|
+
if (!isKeyValue(relatedId)) {
|
|
725
|
+
model.setRelation(relation, null);
|
|
726
|
+
continue;
|
|
727
|
+
}
|
|
728
|
+
model.setRelation(relation, relatedMap.get(relatedId) ?? null);
|
|
729
|
+
}
|
|
730
|
+
};
|
|
721
731
|
const buildParentToThroughIds = (throughResults, throughForeignKey, secondLocalKey) => {
|
|
722
732
|
const parentToThroughIds = new Map();
|
|
723
733
|
for (const throughItem of throughResults) {
|
|
@@ -902,6 +912,72 @@ const loadThroughRelation = async (models, relation, rel, constraint) => {
|
|
|
902
912
|
setThroughRelations(models, relation, localKey, parentToThroughIds, relatedBuckets, isMany);
|
|
903
913
|
return true;
|
|
904
914
|
};
|
|
915
|
+
const loadBelongsToRelation = async (models, relation, rel, constraint) => {
|
|
916
|
+
if (rel.type !== 'belongsTo')
|
|
917
|
+
return false;
|
|
918
|
+
const foreignKey = rel.foreignKey;
|
|
919
|
+
const ownerKey = rel.localKey;
|
|
920
|
+
if (!isNonEmptyString(foreignKey) || !isNonEmptyString(ownerKey))
|
|
921
|
+
return true;
|
|
922
|
+
const relatedModel = rel.related;
|
|
923
|
+
if (typeof relatedModel.query !== 'function')
|
|
924
|
+
return true;
|
|
925
|
+
const ids = getModelIds(models, foreignKey);
|
|
926
|
+
if (ids.length === 0) {
|
|
927
|
+
setBelongsToRelations(models, relation, foreignKey, new Map());
|
|
928
|
+
return true;
|
|
929
|
+
}
|
|
930
|
+
const relatedQuery = applyConstraint(relatedModel.query(), constraint);
|
|
931
|
+
const relatedResults = await relatedQuery.whereIn(ownerKey, ids).get();
|
|
932
|
+
const relatedMap = buildSingleMap(relatedResults, ownerKey);
|
|
933
|
+
setBelongsToRelations(models, relation, foreignKey, relatedMap);
|
|
934
|
+
return true;
|
|
935
|
+
};
|
|
936
|
+
const BELONGS_TO_MANY_PARENT_KEY_ALIAS = '__zin_belongs_to_many_parent_key';
|
|
937
|
+
const resolveRelatedTableName = (relatedModel) => {
|
|
938
|
+
if (typeof relatedModel.getTable === 'function') {
|
|
939
|
+
const tableName = relatedModel.getTable();
|
|
940
|
+
return isNonEmptyString(tableName) ? tableName : null;
|
|
941
|
+
}
|
|
942
|
+
if (typeof relatedModel.query !== 'function')
|
|
943
|
+
return null;
|
|
944
|
+
const query = relatedModel.query();
|
|
945
|
+
const tableName = query.getTable();
|
|
946
|
+
return isNonEmptyString(tableName) ? tableName : null;
|
|
947
|
+
};
|
|
948
|
+
const loadBelongsToManyRelation = async (models, relation, rel, constraint) => {
|
|
949
|
+
if (rel.type !== 'belongsToMany')
|
|
950
|
+
return false;
|
|
951
|
+
const throughTable = rel.throughTable;
|
|
952
|
+
const foreignKey = rel.foreignKey;
|
|
953
|
+
const relatedKey = rel.relatedKey;
|
|
954
|
+
const localKey = rel.localKey;
|
|
955
|
+
if (!isNonEmptyString(throughTable) ||
|
|
956
|
+
!isNonEmptyString(foreignKey) ||
|
|
957
|
+
!isNonEmptyString(relatedKey) ||
|
|
958
|
+
!isNonEmptyString(localKey)) {
|
|
959
|
+
return true;
|
|
960
|
+
}
|
|
961
|
+
const relatedModel = rel.related;
|
|
962
|
+
if (typeof relatedModel.query !== 'function')
|
|
963
|
+
return true;
|
|
964
|
+
const ids = getModelIds(models, localKey);
|
|
965
|
+
if (ids.length === 0) {
|
|
966
|
+
setRelationsFromBuckets(models, relation, localKey, new Map(), true);
|
|
967
|
+
return true;
|
|
968
|
+
}
|
|
969
|
+
const relatedTable = resolveRelatedTableName(relatedModel);
|
|
970
|
+
if (!isNonEmptyString(relatedTable))
|
|
971
|
+
return true;
|
|
972
|
+
const relatedQuery = applyConstraint(relatedModel.query(), constraint)
|
|
973
|
+
.join(throughTable, `${relatedTable}.id = ${throughTable}.${relatedKey}`)
|
|
974
|
+
.selectAs(`${throughTable}.${foreignKey}`, BELONGS_TO_MANY_PARENT_KEY_ALIAS)
|
|
975
|
+
.whereIn(`${throughTable}.${foreignKey}`, ids);
|
|
976
|
+
const relatedResults = await relatedQuery.get();
|
|
977
|
+
const relatedBuckets = buildBucketMap(relatedResults, BELONGS_TO_MANY_PARENT_KEY_ALIAS);
|
|
978
|
+
setRelationsFromBuckets(models, relation, localKey, relatedBuckets, true);
|
|
979
|
+
return true;
|
|
980
|
+
};
|
|
905
981
|
const loadStandardRelation = async (models, relation, rel, constraint) => {
|
|
906
982
|
const related = rel.related;
|
|
907
983
|
if (related === null || related === undefined)
|
|
@@ -942,6 +1018,14 @@ const loadRelation = async (models, relation, constraint) => {
|
|
|
942
1018
|
await loadThroughRelation(models, relation, rel, constraint);
|
|
943
1019
|
return;
|
|
944
1020
|
}
|
|
1021
|
+
if (type === 'belongsTo') {
|
|
1022
|
+
await loadBelongsToRelation(models, relation, rel, constraint);
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
if (type === 'belongsToMany') {
|
|
1026
|
+
await loadBelongsToManyRelation(models, relation, rel, constraint);
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
945
1029
|
await loadStandardRelation(models, relation, rel, constraint);
|
|
946
1030
|
};
|
|
947
1031
|
function attachRelationshipMethods(builder, state, db) {
|
|
@@ -988,7 +1072,7 @@ function attachWriteMethods(builder, state, db) {
|
|
|
988
1072
|
// For multi-row inserts, use the insertedRecords array
|
|
989
1073
|
return {
|
|
990
1074
|
id: result.lastInsertId ??
|
|
991
|
-
(items.length === 1 ? items[0]?.['id'] ?? null : null),
|
|
1075
|
+
(items.length === 1 ? (items[0]?.['id'] ?? null) : null),
|
|
992
1076
|
affectedRows: result.rowCount,
|
|
993
1077
|
insertedRecords: items,
|
|
994
1078
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkerAdapterImports.d.ts","sourceRoot":"","sources":["../../../src/runtime/WorkerAdapterImports.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WorkerAdapterImports.d.ts","sourceRoot":"","sources":["../../../src/runtime/WorkerAdapterImports.ts"],"names":[],"mappings":"AA8BA,eAAO,MAAM,oBAAoB;;;EAG/B,CAAC"}
|
|
@@ -20,12 +20,7 @@ const tryImportProjectRuntime = async () => {
|
|
|
20
20
|
// via the @/ alias configured by the ZinTrust app templates.
|
|
21
21
|
const tryImportOptional = async () => {
|
|
22
22
|
await tryImportProjectRuntime();
|
|
23
|
-
|
|
24
|
-
await import('../zintrust.plugins.wg.js');
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
// Log and swallow errors since these are optional imports that may not exist in all projects.
|
|
28
|
-
}
|
|
23
|
+
await import('./WorkerProjectPlugins.js');
|
|
29
24
|
};
|
|
30
25
|
const ready = await tryImportOptional();
|
|
31
26
|
export const WorkerAdapterImports = Object.freeze({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkerProjectPlugins.d.ts","sourceRoot":"","sources":["../../../src/runtime/WorkerProjectPlugins.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAE/B,eAAO,MAAM,oBAAoB;;EAE/B,CAAC;AAEH,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type DebuggerConfigApi = {
|
|
2
|
+
merge(overrides?: unknown): {
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
connection?: string;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
type DebuggerStorageApi = {
|
|
8
|
+
resolveStorage(db: unknown): unknown;
|
|
9
|
+
};
|
|
10
|
+
export declare const isAvailable: () => boolean;
|
|
11
|
+
export declare const DebuggerConfig: DebuggerConfigApi;
|
|
12
|
+
export declare const DebuggerStorage: DebuggerStorageApi;
|
|
13
|
+
export declare const registerDebuggerRoutes: (router: unknown, storage: unknown, options?: {
|
|
14
|
+
basePath?: string;
|
|
15
|
+
middleware?: ReadonlyArray<string>;
|
|
16
|
+
}) => void;
|
|
17
|
+
export declare const ensureSystemDebuggerRegistered: () => Promise<void>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=system-debugger-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-debugger-runtime.d.ts","sourceRoot":"","sources":["../../../../src/runtime/plugins/system-debugger-runtime.ts"],"names":[],"mappings":"AAAA,KAAK,iBAAiB,GAAG;IACvB,KAAK,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACxE,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,cAAc,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC;CACtC,CAAC;AA+BF,eAAO,MAAM,WAAW,QAAO,OAA6C,CAAC;AAE7E,eAAO,MAAM,cAAc,EAAE,iBACmC,CAAC;AAEjE,eAAO,MAAM,eAAe,EAAE,kBACoC,CAAC;AAEnE,eAAO,MAAM,sBAAsB,WAjCvB,OAAO,WACN,OAAO,YACN;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CAAE,KAChE,IA+ByE,CAAC;AAEjF,eAAO,MAAM,8BAA8B,QAAa,OAAO,CAAC,IAAI,CAGnE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const fallbackDebuggerConfig = Object.freeze({
|
|
2
|
+
merge: () => ({ enabled: false }),
|
|
3
|
+
});
|
|
4
|
+
const fallbackDebuggerStorage = Object.freeze({
|
|
5
|
+
resolveStorage: (_db) => undefined,
|
|
6
|
+
});
|
|
7
|
+
const fallbackRegisterDebuggerRoutes = (_router, _storage, _options) => undefined;
|
|
8
|
+
const systemDebuggerModule = await import('../../../packages/system-debugger/src/index.js')
|
|
9
|
+
.then((module) => module)
|
|
10
|
+
.catch(() => undefined);
|
|
11
|
+
export const isAvailable = () => systemDebuggerModule !== undefined;
|
|
12
|
+
export const DebuggerConfig = systemDebuggerModule?.DebuggerConfig ?? fallbackDebuggerConfig;
|
|
13
|
+
export const DebuggerStorage = systemDebuggerModule?.DebuggerStorage ?? fallbackDebuggerStorage;
|
|
14
|
+
export const registerDebuggerRoutes = systemDebuggerModule?.registerDebuggerRoutes ?? fallbackRegisterDebuggerRoutes;
|
|
15
|
+
export const ensureSystemDebuggerRegistered = async () => {
|
|
16
|
+
if (!isAvailable())
|
|
17
|
+
return;
|
|
18
|
+
await import('../../../packages/system-debugger/src/register.js').catch(() => undefined);
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-debugger.d.ts","sourceRoot":"","sources":["../../../../src/runtime/plugins/system-debugger.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const tryImport = async (specifier) => {
|
|
2
|
+
try {
|
|
3
|
+
await import(specifier);
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
const importedPackagePlugin = await tryImport('@zintrust/system-debugger/plugin');
|
|
11
|
+
if (!importedPackagePlugin) {
|
|
12
|
+
await import('../../../packages/system-debugger/src/plugin.js').catch(() => undefined);
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JwtManager.d.ts","sourceRoot":"","sources":["../../../src/security/JwtManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"JwtManager.d.ts","sourceRoot":"","sources":["../../../src/security/JwtManager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAGjE,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAEvD,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,UAAU,CAAC,UAAU,EAAE,MA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