velocious 1.0.646 → 1.0.647

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.
Files changed (37) hide show
  1. package/README.md +1 -1
  2. package/build/environment-handlers/node/cli/commands/generate/frontend-models.js +24 -5
  3. package/build/frontend-models/base.js +51 -25
  4. package/build/frontend-models/event-hook-models.js +1 -1
  5. package/build/frontend-models/use-destroyed-event.js +2 -2
  6. package/build/frontend-models/use-model-class-event.js +2 -2
  7. package/build/frontend-models/use-updated-event.js +2 -2
  8. package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.d.ts +9 -0
  9. package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.d.ts.map +1 -1
  10. package/build/src/environment-handlers/node/cli/commands/generate/frontend-models.js +22 -5
  11. package/build/src/frontend-models/base.d.ts +43 -38
  12. package/build/src/frontend-models/base.d.ts.map +1 -1
  13. package/build/src/frontend-models/base.js +49 -26
  14. package/build/src/frontend-models/event-hook-models.d.ts +1 -1
  15. package/build/src/frontend-models/event-hook-models.d.ts.map +1 -1
  16. package/build/src/frontend-models/event-hook-models.js +2 -2
  17. package/build/src/frontend-models/use-destroyed-event.d.ts +2 -2
  18. package/build/src/frontend-models/use-destroyed-event.d.ts.map +1 -1
  19. package/build/src/frontend-models/use-destroyed-event.js +3 -3
  20. package/build/src/frontend-models/use-model-class-event.d.ts +2 -2
  21. package/build/src/frontend-models/use-model-class-event.d.ts.map +1 -1
  22. package/build/src/frontend-models/use-model-class-event.js +3 -3
  23. package/build/src/frontend-models/use-updated-event.d.ts +2 -2
  24. package/build/src/frontend-models/use-updated-event.d.ts.map +1 -1
  25. package/build/src/frontend-models/use-updated-event.js +3 -3
  26. package/build/src/testing/browser-frontend-model-event-hook-scenarios.d.ts +10 -8
  27. package/build/src/testing/browser-frontend-model-event-hook-scenarios.d.ts.map +1 -1
  28. package/build/src/testing/browser-frontend-model-event-hook-scenarios.js +19 -11
  29. package/build/testing/browser-frontend-model-event-hook-scenarios.js +18 -10
  30. package/package.json +1 -1
  31. package/src/environment-handlers/node/cli/commands/generate/frontend-models.js +24 -5
  32. package/src/frontend-models/base.js +51 -25
  33. package/src/frontend-models/event-hook-models.js +1 -1
  34. package/src/frontend-models/use-destroyed-event.js +2 -2
  35. package/src/frontend-models/use-model-class-event.js +2 -2
  36. package/src/frontend-models/use-updated-event.js +2 -2
  37. package/src/testing/browser-frontend-model-event-hook-scenarios.js +18 -10
@@ -21,6 +21,9 @@ import {forcedNonBlankString} from "typanic"
21
21
  import {modelPrimaryKeyCacheKey, modelPrimaryKeyConditions, readModelPrimaryKeyValue, scalarModelPrimaryKey, scalarModelPrimaryKeyValue} from "../utils/model-primary-key.js"
22
22
  import {readPayloadAssociationCount, readPayloadComputedAbility, readPayloadQueryData, setPayloadAssociationCount, setPayloadComputedAbility, setPayloadQueryData} from "../record-payload-values.js"
23
23
 
24
+ /** @typedef {string | import("../utils/model-primary-key.js").CompositeModelPrimaryKeyValue} FrontendModelEventPrimaryKeyValue */
25
+ /** @typedef {import("./query.js").FrontendModelEventOptions} FrontendModelEventOptions */
26
+
24
27
  /**
25
28
  * Frontend model relationship helper type. Returned by `getRelationshipByName`,
26
29
  * which generated models immediately cast to their concrete relationship type
@@ -32,11 +35,14 @@ import {readPayloadAssociationCount, readPayloadComputedAbility, readPayloadQuer
32
35
  */
