Format authored monorepo code with pinned language formatters
This commit is contained in:
+21
-7
@@ -3,15 +3,26 @@
|
||||
const identities = new WeakMap<object, string>();
|
||||
declare const referenceBrand: unique symbol;
|
||||
export interface QxObjectRef<Identity extends string = string> {
|
||||
readonly [referenceBrand]: {readonly [K in Identity]: true};
|
||||
readonly [referenceBrand]: { readonly [K in Identity]: true };
|
||||
equals(other: QxObjectRef<string>): boolean;
|
||||
}
|
||||
class Reference {
|
||||
constructor(id: string) { identities.set(this, id); Object.freeze(this); }
|
||||
equals(other: unknown) { return isObjectReference(other) && identities.get(this) === identities.get(other); }
|
||||
toJSON(): never { throw new Error("Object references cannot be serialized into ordinary data"); }
|
||||
toString(): never { throw new Error("Object references cannot be coerced to strings"); }
|
||||
[Symbol.toPrimitive](): never { throw new Error("Object references cannot be coerced to scalar values"); }
|
||||
constructor(id: string) {
|
||||
identities.set(this, id);
|
||||
Object.freeze(this);
|
||||
}
|
||||
equals(other: unknown) {
|
||||
return isObjectReference(other) && identities.get(this) === identities.get(other);
|
||||
}
|
||||
toJSON(): never {
|
||||
throw new Error("Object references cannot be serialized into ordinary data");
|
||||
}
|
||||
toString(): never {
|
||||
throw new Error("Object references cannot be coerced to strings");
|
||||
}
|
||||
[Symbol.toPrimitive](): never {
|
||||
throw new Error("Object references cannot be coerced to scalar values");
|
||||
}
|
||||
}
|
||||
export const isObjectReference = (value: unknown): value is QxObjectRef =>
|
||||
typeof value === "object" && value !== null && identities.has(value);
|
||||
@@ -27,7 +38,10 @@ export const referenceToWire = (value: unknown): string => {
|
||||
};
|
||||
export const assertReferenceFree = (value: unknown, seen = new Set<object>()): void => {
|
||||
if (!value || typeof value !== "object") return;
|
||||
if (isObjectReference(value)) throw new Error("Managed references belong in declared RPC references or graph relationships, not ordinary state/messages");
|
||||
if (isObjectReference(value))
|
||||
throw new Error(
|
||||
"Managed references belong in declared RPC references or graph relationships, not ordinary state/messages",
|
||||
);
|
||||
if (seen.has(value)) throw new Error("Cyclic ordinary data");
|
||||
seen.add(value);
|
||||
if (!(value instanceof Uint8Array)) for (const child of Object.values(value)) assertReferenceFree(child, seen);
|
||||
|
||||
Reference in New Issue
Block a user