Spaces:
Build error
Build error
File size: 1,938 Bytes
23a3b80 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import { marshalErrorLike } from 'civkit';
import { AbstractPseudoTransfer, SYM_PSEUDO_TRANSFERABLE } from 'civkit/pseudo-transfer';
import { container, singleton } from 'tsyringe';
@singleton()
export class PseudoTransfer extends AbstractPseudoTransfer {
override async init() {
await this.dependencyReady();
this.emit('ready');
}
}
const instance = container.resolve(PseudoTransfer);
Object.defineProperty(Error.prototype, SYM_PSEUDO_TRANSFERABLE, {
value: function () {
const prototype = this;
return {
copyOwnProperty: 'all',
marshall: (input: Error) => marshalErrorLike(input),
unMarshall: (input: object) => {
Object.setPrototypeOf(input, prototype);
return input;
},
};
},
enumerable: false,
});
instance.expectPseudoTransferableType(Error);
for (const x of [...Object.values(require('./errors')), ...Object.values(require('civkit/civ-rpc'))]) {
if (typeof x === 'function' && x.prototype instanceof Error) {
instance.expectPseudoTransferableType(x as any);
}
}
Object.defineProperty(URL.prototype, SYM_PSEUDO_TRANSFERABLE, {
value: function () {
return {
copyOwnProperty: 'none',
marshall: (input: URL) => ({ href: input.href }),
unMarshall: (input: { href: string; }) => new URL(input.href),
};
},
enumerable: false,
});
instance.expectPseudoTransferableType(URL);
Object.defineProperty(Buffer.prototype, SYM_PSEUDO_TRANSFERABLE, {
value: function () {
return {
copyOwnProperty: 'none',
unMarshall: (input: Uint8Array | Buffer) => Buffer.isBuffer(input) ? input : Buffer.from(input),
marshall: (input: Uint8Array | Buffer) => input,
};
},
enumerable: false,
});
instance.expectPseudoTransferableType(Buffer);
export default instance;
|