33
36
  /**
34
37
  * Defines this typedef.
35
- * @typedef {{callback: (payload: {id: string | import("../utils/model-primary-key.js").CompositeModelPrimaryKeyValue, model: FrontendModelBase}) => void, eventFilterKey: string | null, eventFilterPayload: import("./query.js").FrontendModelEventFilterPayload | null, projectionPayload: import("./query.js").FrontendModelProjectionPayload}} FrontendModelModelEventCallbackEntry
38
+ * @template {import("../utils/model-primary-key.js").ModelPrimaryKeyValue} [PrimaryKeyValue=import("../utils/model-primary-key.js").ModelPrimaryKeyValue]
39
+ * @template {FrontendModelBase} [Model=FrontendModelBase]
40
+ * @typedef {{callback: (payload: {id: PrimaryKeyValue, model: Model}) => void, eventFilterKey: string | null, eventFilterPayload: import("./query.js").FrontendModelEventFilterPayload | null, projectionPayload: import("./query.js").FrontendModelProjectionPayload}} FrontendModelModelEventCallbackEntry
36
41
  */
37
42
  /**
38
43
  * Defines this typedef.
39
- * @typedef {{callback: (payload: {id: string | import("../utils/model-primary-key.js").CompositeModelPrimaryKeyValue}) => void}} FrontendModelDestroyEventCallbackEntry
44
+ * @template {import("../utils/model-primary-key.js").ModelPrimaryKeyValue} [PrimaryKeyValue=import("../utils/model-primary-key.js").ModelPrimaryKeyValue]
45
+ * @typedef {{callback: (payload: {id: PrimaryKeyValue}) => void}} FrontendModelDestroyEventCallbackEntry
40
46
  */
41
47
  /**
42
48
  * FrontendModelCommandType type.
@@ -111,16 +117,22 @@ import {readPayloadAssociationCount, readPayloadComputedAbility, readPayloadQuer
111
117
  * invariance. Defaulting to `any` lets any subclass satisfy the constraint while
112
118
  * the methods' own `@template T` still captures the precise calling class for
113
119
  * their return types.
114
- * @template {FrontendModelBase} [T=FrontendModelBase<any, any, any>]
120
+ * @template {FrontendModelBase} [T=FrontendModelBase<any, any, any, any, any>]
115
121
  * @template {object} [Attributes=any]
116
122
  * @template {object} [CreateAttributes=any]
117
123
  * @typedef {{new (): T, create(attributes?: CreateAttributes): Promise<T>} & Omit<typeof FrontendModelBase, "create" | "prototype">} FrontendModelClass
118
124
  */
125
+ /** @typedef {Omit<FrontendModelClass<FrontendModelBase<any, any, any, any, string>>, "onDestroy"> & {onDestroy: (callback: (payload: {id: string}) => void, options?: import("./query.js").FrontendModelEventOptions) => Promise<() => void>}} FrontendModelScalarEventClass */
119
126
  /**
120
127
  * Create attributes accepted by a frontend model instance.
121
128
  * @template {FrontendModelBase} T
122
129
  * @typedef {T extends FrontendModelBase<Record<string, FrontendModelAttributeValue>, infer CreateAttributes, infer _UpdateAttributes> ? CreateAttributes : Record<string, FrontendModelAttributeValue>} FrontendModelCreateAttributesFor
123
130
  */
