From ddcdad1a3e91c82b8ed56b344c624663b9f54474 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 10 Jan 2024 16:52:54 -0800 Subject: [PATCH] chore(types): consolidate PassStyled type --- packages/pass-style/src/passStyle-helpers.js | 4 ++-- packages/pass-style/src/remotable.js | 2 +- packages/pass-style/src/types.d.ts | 22 ++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/pass-style/src/passStyle-helpers.js b/packages/pass-style/src/passStyle-helpers.js index 4afb6e0efb..911e3455f9 100644 --- a/packages/pass-style/src/passStyle-helpers.js +++ b/packages/pass-style/src/passStyle-helpers.js @@ -125,7 +125,7 @@ harden(checkNormalProperty); /** * @template {import('./types.js').InterfaceSpec} T - * @param {import('./types.js').TaggedRecord} tagRecord + * @param {import('./types.js').PassStyled} tagRecord * @returns {T} */ export const getTag = tagRecord => tagRecord[Symbol.toStringTag]; @@ -144,7 +144,7 @@ harden(checkPassStyle); const makeCheckTagRecord = checkProto => { /** - * @param {import('./types.js').TaggedRecord} tagRecord + * @param {import('./types.js').PassStyled} tagRecord * @param {PassStyle} passStyle * @param {Checker} [check] * @returns {boolean} diff --git a/packages/pass-style/src/remotable.js b/packages/pass-style/src/remotable.js index 8d4add0968..1f2b91d43a 100644 --- a/packages/pass-style/src/remotable.js +++ b/packages/pass-style/src/remotable.js @@ -169,7 +169,7 @@ const checkRemotable = (val, check) => { /** * Simple semantics, just tell what interface (or undefined) a remotable has. * @type {{ - * (val: import('./types.js').TaggedRecord): T; + * (val: import('./types.js').PassStyled): T; * (val: any): string | undefined; * }} * @returns the interface specification, or undefined diff --git a/packages/pass-style/src/types.d.ts b/packages/pass-style/src/types.d.ts index 040865c05d..65080677cc 100644 --- a/packages/pass-style/src/types.d.ts +++ b/packages/pass-style/src/types.d.ts @@ -33,11 +33,17 @@ export type PassStyle = export type TaggedOrRemotable = 'tagged' | 'remotable'; -export type PassStyled = { +/** + * Tagged has own [PASS_STYLE]: "tagged", [Symbol.toStringTag]: $tag. + * + * Remotable has a prototype chain in which the penultimate object has own [PASS_STYLE]: "remotable", [Symbol.toStringTag]: $iface (where both $tag and $iface must be strings, and the latter must either be "Remotable" or start with "Alleged: " or "DebugName: "). + */ +export type PassStyled = { [PASS_STYLE]: S; + [Symbol.toStringTag]: I; }; -export type ExtractStyle

> = P[typeof PASS_STYLE]; +export type ExtractStyle

> = P[typeof PASS_STYLE]; export type PassByCopy = | Primitive @@ -103,7 +109,7 @@ export type PassStyleOf = { (p: any[]): 'copyArray'; (p: Iterable): 'remotable'; (p: Iterator): 'remotable'; - >(p: T): ExtractStyle; + >(p: T): ExtractStyle; (p: { [key: string]: any }): 'copyRecord'; (p: any): PassStyle; }; @@ -130,12 +136,6 @@ export type PassStyleOf = { * any potential proxies. */ export type PureData = Passable; -export type TaggedRecord< - S extends TaggedOrRemotable, - I extends InterfaceSpec, -> = PassStyled & { - [Symbol.toStringTag]: I; -}; /** * An object marked as remotely accessible using the `Far` or `Remotable` * functions, or a local presence representing such a remote object. @@ -143,7 +143,7 @@ export type TaggedRecord< * A more natural name would be Remotable, but that could be confused with the * value of the `Remotable` export of this module (a function). */ -export type RemotableObject = TaggedRecord< +export type RemotableObject = PassStyled< 'remotable', I >; @@ -171,7 +171,7 @@ export type CopyRecord = Record; export type CopyTagged< Tag extends string = string, Payload extends Passable = any, -> = TaggedRecord<'tagged', Tag> & { +> = PassStyled<'tagged', Tag> & { payload: Payload; }; /**