velocious 1.0.647 → 1.0.648
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/README.md +1 -1
- package/build/environment-handlers/node/cli/commands/generate/frontend-models.js +33 -5
- package/build/frontend-models/base.js +11 -0
- package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.d.ts.map +1 -1
- package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.js +31 -6
- package/build/src/frontend-models/base.d.ts +10 -0
- package/build/src/frontend-models/base.d.ts.map +1 -1
- package/build/src/frontend-models/base.js +11 -1
- package/package.json +1 -1
- package/src/environment-handlers/node/cli/commands/generate/frontend-models.js +33 -5
- package/src/frontend-models/base.js +11 -0
package/package.json
CHANGED
|
@@ -313,6 +313,11 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
313
313
|
}
|
|
314
314
|
const collectionCommands = modelConfig.collectionCommands
|
|
315
315
|
const memberCommands = modelConfig.memberCommands
|
|
316
|
+
|
|
317
|
+
if (Object.hasOwn(collectionCommands, "onDestroy")) {
|
|
318
|
+
throw new Error(`Frontend model collection command '${className}.onDestroy' collides with the generated lifecycle hook`)
|
|
319
|
+
}
|
|
320
|
+
|
|
316
321
|
const declaredCommandMetadata = modelConfig.commandMetadata || {}
|
|
317
322
|
const commandMetadata = await this.commandMetadataWithResourceJsDoc({
|
|
318
323
|
commandMetadata: declaredCommandMetadata,
|
|
@@ -632,16 +637,39 @@ export default class DbGenerateFrontendModels extends BaseCommand {
|
|
|
632
637
|
}
|
|
633
638
|
}
|
|
634
639
|
|
|
640
|
+
fileContent += "\n"
|
|
641
|
+
fileContent += " /**\n"
|
|
642
|
+
fileContent += " * Registers a class-level destroy callback.\n"
|
|
643
|
+
fileContent += " * @overload\n"
|
|
644
|
+
fileContent += ` * @param {(payload: {id: ${eventPrimaryKeyValueType}}) => void} callback - Event callback.\n`
|
|
645
|
+
fileContent += ` * @param {import(${JSON.stringify(importPath)}).FrontendModelEventOptions} [options] - Destroy event options.\n`
|
|
646
|
+
fileContent += " * @returns {Promise<() => void>} - Unsubscribe callback.\n"
|
|
647
|
+
fileContent += " */\n"
|
|
648
|
+
fileContent += " /**\n"
|
|
649
|
+
fileContent += ` * @template {import(${JSON.stringify(importPath)}).FrontendModelClass} T\n`
|
|
650
|
+
fileContent += " * @overload\n"
|
|
651
|
+
fileContent += " * @this {T}\n"
|
|
652
|
+
fileContent += ` * @param {(payload: {id: import(${JSON.stringify(importPath)}).FrontendModelEventPrimaryKeyValueFor<InstanceType<T>>}) => void} callback - Event callback.\n`
|
|
653
|
+
fileContent += ` * @param {import(${JSON.stringify(importPath)}).FrontendModelEventOptions} [options] - Destroy event options.\n`
|
|
654
|
+
fileContent += " * @returns {Promise<() => void>} - Unsubscribe callback.\n"
|
|
655
|
+
fileContent += " */\n"
|
|
656
|
+
fileContent += " /**\n"
|
|
657
|
+
fileContent += " * Implements class-level destroy callback registration.\n"
|
|
658
|
+
fileContent += " * @param {(payload: {id: never}) => void} callback - Type-erased event callback.\n"
|
|
659
|
+
fileContent += ` * @param {import(${JSON.stringify(importPath)}).FrontendModelEventOptions} [options] - Destroy event options.\n`
|
|
660
|
+
fileContent += " * @returns {Promise<() => void>} - Unsubscribe callback.\n"
|
|
661
|
+
fileContent += " */\n"
|
|
662
|
+
fileContent += " static async onDestroy(callback, options = {}) {\n"
|
|
663
|
+
fileContent += " return await this._registerDestroyEventCallback(callback, options)\n"
|
|
664
|
+
fileContent += " }\n"
|
|
665
|
+
|
|
635
666
|
fileContent += "}\n"
|
|
636
667
|
fileContent += "\n"
|
|
637
668
|
fileContent += `FrontendModelBase.registerModel(${className})\n`
|
|
638
669
|
fileContent += "\n"
|
|
639
|
-
|
|
640
|
-
fileContent += `const Generated${className}Class = /** @type {Omit<typeof ${className}, "onDestroy"> & {onDestroy: (callback: (payload: {id: ${eventPrimaryKeyValueType}}) => void, options?: import(${JSON.stringify(importPath)}).FrontendModelEventOptions) => Promise<() => void>}} */ (/** @type {unknown} */ (${className}))\n`
|
|
641
|
-
fileContent += "\n"
|
|
642
|
-
fileContent += `export {Generated${className}Class as ${className}}\n`
|
|
670
|
+
fileContent += `export {${className}}\n`
|
|
643
671
|
fileContent += "\n"
|
|
644
|
-
fileContent += `export default
|
|
672
|
+
fileContent += `export default ${className}\n`
|
|
645
673
|
|
|
646
674
|
return fileContent
|
|
647
675
|
}
|
|
@@ -4012,6 +4012,17 @@ export default class FrontendModelBase {
|
|
|
4012
4012
|
* @returns {Promise<() => void>} - Unsubscribe callback.
|
|
4013
4013
|
*/
|
|
4014
4014
|
static async onDestroy(callback, options = {}) {
|
|
4015
|
+
return await this._registerDestroyEventCallback(callback, options)
|
|
4016
|
+
}
|
|
4017
|
+
|
|
4018
|
+
/**
|
|
4019
|
+
* Registers a destroy callback after the public model-specific signature has been checked.
|
|
4020
|
+
* @this {FrontendModelClass}
|
|
4021
|
+
* @param {(payload: {id: never}) => void} callback - Type-erased event callback.
|
|
4022
|
+
* @param {import("./query.js").FrontendModelEventOptions} [options] - Destroy event options.
|
|
4023
|
+
* @returns {Promise<() => void>} - Unsubscribe callback.
|
|
4024
|
+
*/
|
|
4025
|
+
static async _registerDestroyEventCallback(callback, options = {}) {
|
|
4015
4026
|
assertNoDestroyEventFilter(this, options)
|
|
4016
4027
|
|
|
4017
4028
|
const {requestContext} = frontendModelEventOptionsPayload(this, options)
|