131
+ /**
132
+ * Lifecycle event identity exposed by a concrete frontend model.
133
+ * @template {FrontendModelBase} T
134
+ * @typedef {T extends FrontendModelBase<any, any, any, any, infer EventPrimaryKeyValue> ? EventPrimaryKeyValue : FrontendModelEventPrimaryKeyValue} FrontendModelEventPrimaryKeyValueFor
135
+ */
124
136
  /**
125
137
  * Loaded instance type for relationship helper generics. Older generated
126
138
  * frontend models passed model classes into relationship helpers, while newer
@@ -1432,7 +1444,7 @@ function frontendModelMatchedEventFilterKeys(body) {
1432
1444
 
1433
1445
  /**
1434
1446
  * Runs frontend model event entry matches.
1435
- * @param {FrontendModelModelEventCallbackEntry} entry - Callback entry.
1447
+ * @param {FrontendModelModelEventCallbackEntry<any, any>} entry - Callback entry.
1436
1448
  * @param {Set<string>} matchedEventFilterKeys - Backend matched filter keys.
1437
1449
  * @returns {boolean} Whether the callback should receive the event.
1438
1450
  */
@@ -1478,19 +1490,19 @@ class FrontendModelEventSubscription {
1478
1490
  this.requestContext = requestContext
1479
1491
  /**
1480
1492
  * Narrows the runtime value to the documented type.
1481
- * @type {Set<FrontendModelModelEventCallbackEntry>} */
1493
+ * @type {Set<FrontendModelModelEventCallbackEntry<any, any>>} */
1482
1494
  this.classCreateCallbacks = new Set()
1483
1495
  /**
1484
1496
  * Narrows the runtime value to the documented type.
1485
- * @type {Set<FrontendModelModelEventCallbackEntry>} */
1497
+ * @type {Set<FrontendModelModelEventCallbackEntry<any, any>>} */
1486
1498
  this.classUpdateCallbacks = new Set()
1487
1499
  /**
1488
1500
  * Narrows the runtime value to the documented type.
1489
- * @type {Set<FrontendModelDestroyEventCallbackEntry>} */
1501
+ * @type {Set<FrontendModelDestroyEventCallbackEntry<never>>} */
1490
1502
  this.classDestroyCallbacks = new Set()
1491
1503
  /**
1492
1504
  * Narrows the runtime value to the documented type.
1493
- * @type {Map<string, {instance: FrontendModelBase, updateCallbacks: Set<FrontendModelModelEventCallbackEntry>, destroyCallbacks: Set<FrontendModelDestroyEventCallbackEntry>}>} */
1505
+ * @type {Map<string, {instance: FrontendModelBase, updateCallbacks: Set<FrontendModelModelEventCallbackEntry<any, any>>, destroyCallbacks: Set<FrontendModelDestroyEventCallbackEntry<any>>}>} */
1494
1506
  this.instanceListeners = new Map()
1495
1507
  /**
1496
1508
  * Narrows the runtime value to the documented type.
@@ -1573,7 +1585,7 @@ class FrontendModelEventSubscription {
1573
1585
 
1574
1586
  /**
1575
1587
  * Runs register class callback.
1576
- * @template {FrontendModelModelEventCallbackEntry | FrontendModelDestroyEventCallbackEntry} T
1588
+ * @template {FrontendModelModelEventCallbackEntry<any, any> | FrontendModelDestroyEventCallbackEntry<never>} T
1577
1589
  * @param {Set<T>} callbacks - Callback set for the event type.
1578
1590
  * @param {T} entry - Callback entry.
1579
1591
  * @returns {Promise<() => void>} - Unsubscribe callback.
@@ -1687,7 +1699,9 @@ class FrontendModelEventSubscription {
1687
1699
  deleteFrontendModelInstanceListener(this, listener)
1688
1700
  }
1689
1701
  for (const entry of this.classDestroyCallbacks) {
1690
- try { entry.callback({id: identity}) } catch (error) { console.error(error) }
1702
+ try {
1703
+ /** @type {(payload: {id: import("../utils/model-primary-key.js").ModelPrimaryKeyValue}) => void} */ (entry.callback)({id: identity})
1704
+ } catch (error) { console.error(error) }
1691
1705
  }
1692
1706
  return
1693
1707
  }
@@ -1833,7 +1847,7 @@ function frontendModelEventRequestContext(requestContext) {
1833
1847
  * @param {FrontendModelEventSubscription} sub - Event subscription bucket.
1834
1848
  * @param {string} id - Model id.
1835
1849
  * @param {FrontendModelBase} instance - Listener instance.
1836
- * @returns {{instance: FrontendModelBase, updateCallbacks: Set<FrontendModelModelEventCallbackEntry>, destroyCallbacks: Set<FrontendModelDestroyEventCallbackEntry>}} - Instance listener bucket.
1850
+ * @returns {{instance: FrontendModelBase, updateCallbacks: Set<FrontendModelModelEventCallbackEntry<any, any>>, destroyCallbacks: Set<FrontendModelDestroyEventCallbackEntry<any>>}} - Instance listener bucket.
1837
1851
  */
1838
1852
  function ensureFrontendModelInstanceListener(sub, id, instance) {
1839
1853
  let listener = sub.instanceListeners.get(id)
@@ -2411,6 +2425,8 @@ function assertDefinedFindByConditionValue(value, keyPath) {
2411
2425
  * @template {object} [Attributes=any]
2412
2426
  * @template {object} [CreateAttributes=any]
2413
2427
  * @template {object} [UpdateAttributes=any]
2428
+ * @template {import("../utils/model-primary-key.js").ModelPrimaryKeyValue} [PrimaryKeyValue=import("../utils/model-primary-key.js").ModelPrimaryKeyValue]
2429
+ * @template {import("../utils/model-primary-key.js").ModelPrimaryKeyValue} [EventPrimaryKeyValue=PrimaryKeyValue]
2414
2430
  */
2415
2431
  export default class FrontendModelBase {
2416
2432
  /**
@@ -2968,13 +2984,13 @@ export default class FrontendModelBase {
2968
2984
 
2969
2985
  /**
2970
2986
  * Runs primary key value.
2971
- * @returns {import("../utils/model-primary-key.js").ModelPrimaryKeyValue} - Primary key value.
2987
+ * @returns {PrimaryKeyValue} - Primary key value.
2972
2988
  */
2973
2989
  primaryKeyValue() {
2974
2990
  const ModelClass = frontendModelClassFor(this)
2975
2991
  const primaryKey = ModelClass.primaryKey()
2976
2992
 
2977
- return readModelPrimaryKeyValue(primaryKey, (attributeName) => {
2993
+ return /** @type {PrimaryKeyValue} */ (readModelPrimaryKeyValue(primaryKey, (attributeName) => {
2978
2994
  const value = this.readAttribute(attributeName)
2979
2995
 
2980
2996
  if (value === undefined || value === null) {
@@ -2982,7 +2998,7 @@ export default class FrontendModelBase {
2982
2998
  }
2983
2999
 
2984
3000
  return value
2985
- })
3001
+ }))
2986
3002
  }
2987
3003
 
2988
3004
  /**
@@ -2996,13 +3012,13 @@ export default class FrontendModelBase {
2996
3012
 
2997
3013
  /**
2998
3014
  * Returns the identity represented by the last persisted frontend attributes.
2999
- * @returns {import("../utils/model-primary-key.js").ModelPrimaryKeyValue} - Persisted primary-key value.
3015
+ * @returns {PrimaryKeyValue} - Persisted primary-key value.
3000
3016
  */
3001
3017
  persistedPrimaryKeyValue() {
3002
3018
  const ModelClass = frontendModelClassFor(this)
3003
3019
  const primaryKey = ModelClass.primaryKey()
3004
3020
 
3005
- return readModelPrimaryKeyValue(primaryKey, (attributeName) => {
3021
+ return /** @type {PrimaryKeyValue} */ (readModelPrimaryKeyValue(primaryKey, (attributeName) => {
3006
3022
  const value = this._persistedAttributes[attributeName]
3007
3023
 
3008
3024
  if (value === undefined || value === null) {
@@ -3010,7 +3026,7 @@ export default class FrontendModelBase {
3010
3026
  }
3011
3027
 
3012
3028
  return value
3013
- })
3029
+ }))
3014
3030
  }
3015
3031
 
3016
3032
  /**
@@ -3951,8 +3967,9 @@ export default class FrontendModelBase {
3951
3967
  * accepted, future `create` events for this model are delivered
3952
3968
  * without re-checking per-record visibility. Query options can still
3953
3969
  * narrow which events reach this callback.
3954
- * @this {FrontendModelClass}
3955
- * @param {(payload: {id: string | import("../utils/model-primary-key.js").CompositeModelPrimaryKeyValue, model: FrontendModelBase}) => void} callback - Event callback.
3970
+ * @template {FrontendModelClass} T
3971
+ * @this {T}
3972
+ * @param {(payload: {id: FrontendModelEventPrimaryKeyValueFor<InstanceType<T>>, model: InstanceType<T>}) => void} callback - Event callback.
3956
3973
  * @param {import("./query.js").FrontendModelEventOptions} [options] - Event query or record projection options.
3957
3974
  * @returns {Promise<() => void>} - Unsubscribe callback.
3958
3975
  */
@@ -3966,8 +3983,9 @@ export default class FrontendModelBase {
3966
3983
 
3967
3984
  /**
3968
3985
  * Class-level hook fired when any record of this model is updated.
3969
- * @this {FrontendModelClass}
3970
- * @param {(payload: {id: string | import("../utils/model-primary-key.js").CompositeModelPrimaryKeyValue, model: FrontendModelBase}) => void} callback - Event callback.
3986
+ * @template {FrontendModelClass} T
3987
+ * @this {T}
3988
+ * @param {(payload: {id: FrontendModelEventPrimaryKeyValueFor<InstanceType<T>>, model: InstanceType<T>}) => void} callback - Event callback.
3971
3989
  * @param {import("./query.js").FrontendModelEventOptions} [options] - Event query or record projection options.
3972
3990
  * @returns {Promise<() => void>} - Unsubscribe callback.
3973
3991
  */
@@ -3979,10 +3997,17 @@ export default class FrontendModelBase {
3979
3997
  return await sub.registerClassCallback(sub.classUpdateCallbacks, entry)
3980
3998
  }
3981
3999
 
4000
+ /**
4001
+ * @template {FrontendModelClass} T
4002
+ * @overload
4003
+ * @param {T} this - Concrete frontend model class.
4004
+ * @param {(payload: {id: FrontendModelEventPrimaryKeyValueFor<InstanceType<T>>}) => void} callback - Event callback.
4005
+ * @param {import("./query.js").FrontendModelEventOptions} [options] - Accepted for API symmetry; destroy events carry ids only.
4006
+ * @returns {Promise<() => void>} - Unsubscribe callback.
4007
+ */
3982
4008
  /**
3983
4009
  * Class-level hook fired when any record of this model is destroyed.
3984
- * @this {FrontendModelClass}
3985
- * @param {(payload: {id: string | import("../utils/model-primary-key.js").CompositeModelPrimaryKeyValue}) => void} callback - Event callback.
4010
+ * @param {(payload: {id: never}) => void} callback - Event callback erased at the overload implementation boundary.
3986
4011
  * @param {import("./query.js").FrontendModelEventOptions} [options] - Accepted for API symmetry; destroy events carry ids only.
3987
4012
  * @returns {Promise<() => void>} - Unsubscribe callback.
3988
4013
  */
@@ -3991,6 +4016,7 @@ export default class FrontendModelBase {
3991
4016
 
3992
4017
  const {requestContext} = frontendModelEventOptionsPayload(this, options)
3993
4018
  const sub = ensureFrontendModelEventSubscription(this, frontendModelEventRequestContext(requestContext))
4019
+ /** @type {FrontendModelDestroyEventCallbackEntry<never>} */
3994
4020
  const entry = {callback}
3995
4021
 
3996
4022
  return await sub.registerClassCallback(sub.classDestroyCallbacks, entry)
@@ -4001,7 +4027,7 @@ export default class FrontendModelBase {
4001
4027
  * instance's attributes are auto-merged with the broadcast payload
4002
4028
  * before the callback runs, so callers can read fresh values via
4003
4029
  * `this.someAttr()` without re-fetching.
4004
- * @param {(payload: {id: string | import("../utils/model-primary-key.js").CompositeModelPrimaryKeyValue, model: FrontendModelBase}) => void} callback - Event callback.
4030
+ * @param {(payload: {id: EventPrimaryKeyValue, model: FrontendModelBase<Attributes, CreateAttributes, UpdateAttributes, PrimaryKeyValue, EventPrimaryKeyValue>}) => void} callback - Event callback.
4005
4031
  * @param {import("./query.js").FrontendModelEventOptions} [options] - Event query or record projection options.
4006
4032
  * @returns {Promise<() => void>} - Unsubscribe callback.
4007
4033
  */
@@ -4030,7 +4056,7 @@ export default class FrontendModelBase {
4030
4056
 
4031
4057
  /**
4032
4058
  * Instance-level hook fired when THIS record is destroyed.
4033
- * @param {(payload: {id: string | import("../utils/model-primary-key.js").CompositeModelPrimaryKeyValue}) => void} callback - Event callback.
4059
+ * @param {(payload: {id: EventPrimaryKeyValue}) => void} callback - Event callback.
4034
4060
  * @param {import("./query.js").FrontendModelEventOptions} [options] - Accepted for API symmetry; destroy events carry ids only.
4035
4061
  * @returns {Promise<() => void>} - Unsubscribe callback.
4036
4062
  */
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  * FrontendModelInstance type.
5
- * @typedef {import("./base.js").default} FrontendModelInstance */
5
+ * @typedef {InstanceType<import("./base.js").FrontendModelClass>} FrontendModelInstance */
6
6
 
7
7
  /**
8
8
  * Model dependency ids.
@@ -13,13 +13,13 @@ import useModelClassEvent from "./use-model-class-event.js"
13
13
  * @typedef {import("./base.js").FrontendModelClass} FrontendModelClass */
14
14
  /**
15
15
  * FrontendModelInstance type.
16
- * @typedef {import("./base.js").default} FrontendModelInstance */
16
+ * @typedef {InstanceType<FrontendModelClass>} FrontendModelInstance */
17
17
  /**
18
18
  * FrontendModelClassDestroyEventPayload type.
19
19
  * @typedef {import("./use-model-class-event.js").FrontendModelDestroyEventPayload} FrontendModelClassDestroyEventPayload */
20
20
  /**
21
21
  * Defines this typedef.
22
- * @typedef {{id: string | import("../utils/model-primary-key.js").CompositeModelPrimaryKeyValue}} FrontendModelInstanceDestroyEventPayload */
22
+ * @typedef {{id: import("./base.js").FrontendModelEventPrimaryKeyValue}} FrontendModelInstanceDestroyEventPayload */
23
23
  /**
24
24
  * FrontendModelDestroyEventPayload type.
25
25
  * @typedef {FrontendModelClassDestroyEventPayload | FrontendModelInstanceDestroyEventPayload} FrontendModelDestroyEventPayload */
@@ -17,10 +17,10 @@ import {frontendModelRemoteRequestContextKey} from "./remote-request-context.js"
17
17
  * @typedef {"create" | "update" | "destroy"} FrontendModelClassEventName */
18
18
  /**
19
19
  * Defines this typedef.
20
- * @typedef {{id: string | import("../utils/model-primary-key.js").CompositeModelPrimaryKeyValue, model: FrontendModelInstance}} FrontendModelCreateUpdateEventPayload */
20
+ * @typedef {{id: import("./base.js").FrontendModelEventPrimaryKeyValue, model: FrontendModelInstance}} FrontendModelCreateUpdateEventPayload */
21
21
  /**
22
22
  * Defines this typedef.
23
- * @typedef {{id: string | import("../utils/model-primary-key.js").CompositeModelPrimaryKeyValue}} FrontendModelDestroyEventPayload */
23
+ * @typedef {{id: import("./base.js").FrontendModelEventPrimaryKeyValue}} FrontendModelDestroyEventPayload */
24
24
  /**
25
25
  * FrontendModelClassEventPayload type.
26
26
  * @typedef {FrontendModelCreateUpdateEventPayload | FrontendModelDestroyEventPayload} FrontendModelClassEventPayload */
@@ -13,13 +13,13 @@ import useModelClassEvent from "./use-model-class-event.js"
13
13
  * @typedef {import("./base.js").FrontendModelClass} FrontendModelClass */
14
14
  /**
15
15
  * FrontendModelInstance type.
16
- * @typedef {import("./base.js").default} FrontendModelInstance */
16
+ * @typedef {InstanceType<FrontendModelClass>} FrontendModelInstance */
17
17
  /**
18
18
  * FrontendModelClassUpdateEventPayload type.
19
19
  * @typedef {import("./use-model-class-event.js").FrontendModelCreateUpdateEventPayload} FrontendModelClassUpdateEventPayload */
20
20
  /**
21
21
  * Defines this typedef.
22
- * @typedef {{id: string | import("../utils/model-primary-key.js").CompositeModelPrimaryKeyValue, model: FrontendModelInstance}} FrontendModelInstanceUpdateEventPayload */
22
+ * @typedef {{id: import("./base.js").FrontendModelEventPrimaryKeyValue, model: FrontendModelInstance}} FrontendModelInstanceUpdateEventPayload */
23
23
  /**
24
24
  * FrontendModelUpdateEventPayload type.
25
25
  * @typedef {FrontendModelClassUpdateEventPayload | FrontendModelInstanceUpdateEventPayload} FrontendModelUpdateEventPayload */
@@ -13,19 +13,23 @@ import wait from "awaitery/build/wait.js"
13
13
  /**
14
14
  * FrontendModelResourceConfig type.
15
15
  * @typedef {import("../frontend-models/base.js").FrontendModelResourceConfig} FrontendModelResourceConfig */
16
+ /**
17
+ * FrontendModelClass type.
18
+ * @typedef {import("../frontend-models/base.js").FrontendModelClass} FrontendModelClass */
16
19
  /**
17
20
  * Defines this typedef.
18
- * @typedef {{id: string | import("../utils/model-primary-key.js").CompositeModelPrimaryKeyValue, model: FrontendModelBase}} FrontendModelHookTestCreateUpdatePayload */
21
+ * @typedef {{id: import("../frontend-models/base.js").FrontendModelEventPrimaryKeyValue, model: FrontendModelBase}} FrontendModelHookTestCreateUpdatePayload */
19
22
  /**
20
23
  * Defines this typedef.
21
- * @typedef {{id: string | import("../utils/model-primary-key.js").CompositeModelPrimaryKeyValue}} FrontendModelHookTestDestroyPayload */
24
+ * @typedef {{id: import("../frontend-models/base.js").FrontendModelEventPrimaryKeyValue}} FrontendModelHookTestDestroyPayload */
25
+ /** @typedef {(payload: never) => void} ErasedFrontendModelHookCallback */
22
26
  /**
23
27
  * FakeSubscriptions type.
24
28
  * @typedef {object} FakeSubscriptions
25
- * @property {Set<(payload: FrontendModelHookTestCreateUpdatePayload) => void>} create - Create callbacks.
26
- * @property {Set<(payload: FrontendModelHookTestDestroyPayload) => void>} destroy - Destroy callbacks.
29
+ * @property {Set<ErasedFrontendModelHookCallback>} create - Heterogeneous create callbacks owned by the fake transport.
30
+ * @property {Set<ErasedFrontendModelHookCallback>} destroy - Heterogeneous destroy callbacks owned by the fake transport.
27
31
  * @property {{create: import("../frontend-models/query.js").FrontendModelEventOptionsObject[], destroy: import("../frontend-models/query.js").FrontendModelEventOptionsObject[], update: import("../frontend-models/query.js").FrontendModelEventOptionsObject[]}} options - Subscription options.
28
- * @property {Set<(payload: FrontendModelHookTestCreateUpdatePayload) => void>} update - Update callbacks.
32
+ * @property {Set<ErasedFrontendModelHookCallback>} update - Heterogeneous update callbacks owned by the fake transport.
29
33
  */
30
34
 
31
35
  /**
@@ -122,7 +126,9 @@ function buildFakeModelClass() {
122
126
 
123
127
  /**
124
128
  * Runs on create.
125
- * @param {(payload: FrontendModelHookTestCreateUpdatePayload) => void} callback - Event callback.
129
+ * @template {FrontendModelClass} T
130
+ * @this {T}
131
+ * @param {(payload: {id: import("../frontend-models/base.js").FrontendModelEventPrimaryKeyValueFor<InstanceType<T>>, model: InstanceType<T>}) => void} callback - Event callback.
126
132
  * @param {import("../frontend-models/query.js").FrontendModelEventOptionsObject} [options] - Event query or projection options.
127
133
  * @returns {Promise<() => void>} - Unsubscribe callback.
128
134
  */
@@ -135,7 +141,7 @@ function buildFakeModelClass() {
135
141
 
136
142
  /**
137
143
  * Runs on destroy.
138
- * @param {(payload: FrontendModelHookTestDestroyPayload) => void} callback - Event callback.
144
+ * @param {ErasedFrontendModelHookCallback} callback - Event callback stored by the heterogeneous fake transport.
139
145
  * @param {import("../frontend-models/query.js").FrontendModelEventOptionsObject} [options] - Event query or projection options.
140
146
  * @returns {Promise<() => void>} - Unsubscribe callback.
141
147
  */
@@ -148,7 +154,9 @@ function buildFakeModelClass() {
148
154
 
149
155
  /**
150
156
  * Runs on update.
151
- * @param {(payload: FrontendModelHookTestCreateUpdatePayload) => void} callback - Event callback.
157
+ * @template {FrontendModelClass} T
158
+ * @this {T}
159
+ * @param {(payload: {id: import("../frontend-models/base.js").FrontendModelEventPrimaryKeyValueFor<InstanceType<T>>, model: InstanceType<T>}) => void} callback - Event callback.
152
160
  * @param {import("../frontend-models/query.js").FrontendModelEventOptionsObject} [options] - Event query or projection options.
153
161
  * @returns {Promise<() => void>} - Unsubscribe callback.
154
162
  */
@@ -173,7 +181,7 @@ function buildFakeModelClass() {
173
181
  function emitEvent(subscriptions, eventName, payload) {
174
182
  if (eventName === "destroy") {
175
183
  for (const callback of subscriptions.destroy) {
176
- callback({id: payload.id})
184
+ /** @type {(event: FrontendModelHookTestDestroyPayload) => void} */ (callback)({id: payload.id})
177
185
  }
178
186
 
179
187
  return
@@ -184,7 +192,7 @@ function emitEvent(subscriptions, eventName, payload) {
184
192
  }
185
193
 
186
194
  for (const callback of subscriptions[eventName]) {
187
- callback(payload)
195
+ /** @type {(event: FrontendModelHookTestCreateUpdatePayload) => void} */ (callback)(payload)
188
196
  }
189
197
  }
190
198