patron-oop 1.15.0 → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"patron.min.mjs","sources":["../src/Guest/GuestAware.ts","../src/Guest/Guest.ts","../src/Guest/GuestCast.ts","../src/Patron/PatronPool.ts","../src/Guest/GuestPool.ts","../src/Guest/GuestMiddle.ts","../src/Source/Source.ts","../src/Guest/GuestObject.ts","../src/Guest/GuestChain.ts","../src/Guest/GuestSync.ts","../src/Patron/Patron.ts","../src/Patron/PatronOnce.ts","../src/Source/SourceEmpty.ts","../src/Factory/Factory.ts"],"sourcesContent":["import { GuestType } from \"./Guest\";\n\nexport interface GuestAwareType<T = unknown> {\n receiving(guest: GuestType<T>): unknown;\n}\n\nexport class GuestAware<T = unknown> implements GuestAwareType<T> {\n public constructor(private guestReceiver: (guest: GuestType<T>) => void) {}\n\n public receiving(guest: GuestType<T>): GuestType<T> {\n this.guestReceiver(guest);\n return guest;\n }\n}\n","type GuestIntroduction = \"guest\" | \"patron\";\n\nexport interface ReceiveOptions {\n data?: unknown;\n}\n\nexport type GuestExecutorType<T = unknown> = (\n value: T,\n options?: ReceiveOptions,\n) => void;\n\nexport interface GuestObjectType<T = unknown> {\n receive(value: T, options?: ReceiveOptions): this;\n introduction?(): GuestIntroduction;\n}\n\nexport type GuestType<T = unknown> = GuestExecutorType<T> | GuestObjectType<T>;\n\nexport function give<T>(\n data: T,\n guest: GuestType<T>,\n options?: ReceiveOptions,\n) {\n if (typeof guest === \"function\") {\n guest(data, options);\n } else {\n guest.receive(data, options);\n }\n}\n\nexport class Guest<T> implements GuestObjectType<T> {\n public constructor(private receiver: GuestExecutorType<T>) {}\n\n public receive(value: T, options?: ReceiveOptions) {\n this.receiver(value, options);\n return this;\n }\n}\n","import { give, GuestObjectType, GuestType, ReceiveOptions } from \"./Guest\";\n\nexport class GuestCast<T> implements GuestObjectType<T> {\n public constructor(\n private sourceGuest: GuestType<unknown>,\n private targetGuest: GuestType<T>,\n ) {}\n\n introduction() {\n if (typeof this.sourceGuest === \"function\") {\n return \"guest\";\n }\n\n if (!this.sourceGuest.introduction) {\n return \"guest\";\n }\n return this.sourceGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n give(value, this.targetGuest, options);\n return this;\n }\n}\n","import {\n give,\n GuestObjectType,\n GuestType,\n ReceiveOptions,\n} from \"../Guest/Guest\";\n\nconst poolSets = new Map<PoolType, Set<GuestObjectType>>();\n\n/**\n * Удалить патрон из всех пулов\n */\nexport const removePatronFromPools = (patron: GuestObjectType) => {\n poolSets.forEach((pool) => {\n pool.delete(patron);\n });\n};\n\nexport interface PoolType<T = unknown> extends GuestObjectType<T> {\n add(guest: GuestObjectType<T>): this;\n distribute(receiving: T, possiblePatron: GuestObjectType<T>): this;\n remove(patron: GuestObjectType<T>): this;\n}\n\nexport class PatronPool<T> implements PoolType<T> {\n private patrons = new Set<GuestObjectType<T>>();\n\n public receive: (value: T, options?: ReceiveOptions) => this;\n\n public constructor(private initiator: unknown) {\n poolSets.set(this, this.patrons);\n\n let lastMicrotask: (() => void) | null = null;\n const doReceive = (value: T, options?: ReceiveOptions) => {\n this.patrons.forEach((target) => {\n this.sendValueToGuest(value, target, options);\n });\n };\n this.receive = (value: T, options?: ReceiveOptions) => {\n const currentMicroTask = () => {\n if (currentMicroTask === lastMicrotask) {\n doReceive(value, options);\n }\n };\n lastMicrotask = currentMicroTask;\n queueMicrotask(currentMicroTask);\n return this;\n };\n }\n\n public add(shouldBePatron: GuestType<T>) {\n if (\n typeof shouldBePatron !== \"function\" &&\n shouldBePatron.introduction &&\n shouldBePatron.introduction() === \"patron\"\n ) {\n this.patrons.add(shouldBePatron);\n }\n return this;\n }\n\n public remove(patron: GuestObjectType<T>) {\n this.patrons.delete(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestType<T>): this {\n this.add(possiblePatron);\n this.sendValueToGuest(receiving, possiblePatron, {});\n return this;\n }\n\n private sendValueToGuest(\n value: T,\n guest: GuestType<T>,\n options?: ReceiveOptions,\n ) {\n give(value, guest, {\n ...options,\n data: {\n ...((options?.data as Record<string, unknown>) ?? {}),\n initiator: this.initiator,\n pool: this,\n },\n });\n }\n}\n","import { PatronPool } from \"../Patron/PatronPool\";\nimport { PoolType } from \"../Patron/PatronPool\";\nimport { give, GuestObjectType, GuestType, ReceiveOptions } from \"./Guest\";\n\nexport class GuestPool<T> implements GuestObjectType<T>, PoolType<T> {\n private guests = new Set<GuestType<T>>();\n\n private patronPool: PatronPool<T>;\n\n public constructor(initiator: unknown) {\n this.patronPool = new PatronPool(initiator);\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n this.deliverToGuests(value, options);\n this.patronPool.receive(value, options);\n return this;\n }\n\n public add(guest: GuestType<T>): this {\n if (\n typeof guest === \"function\" ||\n !guest.introduction ||\n guest.introduction() === \"guest\"\n ) {\n this.guests.add(guest);\n }\n this.patronPool.add(guest);\n return this;\n }\n\n public remove(patron: GuestObjectType<T>): this {\n this.guests.delete(patron);\n this.patronPool.remove(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestObjectType<T>): this {\n this.add(possiblePatron);\n this.receive(receiving);\n return this;\n }\n\n private deliverToGuests(value: T, options?: ReceiveOptions) {\n this.guests.forEach((target) => {\n give(value, target, options);\n });\n this.guests.clear();\n }\n}\n","import { GuestObjectType, GuestType, ReceiveOptions } from \"./Guest\";\n\nexport class GuestMiddle<T> implements GuestObjectType<T> {\n public constructor(\n private baseGuest: GuestType<unknown>,\n private middleFn: (value: T, options?: ReceiveOptions) => void,\n ) {}\n\n introduction() {\n if (typeof this.baseGuest === \"function\" || !this.baseGuest.introduction) {\n return \"guest\";\n }\n return this.baseGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n this.middleFn(value, options);\n return this;\n }\n}\n","import { GuestAwareType } from \"../Guest/GuestAware\";\nimport { Guest, GuestObjectType, GuestType } from \"../Guest/Guest\";\nimport { PatronPool } from \"../Patron/PatronPool\";\n\nexport type SourceType<T = unknown> = GuestAwareType<T> & GuestObjectType<T>;\n\nexport class Source<T> implements SourceType<T> {\n private pool = new PatronPool(this);\n\n public constructor(private sourceDocument: T) {}\n\n public receive(value: T): this {\n this.sourceDocument = value;\n this.pool.receive(this.sourceDocument);\n return this;\n }\n\n public receiving(guest: GuestType<T>): this {\n if (typeof guest === \"function\") {\n this.pool.distribute(this.sourceDocument, new Guest(guest));\n } else {\n this.pool.distribute(this.sourceDocument, guest);\n }\n return this;\n }\n}\n","import { Guest, GuestObjectType, GuestType, ReceiveOptions } from \"./Guest\";\n\nexport class GuestObject<T> implements GuestObjectType<T> {\n public constructor(private baseGuest: GuestType<T>) {}\n\n public receive(value: T, options?: ReceiveOptions): this {\n let guest = this.baseGuest;\n if (typeof guest === \"function\") {\n guest = new Guest(guest);\n }\n guest.receive(value, options);\n return this;\n }\n\n public introduction() {\n if (typeof this.baseGuest === \"function\" || !this.baseGuest.introduction) {\n return \"guest\";\n }\n\n return this.baseGuest.introduction();\n }\n}\n","import { Guest, GuestObjectType, GuestType } from \"./Guest\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestMiddle } from \"./GuestMiddle\";\nimport { Source } from \"../Source/Source\";\nimport { GuestObject } from \"./GuestObject\";\n\nexport interface ChainType<T = unknown> {\n result(guest: GuestObjectType<T>): this;\n resultArray(guest: GuestObjectType<T>): this;\n receiveKey<R>(key: string): GuestObjectType<R>;\n}\n\nexport class GuestChain<T> implements ChainType<T> {\n private theChain: Source<Record<string, unknown>>;\n\n private keysKnown = new Set();\n\n private keysFilled = new Set();\n\n private filledChainPool = new GuestPool(this);\n\n public constructor() {\n this.theChain = new Source<Record<string, unknown>>({});\n }\n\n public resultArray(guest: GuestType<T>) {\n const guestObject = new GuestObject(guest);\n this.filledChainPool.add(\n new GuestMiddle(guestObject, (value: Record<string, unknown>) =>\n Object.values(value),\n ),\n );\n if (this.isChainFilled()) {\n this.theChain.receiving(\n new Guest((chain: Record<string, unknown>) => {\n this.filledChainPool.receive(Object.values(chain));\n }),\n );\n }\n\n return this;\n }\n\n public result(guest: GuestType<T>) {\n const guestObject = new GuestObject(guest);\n if (this.isChainFilled()) {\n this.filledChainPool.add(guestObject);\n this.theChain.receiving(\n new Guest((chain) => {\n this.filledChainPool.receive(chain);\n }),\n );\n } else {\n this.filledChainPool.add(guestObject);\n }\n return this;\n }\n\n public receiveKey<R>(key: string): GuestObjectType<R> {\n this.keysKnown.add(key);\n return new Guest((value) => {\n // Обернул в очередь чтобы можно было синхронно наполнить очередь известных ключей\n queueMicrotask(() => {\n this.theChain.receiving(\n new Guest((chain: Record<string, unknown>) => {\n this.keysFilled.add(key);\n const lastChain = {\n ...chain,\n [key]: value,\n };\n this.theChain.receive(lastChain);\n if (this.isChainFilled()) {\n this.filledChainPool.receive(lastChain);\n }\n }),\n );\n });\n });\n }\n\n private isChainFilled() {\n return (\n this.keysFilled.size > 0 && this.keysFilled.size === this.keysKnown.size\n );\n }\n}\n","import { GuestObjectType } from \"./Guest\";\n\nexport interface GuestValueType<T = unknown> extends GuestObjectType<T> {\n value(): T;\n}\n\nexport class GuestSync<T> implements GuestValueType<T> {\n public constructor(private theValue: T) {}\n\n public receive(value: T): this {\n this.theValue = value;\n return this;\n }\n\n public value() {\n return this.theValue;\n }\n}\n","import {\n give,\n GuestObjectType,\n GuestType,\n ReceiveOptions,\n} from \"../Guest/Guest\";\n\n/**\n * Патрон - это постоянный посетитель\n */\nexport class Patron<T> implements GuestObjectType<T> {\n public constructor(private willBePatron: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n give(value, this.willBePatron, options);\n return this;\n }\n}\n","import { PoolType } from \"./PatronPool\";\nimport {\n give,\n GuestObjectType,\n GuestType,\n ReceiveOptions,\n} from \"../Guest/Guest\";\n\ntype PoolAware = {\n pool?: PoolType;\n};\n\nexport class PatronOnce<T> implements GuestObjectType<T> {\n private received = false;\n\n public constructor(private baseGuest: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n if (!this.received) {\n give(value, this.baseGuest, options);\n }\n\n const data = options?.data as PoolAware;\n\n if (data?.pool) {\n data.pool.remove(this);\n }\n\n return this;\n }\n}\n","import { give, GuestType } from \"./../Guest/Guest\";\nimport { GuestMiddle } from \"./../Guest/GuestMiddle\";\nimport { Source, SourceType } from \"./Source\";\n\nexport class SourceEmpty<T> implements SourceType<T> {\n private baseSource = new Source<T | null>(null);\n\n public receiving(guest: GuestType<T>) {\n this.baseSource.receiving(\n new GuestMiddle(guest as GuestType, (value) => {\n if (value !== null) {\n give(value, guest);\n }\n }),\n );\n return this;\n }\n\n public receive(value: T): this {\n this.baseSource.receive(value);\n return this;\n }\n}\n","interface Constructable<T> {\n new(...args: unknown[]): T;\n}\n\ninterface Prototyped<T> {\n prototype: T\n}\n\nexport interface FactoryType<T> {\n create<R extends unknown[], CT = null>(...args: R): CT extends null ? T : CT;\n}\n\nexport class Factory<T> implements FactoryType<T> {\n public constructor(\n private constructorFn: Prototyped<T>,\n private factories: Record<string, unknown> = {},\n ) { }\n\n public create<R extends unknown[], CT = null>(...args: R): CT extends null ? T : CT {\n return new (this.constructorFn as Constructable<T>)(...args, this.factories) as CT extends null ? T : CT;\n }\n}\n"],"names":["GuestAware","constructor","guestReceiver","this","receiving","guest","give","data","options","receive","Guest","receiver","value","GuestCast","sourceGuest","targetGuest","introduction","poolSets","Map","removePatronFromPools","patron","forEach","pool","delete","PatronPool","initiator","__publicField","Set","set","patrons","lastMicrotask","doReceive","target","sendValueToGuest","currentMicroTask","queueMicrotask","add","shouldBePatron","remove","distribute","possiblePatron","GuestPool","patronPool","deliverToGuests","guests","clear","GuestMiddle","baseGuest","middleFn","Source","sourceDocument","GuestObject","GuestChain","theChain","resultArray","guestObject","filledChainPool","Object","values","isChainFilled","chain","result","receiveKey","key","keysKnown","keysFilled","lastChain","size","GuestSync","theValue","Patron","willBePatron","PatronOnce","received","SourceEmpty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oE,aAAc/D,GACxBL,IACT,uICRK,MAAMqE,EAGJ,WAAAvE,CAAoB8C,GAAA5C,KAAA4C,UAAAA,EAF3BrB,EAAAvB,KAAQ,YAAW,EAEkC,CAE9C,YAAAa,GACE,MAAA,QACT,CAEO,OAAAP,CAAQG,EAAUJ,GAClBL,KAAKsE,UACHnE,EAAAM,EAAOT,KAAK4C,UAAWvC,GAG9B,MAAMD,EAAOC,GAASD,KAMf,OAJHA,GAAMe,MACHf,EAAAe,KAAKgB,OAAOnC,MAGZA,IACT,uIC7BK,MAAMuE,EAAN,WAAAzE,GACGyB,EAAAvB,KAAA,aAAa,IAAI8C,EAAiB,MAAI,CAEvC,SAAA7C,CAAUC,GAQR,OAPPF,KAAKwE,WAAWvE,UACd,IAAI0C,EAAYzC,GAAqBO,IACrB,OAAVA,GACFN,EAAKM,EAAOP,EACd,KAGGF,IACT,CAEO,OAAAM,CAAQG,GAEN,OADFT,KAAAwE,WAAWlE,QAAQG,GACjBT,IACT,ECTK,MAAMyE,EACF,WAAA3E,CACK4E,EACAC,EAAqC,IADrC3E,KAAA0E,cAAAA,EACA1E,KAAA2E,UAAAA,CACR,CAEG,MAAAC,IAA0CC,GAC7C,OAAO,IAAK7E,KAAK0E,iBAAsCG,EAAM7E,KAAK2E,UACtE"}
1
+ {"version":3,"file":"patron.min.mjs","sources":["../src/Guest/GuestAware.ts","../src/Guest/Guest.ts","../src/Guest/GuestCast.ts","../src/Patron/PatronPool.ts","../src/Guest/GuestPool.ts","../src/Guest/GuestMiddle.ts","../src/Source/Source.ts","../src/Guest/GuestObject.ts","../src/Guest/GuestChain.ts","../src/Guest/GuestSync.ts","../src/Patron/Patron.ts","../src/Patron/PatronOnce.ts","../src/Source/SourceEmpty.ts","../src/Factory/Factory.ts"],"sourcesContent":["import { GuestType } from \"./Guest\";\n\nexport interface GuestAwareType<T = unknown> {\n value(guest: GuestType<T>): unknown;\n}\n\nexport class GuestAware<T = unknown> implements GuestAwareType<T> {\n public constructor(private guestReceiver: (guest: GuestType<T>) => void) {}\n\n public value(guest: GuestType<T>): GuestType<T> {\n this.guestReceiver(guest);\n return guest;\n }\n}\n","type GuestIntroduction = \"guest\" | \"patron\";\n\nexport interface GiveOptions {\n data?: unknown;\n}\n\nexport type GuestExecutorType<T = unknown> = (\n value: T,\n options?: GiveOptions,\n) => void;\n\nexport interface GuestObjectType<T = unknown> {\n give(value: T, options?: GiveOptions): this;\n introduction?(): GuestIntroduction;\n}\n\nexport type GuestType<T = unknown> = GuestExecutorType<T> | GuestObjectType<T>;\n\nexport function give<T>(data: T, guest: GuestType<T>, options?: GiveOptions) {\n if (typeof guest === \"function\") {\n guest(data, options);\n } else {\n guest.give(data, options);\n }\n}\n\nexport class Guest<T> implements GuestObjectType<T> {\n public constructor(private receiver: GuestExecutorType<T>) {}\n\n public give(value: T, options?: GiveOptions) {\n this.receiver(value, options);\n return this;\n }\n}\n","import { give, GuestObjectType, GuestType, GiveOptions } from \"./Guest\";\n\nexport class GuestCast<T> implements GuestObjectType<T> {\n public constructor(\n private sourceGuest: GuestType<unknown>,\n private targetGuest: GuestType<T>,\n ) {}\n\n public introduction() {\n if (typeof this.sourceGuest === \"function\") {\n return \"guest\";\n }\n if (!this.sourceGuest.introduction) {\n return \"guest\";\n }\n return this.sourceGuest.introduction();\n }\n\n public give(value: T, options?: GiveOptions): this {\n give(value, this.targetGuest, options);\n return this;\n }\n}\n","import { give, GuestObjectType, GuestType, GiveOptions } from \"../Guest/Guest\";\n\nconst poolSets = new Map<PoolType, Set<GuestObjectType>>();\n\n// remove patron from all pools\nexport const removePatronFromPools = (patron: GuestObjectType) => {\n poolSets.forEach((pool) => {\n pool.delete(patron);\n });\n};\n\nexport interface PoolType<T = unknown> extends GuestObjectType<T> {\n add(guest: GuestObjectType<T>): this;\n distribute(receiving: T, possiblePatron: GuestObjectType<T>): this;\n remove(patron: GuestObjectType<T>): this;\n}\n\nexport class PatronPool<T> implements PoolType<T> {\n private patrons = new Set<GuestObjectType<T>>();\n\n public give: (value: T, options?: GiveOptions) => this;\n\n public constructor(private initiator: unknown) {\n poolSets.set(this, this.patrons);\n let lastMicrotask: (() => void) | null = null;\n const doReceive = (value: T, options?: GiveOptions) => {\n this.patrons.forEach((target) => {\n this.sendValueToGuest(value, target, options);\n });\n };\n this.give = (value: T, options?: GiveOptions) => {\n const currentMicroTask = () => {\n if (currentMicroTask === lastMicrotask) {\n doReceive(value, options);\n }\n };\n lastMicrotask = currentMicroTask;\n queueMicrotask(currentMicroTask);\n return this;\n };\n }\n\n public add(shouldBePatron: GuestType<T>) {\n if (\n typeof shouldBePatron !== \"function\" &&\n shouldBePatron.introduction &&\n shouldBePatron.introduction() === \"patron\"\n ) {\n this.patrons.add(shouldBePatron);\n }\n return this;\n }\n\n public remove(patron: GuestObjectType<T>) {\n this.patrons.delete(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestType<T>): this {\n this.add(possiblePatron);\n this.sendValueToGuest(receiving, possiblePatron, {});\n return this;\n }\n\n private sendValueToGuest(\n value: T,\n guest: GuestType<T>,\n options?: GiveOptions,\n ) {\n give(value, guest, {\n ...options,\n data: {\n ...((options?.data as Record<string, unknown>) ?? {}),\n initiator: this.initiator,\n pool: this,\n },\n });\n }\n}\n","import { PatronPool } from \"../Patron/PatronPool\";\nimport { PoolType } from \"../Patron/PatronPool\";\nimport { give, GuestObjectType, GuestType, GiveOptions } from \"./Guest\";\n\nexport class GuestPool<T> implements GuestObjectType<T>, PoolType<T> {\n private guests = new Set<GuestType<T>>();\n\n private patronPool: PatronPool<T>;\n\n public constructor(initiator: unknown) {\n this.patronPool = new PatronPool(initiator);\n }\n\n public give(value: T, options?: GiveOptions): this {\n this.deliverToGuests(value, options);\n this.patronPool.give(value, options);\n return this;\n }\n\n public add(guest: GuestType<T>): this {\n if (\n typeof guest === \"function\" ||\n !guest.introduction ||\n guest.introduction() === \"guest\"\n ) {\n this.guests.add(guest);\n }\n this.patronPool.add(guest);\n return this;\n }\n\n public remove(patron: GuestObjectType<T>): this {\n this.guests.delete(patron);\n this.patronPool.remove(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestObjectType<T>): this {\n this.add(possiblePatron);\n this.give(receiving);\n return this;\n }\n\n private deliverToGuests(value: T, options?: GiveOptions) {\n this.guests.forEach((target) => {\n give(value, target, options);\n });\n this.guests.clear();\n }\n}\n","import { GuestObjectType, GuestType, GiveOptions } from \"./Guest\";\n\nexport class GuestMiddle<T> implements GuestObjectType<T> {\n public constructor(\n private baseGuest: GuestType<unknown>,\n private middleFn: (value: T, options?: GiveOptions) => void,\n ) {}\n\n public introduction() {\n if (typeof this.baseGuest === \"function\" || !this.baseGuest.introduction) {\n return \"guest\";\n }\n return this.baseGuest.introduction();\n }\n\n public give(value: T, options?: GiveOptions): this {\n this.middleFn(value, options);\n return this;\n }\n}\n","import { GuestAwareType } from \"../Guest/GuestAware\";\nimport { Guest, GuestObjectType, GuestType } from \"../Guest/Guest\";\nimport { PatronPool } from \"../Patron/PatronPool\";\n\nexport type SourceType<T = unknown> = GuestAwareType<T> & GuestObjectType<T>;\n\nexport class Source<T> implements SourceType<T> {\n private pool = new PatronPool(this);\n\n public constructor(private sourceDocument: T) {}\n\n public give(value: T): this {\n this.sourceDocument = value;\n this.pool.give(this.sourceDocument);\n return this;\n }\n\n public value(guest: GuestType<T>): this {\n if (typeof guest === \"function\") {\n this.pool.distribute(this.sourceDocument, new Guest(guest));\n } else {\n this.pool.distribute(this.sourceDocument, guest);\n }\n return this;\n }\n}\n","import { Guest, GuestObjectType, GuestType, GiveOptions } from \"./Guest\";\n\nexport class GuestObject<T> implements GuestObjectType<T> {\n public constructor(private baseGuest: GuestType<T>) {}\n\n public give(value: T, options?: GiveOptions): this {\n let guest = this.baseGuest;\n if (typeof guest === \"function\") {\n guest = new Guest(guest);\n }\n guest.give(value, options);\n return this;\n }\n\n public introduction() {\n if (typeof this.baseGuest === \"function\" || !this.baseGuest.introduction) {\n return \"guest\";\n }\n return this.baseGuest.introduction();\n }\n}\n","import { Guest, GuestObjectType, GuestType } from \"./Guest\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestMiddle } from \"./GuestMiddle\";\nimport { Source } from \"../Source/Source\";\nimport { GuestObject } from \"./GuestObject\";\n\nexport interface ChainType<T = unknown> {\n result(guest: GuestObjectType<T>): this;\n resultArray(guest: GuestObjectType<T>): this;\n receiveKey<R>(key: string): GuestObjectType<R>;\n}\n\nexport class GuestChain<T> implements ChainType<T> {\n private theChain: Source<Record<string, unknown>>;\n\n private keysKnown = new Set();\n\n private keysFilled = new Set();\n\n private filledChainPool = new GuestPool(this);\n\n public constructor() {\n this.theChain = new Source<Record<string, unknown>>({});\n }\n\n public resultArray(guest: GuestType<T>) {\n const guestObject = new GuestObject(guest);\n this.filledChainPool.add(\n new GuestMiddle(guestObject, (value: Record<string, unknown>) =>\n Object.values(value),\n ),\n );\n if (this.isChainFilled()) {\n this.theChain.value(\n new Guest((chain: Record<string, unknown>) => {\n this.filledChainPool.give(Object.values(chain));\n }),\n );\n }\n return this;\n }\n\n public result(guest: GuestType<T>) {\n const guestObject = new GuestObject(guest);\n if (this.isChainFilled()) {\n this.filledChainPool.add(guestObject);\n this.theChain.value(\n new Guest((chain) => {\n this.filledChainPool.give(chain);\n }),\n );\n } else {\n this.filledChainPool.add(guestObject);\n }\n return this;\n }\n\n public receiveKey<R>(key: string): GuestObjectType<R> {\n this.keysKnown.add(key);\n return new Guest((value) => {\n // Обернул в очередь чтобы можно было синхронно наполнить очередь известных ключей\n queueMicrotask(() => {\n this.theChain.value(\n new Guest((chain: Record<string, unknown>) => {\n this.keysFilled.add(key);\n const lastChain = {\n ...chain,\n [key]: value,\n };\n this.theChain.give(lastChain);\n if (this.isChainFilled()) {\n this.filledChainPool.give(lastChain);\n }\n }),\n );\n });\n });\n }\n\n private isChainFilled() {\n return (\n this.keysFilled.size > 0 && this.keysFilled.size === this.keysKnown.size\n );\n }\n}\n","import { GuestObjectType } from \"./Guest\";\n\nexport interface GuestValueType<T = unknown> extends GuestObjectType<T> {\n value(): T;\n}\n\nexport class GuestSync<T> implements GuestValueType<T> {\n public constructor(private theValue: T) {}\n\n public give(value: T): this {\n this.theValue = value;\n return this;\n }\n\n public value() {\n return this.theValue;\n }\n}\n","import { give, GuestObjectType, GuestType, GiveOptions } from \"../Guest/Guest\";\n\nexport class Patron<T> implements GuestObjectType<T> {\n public constructor(private willBePatron: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public give(value: T, options?: GiveOptions): this {\n give(value, this.willBePatron, options);\n return this;\n }\n}\n","import { PoolType } from \"./PatronPool\";\nimport { give, GuestObjectType, GuestType, GiveOptions } from \"../Guest/Guest\";\n\ntype PoolAware = {\n pool?: PoolType;\n};\n\nexport class PatronOnce<T> implements GuestObjectType<T> {\n private received = false;\n\n public constructor(private baseGuest: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public give(value: T, options?: GiveOptions): this {\n if (!this.received) {\n give(value, this.baseGuest, options);\n }\n const data = options?.data as PoolAware;\n if (data?.pool) {\n data.pool.remove(this);\n }\n return this;\n }\n}\n","import { give, GuestType } from \"./../Guest/Guest\";\nimport { GuestMiddle } from \"./../Guest/GuestMiddle\";\nimport { Source, SourceType } from \"./Source\";\n\nexport class SourceEmpty<T> implements SourceType<T> {\n private baseSource = new Source<T | null>(null);\n\n public value(guest: GuestType<T>) {\n this.baseSource.value(\n new GuestMiddle(guest as GuestType, (value) => {\n if (value !== null) {\n give(value, guest);\n }\n }),\n );\n return this;\n }\n\n public give(value: T): this {\n this.baseSource.give(value);\n return this;\n }\n}\n","interface Constructable<T> {\n new (...args: unknown[]): T;\n}\n\ninterface Prototyped<T> {\n prototype: T;\n}\n\nexport interface FactoryType<T> {\n create<R extends unknown[], CT = null>(...args: R): CT extends null ? T : CT;\n}\n\nexport class Factory<T> implements FactoryType<T> {\n public constructor(\n private constructorFn: Prototyped<T>,\n private factories: Record<string, unknown> = {},\n ) {}\n\n public create<R extends unknown[], CT = null>(\n ...args: R\n ): CT extends null ? T : CT {\n return new (this.constructorFn as Constructable<T>)(\n ...args,\n this.factories,\n ) as CT extends null ? T : CT;\n }\n}\n"],"names":["GuestAware","constructor","guestReceiver","this","value","guest","give","data","options","Guest","receiver","GuestCast","sourceGuest","targetGuest","introduction","poolSets","Map","removePatronFromPools","patron","forEach","pool","delete","PatronPool","initiator","__publicField","Set","set","patrons","lastMicrotask","doReceive","target","sendValueToGuest","currentMicroTask","queueMicrotask","add","shouldBePatron","remove","distribute","receiving","possiblePatron","GuestPool","patronPool","deliverToGuests","guests","clear","GuestMiddle","baseGuest","middleFn","Source","sourceDocument","GuestObject","GuestChain","theChain","resultArray","guestObject","filledChainPool","Object","values","isChainFilled","chain","result","receiveKey","key","keysKnown","keysFilled","lastChain","size","GuestSync","theValue","Patron","willBePatron","PatronOnce","received","SourceEmpty","baseSource","Factory","constructorFn","factories","create","args"],"mappings":"AAMO,MAAMA,EACJ,WAAAC,CAAoBC,GAAAC,KAAAD,cAAAA,CAA+C,CAEnE,KAAAE,CAAMC,GAEJ,OADPF,KAAKD,cAAcG,GACZA,CACT,ECMc,SAAAC,EAAQC,EAASF,EAAqBG,GAC/B,mBAAVH,EACTA,EAAME,EAAMC,GAENH,EAAAC,KAAKC,EAAMC,EAErB,CAEO,MAAMC,EACJ,WAAAR,CAAoBS,GAAAP,KAAAO,SAAAA,CAAiC,CAErD,IAAAJ,CAAKF,EAAUI,GAEb,OADFL,KAAAO,SAASN,EAAOI,GACdL,IACT,EC9BK,MAAMQ,EACJ,WAAAV,CACGW,EACAC,GADAV,KAAAS,YAAAA,EACAT,KAAAU,YAAAA,CACP,CAEI,YAAAC,GACD,MAA4B,mBAArBX,KAAKS,YACP,QAEJT,KAAKS,YAAYE,aAGfX,KAAKS,YAAYE,eAFf,OAGX,CAEO,IAAAR,CAAKF,EAAUI,GAEb,OADFF,EAAAF,EAAOD,KAAKU,YAAaL,GACvBL,IACT,4JCnBF,MAAMY,MAAeC,IA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ACFC,GAEH,OAAO,IAAK5E,KAAKyE,iBACZG,EACH5E,KAAK0E,UAET"}
package/dist/patron.mjs CHANGED
@@ -2,7 +2,7 @@ class GuestAware {
2
2
  constructor(guestReceiver) {
3
3
  this.guestReceiver = guestReceiver;
4
4
  }
5
- receiving(guest) {
5
+ value(guest) {
6
6
  this.guestReceiver(guest);
7
7
  return guest;
8
8
  }
@@ -12,14 +12,14 @@ function give(data, guest, options) {
12
12
  if (typeof guest === "function") {
13
13
  guest(data, options);
14
14
  } else {
15
- guest.receive(data, options);
15
+ guest.give(data, options);
16
16
  }
17
17
  }
18
18
  class Guest {
19
19
  constructor(receiver) {
20
20
  this.receiver = receiver;
21
21
  }
22
- receive(value, options) {
22
+ give(value, options) {
23
23
  this.receiver(value, options);
24
24
  return this;
25
25
  }
@@ -39,7 +39,7 @@ class GuestCast {
39
39
  }
40
40
  return this.sourceGuest.introduction();
41
41
  }
42
- receive(value, options) {
42
+ give(value, options) {
43
43
  give(value, this.targetGuest, options);
44
44
  return this;
45
45
  }
@@ -58,7 +58,7 @@ class PatronPool {
58
58
  constructor(initiator) {
59
59
  this.initiator = initiator;
60
60
  __publicField$5(this, "patrons", /* @__PURE__ */ new Set());
61
- __publicField$5(this, "receive");
61
+ __publicField$5(this, "give");
62
62
  poolSets.set(this, this.patrons);
63
63
  let lastMicrotask = null;
64
64
  const doReceive = (value, options) => {
@@ -66,7 +66,7 @@ class PatronPool {
66
66
  this.sendValueToGuest(value, target, options);
67
67
  });
68
68
  };
69
- this.receive = (value, options) => {
69
+ this.give = (value, options) => {
70
70
  const currentMicroTask = () => {
71
71
  if (currentMicroTask === lastMicrotask) {
72
72
  doReceive(value, options);
@@ -113,9 +113,9 @@ class GuestPool {
113
113
  __publicField$4(this, "patronPool");
114
114
  this.patronPool = new PatronPool(initiator);
115
115
  }
116
- receive(value, options) {
116
+ give(value, options) {
117
117
  this.deliverToGuests(value, options);
118
- this.patronPool.receive(value, options);
118
+ this.patronPool.give(value, options);
119
119
  return this;
120
120
  }
121
121
  add(guest) {
@@ -132,7 +132,7 @@ class GuestPool {
132
132
  }
133
133
  distribute(receiving, possiblePatron) {
134
134
  this.add(possiblePatron);
135
- this.receive(receiving);
135
+ this.give(receiving);
136
136
  return this;
137
137
  }
138
138
  deliverToGuests(value, options) {
@@ -154,7 +154,7 @@ class GuestMiddle {
154
154
  }
155
155
  return this.baseGuest.introduction();
156
156
  }
157
- receive(value, options) {
157
+ give(value, options) {
158
158
  this.middleFn(value, options);
159
159
  return this;
160
160
  }
@@ -168,12 +168,12 @@ class Source {
168
168
  this.sourceDocument = sourceDocument;
169
169
  __publicField$3(this, "pool", new PatronPool(this));
170
170
  }
171
- receive(value) {
171
+ give(value) {
172
172
  this.sourceDocument = value;
173
- this.pool.receive(this.sourceDocument);
173
+ this.pool.give(this.sourceDocument);
174
174
  return this;
175
175
  }
176
- receiving(guest) {
176
+ value(guest) {
177
177
  if (typeof guest === "function") {
178
178
  this.pool.distribute(this.sourceDocument, new Guest(guest));
179
179
  } else {
@@ -187,12 +187,12 @@ class GuestObject {
187
187
  constructor(baseGuest) {
188
188
  this.baseGuest = baseGuest;
189
189
  }
190
- receive(value, options) {
190
+ give(value, options) {
191
191
  let guest = this.baseGuest;
192
192
  if (typeof guest === "function") {
193
193
  guest = new Guest(guest);
194
194
  }
195
- guest.receive(value, options);
195
+ guest.give(value, options);
196
196
  return this;
197
197
  }
198
198
  introduction() {
@@ -223,9 +223,9 @@ class GuestChain {
223
223
  )
224
224
  );
225
225
  if (this.isChainFilled()) {
226
- this.theChain.receiving(
226
+ this.theChain.value(
227
227
  new Guest((chain) => {
228
- this.filledChainPool.receive(Object.values(chain));
228
+ this.filledChainPool.give(Object.values(chain));
229
229
  })
230
230
  );
231
231
  }
@@ -235,9 +235,9 @@ class GuestChain {
235
235
  const guestObject = new GuestObject(guest);
236
236
  if (this.isChainFilled()) {
237
237
  this.filledChainPool.add(guestObject);
238
- this.theChain.receiving(
238
+ this.theChain.value(
239
239
  new Guest((chain) => {
240
- this.filledChainPool.receive(chain);
240
+ this.filledChainPool.give(chain);
241
241
  })
242
242
  );
243
243
  } else {
@@ -249,16 +249,16 @@ class GuestChain {
249
249
  this.keysKnown.add(key);
250
250
  return new Guest((value) => {
251
251
  queueMicrotask(() => {
252
- this.theChain.receiving(
252
+ this.theChain.value(
253
253
  new Guest((chain) => {
254
254
  this.keysFilled.add(key);
255
255
  const lastChain = {
256
256
  ...chain,
257
257
  [key]: value
258
258
  };
259
- this.theChain.receive(lastChain);
259
+ this.theChain.give(lastChain);
260
260
  if (this.isChainFilled()) {
261
- this.filledChainPool.receive(lastChain);
261
+ this.filledChainPool.give(lastChain);
262
262
  }
263
263
  })
264
264
  );
@@ -274,7 +274,7 @@ class GuestSync {
274
274
  constructor(theValue) {
275
275
  this.theValue = theValue;
276
276
  }
277
- receive(value) {
277
+ give(value) {
278
278
  this.theValue = value;
279
279
  return this;
280
280
  }
@@ -290,7 +290,7 @@ class Patron {
290
290
  introduction() {
291
291
  return "patron";
292
292
  }
293
- receive(value, options) {
293
+ give(value, options) {
294
294
  give(value, this.willBePatron, options);
295
295
  return this;
296
296
  }
@@ -307,7 +307,7 @@ class PatronOnce {
307
307
  introduction() {
308
308
  return "patron";
309
309
  }
310
- receive(value, options) {
310
+ give(value, options) {
311
311
  if (!this.received) {
312
312
  give(value, this.baseGuest, options);
313
313
  }
@@ -326,8 +326,8 @@ class SourceEmpty {
326
326
  constructor() {
327
327
  __publicField(this, "baseSource", new Source(null));
328
328
  }
329
- receiving(guest) {
330
- this.baseSource.receiving(
329
+ value(guest) {
330
+ this.baseSource.value(
331
331
  new GuestMiddle(guest, (value) => {
332
332
  if (value !== null) {
333
333
  give(value, guest);
@@ -336,8 +336,8 @@ class SourceEmpty {
336
336
  );
337
337
  return this;
338
338
  }
339
- receive(value) {
340
- this.baseSource.receive(value);
339
+ give(value) {
340
+ this.baseSource.give(value);
341
341
  return this;
342
342
  }
343
343
  }
@@ -348,7 +348,10 @@ class Factory {
348
348
  this.factories = factories;
349
349
  }
350
350
  create(...args) {
351
- return new this.constructorFn(...args, this.factories);
351
+ return new this.constructorFn(
352
+ ...args,
353
+ this.factories
354
+ );
352
355
  }
353
356
  }
354
357
 
@@ -1 +1 @@
1
- {"version":3,"file":"patron.mjs","sources":["../src/Guest/GuestAware.ts","../src/Guest/Guest.ts","../src/Guest/GuestCast.ts","../src/Patron/PatronPool.ts","../src/Guest/GuestPool.ts","../src/Guest/GuestMiddle.ts","../src/Source/Source.ts","../src/Guest/GuestObject.ts","../src/Guest/GuestChain.ts","../src/Guest/GuestSync.ts","../src/Patron/Patron.ts","../src/Patron/PatronOnce.ts","../src/Source/SourceEmpty.ts","../src/Factory/Factory.ts"],"sourcesContent":["import { GuestType } from \"./Guest\";\n\nexport interface GuestAwareType<T = unknown> {\n receiving(guest: GuestType<T>): unknown;\n}\n\nexport class GuestAware<T = unknown> implements GuestAwareType<T> {\n public constructor(private guestReceiver: (guest: GuestType<T>) => void) {}\n\n public receiving(guest: GuestType<T>): GuestType<T> {\n this.guestReceiver(guest);\n return guest;\n }\n}\n","type GuestIntroduction = \"guest\" | \"patron\";\n\nexport interface ReceiveOptions {\n data?: unknown;\n}\n\nexport type GuestExecutorType<T = unknown> = (\n value: T,\n options?: ReceiveOptions,\n) => void;\n\nexport interface GuestObjectType<T = unknown> {\n receive(value: T, options?: ReceiveOptions): this;\n introduction?(): GuestIntroduction;\n}\n\nexport type GuestType<T = unknown> = GuestExecutorType<T> | GuestObjectType<T>;\n\nexport function give<T>(\n data: T,\n guest: GuestType<T>,\n options?: ReceiveOptions,\n) {\n if (typeof guest === \"function\") {\n guest(data, options);\n } else {\n guest.receive(data, options);\n }\n}\n\nexport class Guest<T> implements GuestObjectType<T> {\n public constructor(private receiver: GuestExecutorType<T>) {}\n\n public receive(value: T, options?: ReceiveOptions) {\n this.receiver(value, options);\n return this;\n }\n}\n","import { give, GuestObjectType, GuestType, ReceiveOptions } from \"./Guest\";\n\nexport class GuestCast<T> implements GuestObjectType<T> {\n public constructor(\n private sourceGuest: GuestType<unknown>,\n private targetGuest: GuestType<T>,\n ) {}\n\n introduction() {\n if (typeof this.sourceGuest === \"function\") {\n return \"guest\";\n }\n\n if (!this.sourceGuest.introduction) {\n return \"guest\";\n }\n return this.sourceGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n give(value, this.targetGuest, options);\n return this;\n }\n}\n","import {\n give,\n GuestObjectType,\n GuestType,\n ReceiveOptions,\n} from \"../Guest/Guest\";\n\nconst poolSets = new Map<PoolType, Set<GuestObjectType>>();\n\n/**\n * Удалить патрон из всех пулов\n */\nexport const removePatronFromPools = (patron: GuestObjectType) => {\n poolSets.forEach((pool) => {\n pool.delete(patron);\n });\n};\n\nexport interface PoolType<T = unknown> extends GuestObjectType<T> {\n add(guest: GuestObjectType<T>): this;\n distribute(receiving: T, possiblePatron: GuestObjectType<T>): this;\n remove(patron: GuestObjectType<T>): this;\n}\n\nexport class PatronPool<T> implements PoolType<T> {\n private patrons = new Set<GuestObjectType<T>>();\n\n public receive: (value: T, options?: ReceiveOptions) => this;\n\n public constructor(private initiator: unknown) {\n poolSets.set(this, this.patrons);\n\n let lastMicrotask: (() => void) | null = null;\n const doReceive = (value: T, options?: ReceiveOptions) => {\n this.patrons.forEach((target) => {\n this.sendValueToGuest(value, target, options);\n });\n };\n this.receive = (value: T, options?: ReceiveOptions) => {\n const currentMicroTask = () => {\n if (currentMicroTask === lastMicrotask) {\n doReceive(value, options);\n }\n };\n lastMicrotask = currentMicroTask;\n queueMicrotask(currentMicroTask);\n return this;\n };\n }\n\n public add(shouldBePatron: GuestType<T>) {\n if (\n typeof shouldBePatron !== \"function\" &&\n shouldBePatron.introduction &&\n shouldBePatron.introduction() === \"patron\"\n ) {\n this.patrons.add(shouldBePatron);\n }\n return this;\n }\n\n public remove(patron: GuestObjectType<T>) {\n this.patrons.delete(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestType<T>): this {\n this.add(possiblePatron);\n this.sendValueToGuest(receiving, possiblePatron, {});\n return this;\n }\n\n private sendValueToGuest(\n value: T,\n guest: GuestType<T>,\n options?: ReceiveOptions,\n ) {\n give(value, guest, {\n ...options,\n data: {\n ...((options?.data as Record<string, unknown>) ?? {}),\n initiator: this.initiator,\n pool: this,\n },\n });\n }\n}\n","import { PatronPool } from \"../Patron/PatronPool\";\nimport { PoolType } from \"../Patron/PatronPool\";\nimport { give, GuestObjectType, GuestType, ReceiveOptions } from \"./Guest\";\n\nexport class GuestPool<T> implements GuestObjectType<T>, PoolType<T> {\n private guests = new Set<GuestType<T>>();\n\n private patronPool: PatronPool<T>;\n\n public constructor(initiator: unknown) {\n this.patronPool = new PatronPool(initiator);\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n this.deliverToGuests(value, options);\n this.patronPool.receive(value, options);\n return this;\n }\n\n public add(guest: GuestType<T>): this {\n if (\n typeof guest === \"function\" ||\n !guest.introduction ||\n guest.introduction() === \"guest\"\n ) {\n this.guests.add(guest);\n }\n this.patronPool.add(guest);\n return this;\n }\n\n public remove(patron: GuestObjectType<T>): this {\n this.guests.delete(patron);\n this.patronPool.remove(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestObjectType<T>): this {\n this.add(possiblePatron);\n this.receive(receiving);\n return this;\n }\n\n private deliverToGuests(value: T, options?: ReceiveOptions) {\n this.guests.forEach((target) => {\n give(value, target, options);\n });\n this.guests.clear();\n }\n}\n","import { GuestObjectType, GuestType, ReceiveOptions } from \"./Guest\";\n\nexport class GuestMiddle<T> implements GuestObjectType<T> {\n public constructor(\n private baseGuest: GuestType<unknown>,\n private middleFn: (value: T, options?: ReceiveOptions) => void,\n ) {}\n\n introduction() {\n if (typeof this.baseGuest === \"function\" || !this.baseGuest.introduction) {\n return \"guest\";\n }\n return this.baseGuest.introduction();\n }\n\n receive(value: T, options?: ReceiveOptions): this {\n this.middleFn(value, options);\n return this;\n }\n}\n","import { GuestAwareType } from \"../Guest/GuestAware\";\nimport { Guest, GuestObjectType, GuestType } from \"../Guest/Guest\";\nimport { PatronPool } from \"../Patron/PatronPool\";\n\nexport type SourceType<T = unknown> = GuestAwareType<T> & GuestObjectType<T>;\n\nexport class Source<T> implements SourceType<T> {\n private pool = new PatronPool(this);\n\n public constructor(private sourceDocument: T) {}\n\n public receive(value: T): this {\n this.sourceDocument = value;\n this.pool.receive(this.sourceDocument);\n return this;\n }\n\n public receiving(guest: GuestType<T>): this {\n if (typeof guest === \"function\") {\n this.pool.distribute(this.sourceDocument, new Guest(guest));\n } else {\n this.pool.distribute(this.sourceDocument, guest);\n }\n return this;\n }\n}\n","import { Guest, GuestObjectType, GuestType, ReceiveOptions } from \"./Guest\";\n\nexport class GuestObject<T> implements GuestObjectType<T> {\n public constructor(private baseGuest: GuestType<T>) {}\n\n public receive(value: T, options?: ReceiveOptions): this {\n let guest = this.baseGuest;\n if (typeof guest === \"function\") {\n guest = new Guest(guest);\n }\n guest.receive(value, options);\n return this;\n }\n\n public introduction() {\n if (typeof this.baseGuest === \"function\" || !this.baseGuest.introduction) {\n return \"guest\";\n }\n\n return this.baseGuest.introduction();\n }\n}\n","import { Guest, GuestObjectType, GuestType } from \"./Guest\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestMiddle } from \"./GuestMiddle\";\nimport { Source } from \"../Source/Source\";\nimport { GuestObject } from \"./GuestObject\";\n\nexport interface ChainType<T = unknown> {\n result(guest: GuestObjectType<T>): this;\n resultArray(guest: GuestObjectType<T>): this;\n receiveKey<R>(key: string): GuestObjectType<R>;\n}\n\nexport class GuestChain<T> implements ChainType<T> {\n private theChain: Source<Record<string, unknown>>;\n\n private keysKnown = new Set();\n\n private keysFilled = new Set();\n\n private filledChainPool = new GuestPool(this);\n\n public constructor() {\n this.theChain = new Source<Record<string, unknown>>({});\n }\n\n public resultArray(guest: GuestType<T>) {\n const guestObject = new GuestObject(guest);\n this.filledChainPool.add(\n new GuestMiddle(guestObject, (value: Record<string, unknown>) =>\n Object.values(value),\n ),\n );\n if (this.isChainFilled()) {\n this.theChain.receiving(\n new Guest((chain: Record<string, unknown>) => {\n this.filledChainPool.receive(Object.values(chain));\n }),\n );\n }\n\n return this;\n }\n\n public result(guest: GuestType<T>) {\n const guestObject = new GuestObject(guest);\n if (this.isChainFilled()) {\n this.filledChainPool.add(guestObject);\n this.theChain.receiving(\n new Guest((chain) => {\n this.filledChainPool.receive(chain);\n }),\n );\n } else {\n this.filledChainPool.add(guestObject);\n }\n return this;\n }\n\n public receiveKey<R>(key: string): GuestObjectType<R> {\n this.keysKnown.add(key);\n return new Guest((value) => {\n // Обернул в очередь чтобы можно было синхронно наполнить очередь известных ключей\n queueMicrotask(() => {\n this.theChain.receiving(\n new Guest((chain: Record<string, unknown>) => {\n this.keysFilled.add(key);\n const lastChain = {\n ...chain,\n [key]: value,\n };\n this.theChain.receive(lastChain);\n if (this.isChainFilled()) {\n this.filledChainPool.receive(lastChain);\n }\n }),\n );\n });\n });\n }\n\n private isChainFilled() {\n return (\n this.keysFilled.size > 0 && this.keysFilled.size === this.keysKnown.size\n );\n }\n}\n","import { GuestObjectType } from \"./Guest\";\n\nexport interface GuestValueType<T = unknown> extends GuestObjectType<T> {\n value(): T;\n}\n\nexport class GuestSync<T> implements GuestValueType<T> {\n public constructor(private theValue: T) {}\n\n public receive(value: T): this {\n this.theValue = value;\n return this;\n }\n\n public value() {\n return this.theValue;\n }\n}\n","import {\n give,\n GuestObjectType,\n GuestType,\n ReceiveOptions,\n} from \"../Guest/Guest\";\n\n/**\n * Патрон - это постоянный посетитель\n */\nexport class Patron<T> implements GuestObjectType<T> {\n public constructor(private willBePatron: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n give(value, this.willBePatron, options);\n return this;\n }\n}\n","import { PoolType } from \"./PatronPool\";\nimport {\n give,\n GuestObjectType,\n GuestType,\n ReceiveOptions,\n} from \"../Guest/Guest\";\n\ntype PoolAware = {\n pool?: PoolType;\n};\n\nexport class PatronOnce<T> implements GuestObjectType<T> {\n private received = false;\n\n public constructor(private baseGuest: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public receive(value: T, options?: ReceiveOptions): this {\n if (!this.received) {\n give(value, this.baseGuest, options);\n }\n\n const data = options?.data as PoolAware;\n\n if (data?.pool) {\n data.pool.remove(this);\n }\n\n return this;\n }\n}\n","import { give, GuestType } from \"./../Guest/Guest\";\nimport { GuestMiddle } from \"./../Guest/GuestMiddle\";\nimport { Source, SourceType } from \"./Source\";\n\nexport class SourceEmpty<T> implements SourceType<T> {\n private baseSource = new Source<T | null>(null);\n\n public receiving(guest: GuestType<T>) {\n this.baseSource.receiving(\n new GuestMiddle(guest as GuestType, (value) => {\n if (value !== null) {\n give(value, guest);\n }\n }),\n );\n return this;\n }\n\n public receive(value: T): this {\n this.baseSource.receive(value);\n return this;\n }\n}\n","interface Constructable<T> {\n new(...args: unknown[]): T;\n}\n\ninterface Prototyped<T> {\n prototype: T\n}\n\nexport interface FactoryType<T> {\n create<R extends unknown[], CT = null>(...args: R): CT extends null ? T : CT;\n}\n\nexport class Factory<T> implements FactoryType<T> {\n public constructor(\n private constructorFn: Prototyped<T>,\n private factories: Record<string, unknown> = {},\n ) { }\n\n public create<R extends unknown[], CT = null>(...args: R): CT extends null ? T : CT {\n return new (this.constructorFn as Constructable<T>)(...args, this.factories) as CT extends null ? T : CT;\n }\n}\n"],"names":["__publicField"],"mappings":"AAMO,MAAM,UAAqD,CAAA;AAAA,EACzD,YAAoB,aAA8C,EAAA;AAA9C,IAAA,IAAA,CAAA,aAAA,GAAA,aAAA,CAAA;AAAA,GAA+C;AAAA,EAEnE,UAAU,KAAmC,EAAA;AAClD,IAAA,IAAA,CAAK,cAAc,KAAK,CAAA,CAAA;AACxB,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACF;;ACKgB,SAAA,IAAA,CACd,IACA,EAAA,KAAA,EACA,OACA,EAAA;AACA,EAAI,IAAA,OAAO,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AAA,GAAA,aAAA,CAAA;AACA,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA,CAAA;AAAA,GACR;AAAA,EAEG,UAA0C,IAAmC,EAAA;AAChF,IAAA,OAAO,IAAK,IAAK,CAAA,aAAA,CAAmC,GAAG,IAAA,EAAM,KAAK,SAAS,CAAA,CAAA;AAAA,GAC/E;AACJ;;;;"}
1
+ {"version":3,"file":"patron.mjs","sources":["../src/Guest/GuestAware.ts","../src/Guest/Guest.ts","../src/Guest/GuestCast.ts","../src/Patron/PatronPool.ts","../src/Guest/GuestPool.ts","../src/Guest/GuestMiddle.ts","../src/Source/Source.ts","../src/Guest/GuestObject.ts","../src/Guest/GuestChain.ts","../src/Guest/GuestSync.ts","../src/Patron/Patron.ts","../src/Patron/PatronOnce.ts","../src/Source/SourceEmpty.ts","../src/Factory/Factory.ts"],"sourcesContent":["import { GuestType } from \"./Guest\";\n\nexport interface GuestAwareType<T = unknown> {\n value(guest: GuestType<T>): unknown;\n}\n\nexport class GuestAware<T = unknown> implements GuestAwareType<T> {\n public constructor(private guestReceiver: (guest: GuestType<T>) => void) {}\n\n public value(guest: GuestType<T>): GuestType<T> {\n this.guestReceiver(guest);\n return guest;\n }\n}\n","type GuestIntroduction = \"guest\" | \"patron\";\n\nexport interface GiveOptions {\n data?: unknown;\n}\n\nexport type GuestExecutorType<T = unknown> = (\n value: T,\n options?: GiveOptions,\n) => void;\n\nexport interface GuestObjectType<T = unknown> {\n give(value: T, options?: GiveOptions): this;\n introduction?(): GuestIntroduction;\n}\n\nexport type GuestType<T = unknown> = GuestExecutorType<T> | GuestObjectType<T>;\n\nexport function give<T>(data: T, guest: GuestType<T>, options?: GiveOptions) {\n if (typeof guest === \"function\") {\n guest(data, options);\n } else {\n guest.give(data, options);\n }\n}\n\nexport class Guest<T> implements GuestObjectType<T> {\n public constructor(private receiver: GuestExecutorType<T>) {}\n\n public give(value: T, options?: GiveOptions) {\n this.receiver(value, options);\n return this;\n }\n}\n","import { give, GuestObjectType, GuestType, GiveOptions } from \"./Guest\";\n\nexport class GuestCast<T> implements GuestObjectType<T> {\n public constructor(\n private sourceGuest: GuestType<unknown>,\n private targetGuest: GuestType<T>,\n ) {}\n\n public introduction() {\n if (typeof this.sourceGuest === \"function\") {\n return \"guest\";\n }\n if (!this.sourceGuest.introduction) {\n return \"guest\";\n }\n return this.sourceGuest.introduction();\n }\n\n public give(value: T, options?: GiveOptions): this {\n give(value, this.targetGuest, options);\n return this;\n }\n}\n","import { give, GuestObjectType, GuestType, GiveOptions } from \"../Guest/Guest\";\n\nconst poolSets = new Map<PoolType, Set<GuestObjectType>>();\n\n// remove patron from all pools\nexport const removePatronFromPools = (patron: GuestObjectType) => {\n poolSets.forEach((pool) => {\n pool.delete(patron);\n });\n};\n\nexport interface PoolType<T = unknown> extends GuestObjectType<T> {\n add(guest: GuestObjectType<T>): this;\n distribute(receiving: T, possiblePatron: GuestObjectType<T>): this;\n remove(patron: GuestObjectType<T>): this;\n}\n\nexport class PatronPool<T> implements PoolType<T> {\n private patrons = new Set<GuestObjectType<T>>();\n\n public give: (value: T, options?: GiveOptions) => this;\n\n public constructor(private initiator: unknown) {\n poolSets.set(this, this.patrons);\n let lastMicrotask: (() => void) | null = null;\n const doReceive = (value: T, options?: GiveOptions) => {\n this.patrons.forEach((target) => {\n this.sendValueToGuest(value, target, options);\n });\n };\n this.give = (value: T, options?: GiveOptions) => {\n const currentMicroTask = () => {\n if (currentMicroTask === lastMicrotask) {\n doReceive(value, options);\n }\n };\n lastMicrotask = currentMicroTask;\n queueMicrotask(currentMicroTask);\n return this;\n };\n }\n\n public add(shouldBePatron: GuestType<T>) {\n if (\n typeof shouldBePatron !== \"function\" &&\n shouldBePatron.introduction &&\n shouldBePatron.introduction() === \"patron\"\n ) {\n this.patrons.add(shouldBePatron);\n }\n return this;\n }\n\n public remove(patron: GuestObjectType<T>) {\n this.patrons.delete(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestType<T>): this {\n this.add(possiblePatron);\n this.sendValueToGuest(receiving, possiblePatron, {});\n return this;\n }\n\n private sendValueToGuest(\n value: T,\n guest: GuestType<T>,\n options?: GiveOptions,\n ) {\n give(value, guest, {\n ...options,\n data: {\n ...((options?.data as Record<string, unknown>) ?? {}),\n initiator: this.initiator,\n pool: this,\n },\n });\n }\n}\n","import { PatronPool } from \"../Patron/PatronPool\";\nimport { PoolType } from \"../Patron/PatronPool\";\nimport { give, GuestObjectType, GuestType, GiveOptions } from \"./Guest\";\n\nexport class GuestPool<T> implements GuestObjectType<T>, PoolType<T> {\n private guests = new Set<GuestType<T>>();\n\n private patronPool: PatronPool<T>;\n\n public constructor(initiator: unknown) {\n this.patronPool = new PatronPool(initiator);\n }\n\n public give(value: T, options?: GiveOptions): this {\n this.deliverToGuests(value, options);\n this.patronPool.give(value, options);\n return this;\n }\n\n public add(guest: GuestType<T>): this {\n if (\n typeof guest === \"function\" ||\n !guest.introduction ||\n guest.introduction() === \"guest\"\n ) {\n this.guests.add(guest);\n }\n this.patronPool.add(guest);\n return this;\n }\n\n public remove(patron: GuestObjectType<T>): this {\n this.guests.delete(patron);\n this.patronPool.remove(patron);\n return this;\n }\n\n public distribute(receiving: T, possiblePatron: GuestObjectType<T>): this {\n this.add(possiblePatron);\n this.give(receiving);\n return this;\n }\n\n private deliverToGuests(value: T, options?: GiveOptions) {\n this.guests.forEach((target) => {\n give(value, target, options);\n });\n this.guests.clear();\n }\n}\n","import { GuestObjectType, GuestType, GiveOptions } from \"./Guest\";\n\nexport class GuestMiddle<T> implements GuestObjectType<T> {\n public constructor(\n private baseGuest: GuestType<unknown>,\n private middleFn: (value: T, options?: GiveOptions) => void,\n ) {}\n\n public introduction() {\n if (typeof this.baseGuest === \"function\" || !this.baseGuest.introduction) {\n return \"guest\";\n }\n return this.baseGuest.introduction();\n }\n\n public give(value: T, options?: GiveOptions): this {\n this.middleFn(value, options);\n return this;\n }\n}\n","import { GuestAwareType } from \"../Guest/GuestAware\";\nimport { Guest, GuestObjectType, GuestType } from \"../Guest/Guest\";\nimport { PatronPool } from \"../Patron/PatronPool\";\n\nexport type SourceType<T = unknown> = GuestAwareType<T> & GuestObjectType<T>;\n\nexport class Source<T> implements SourceType<T> {\n private pool = new PatronPool(this);\n\n public constructor(private sourceDocument: T) {}\n\n public give(value: T): this {\n this.sourceDocument = value;\n this.pool.give(this.sourceDocument);\n return this;\n }\n\n public value(guest: GuestType<T>): this {\n if (typeof guest === \"function\") {\n this.pool.distribute(this.sourceDocument, new Guest(guest));\n } else {\n this.pool.distribute(this.sourceDocument, guest);\n }\n return this;\n }\n}\n","import { Guest, GuestObjectType, GuestType, GiveOptions } from \"./Guest\";\n\nexport class GuestObject<T> implements GuestObjectType<T> {\n public constructor(private baseGuest: GuestType<T>) {}\n\n public give(value: T, options?: GiveOptions): this {\n let guest = this.baseGuest;\n if (typeof guest === \"function\") {\n guest = new Guest(guest);\n }\n guest.give(value, options);\n return this;\n }\n\n public introduction() {\n if (typeof this.baseGuest === \"function\" || !this.baseGuest.introduction) {\n return \"guest\";\n }\n return this.baseGuest.introduction();\n }\n}\n","import { Guest, GuestObjectType, GuestType } from \"./Guest\";\nimport { GuestPool } from \"./GuestPool\";\nimport { GuestMiddle } from \"./GuestMiddle\";\nimport { Source } from \"../Source/Source\";\nimport { GuestObject } from \"./GuestObject\";\n\nexport interface ChainType<T = unknown> {\n result(guest: GuestObjectType<T>): this;\n resultArray(guest: GuestObjectType<T>): this;\n receiveKey<R>(key: string): GuestObjectType<R>;\n}\n\nexport class GuestChain<T> implements ChainType<T> {\n private theChain: Source<Record<string, unknown>>;\n\n private keysKnown = new Set();\n\n private keysFilled = new Set();\n\n private filledChainPool = new GuestPool(this);\n\n public constructor() {\n this.theChain = new Source<Record<string, unknown>>({});\n }\n\n public resultArray(guest: GuestType<T>) {\n const guestObject = new GuestObject(guest);\n this.filledChainPool.add(\n new GuestMiddle(guestObject, (value: Record<string, unknown>) =>\n Object.values(value),\n ),\n );\n if (this.isChainFilled()) {\n this.theChain.value(\n new Guest((chain: Record<string, unknown>) => {\n this.filledChainPool.give(Object.values(chain));\n }),\n );\n }\n return this;\n }\n\n public result(guest: GuestType<T>) {\n const guestObject = new GuestObject(guest);\n if (this.isChainFilled()) {\n this.filledChainPool.add(guestObject);\n this.theChain.value(\n new Guest((chain) => {\n this.filledChainPool.give(chain);\n }),\n );\n } else {\n this.filledChainPool.add(guestObject);\n }\n return this;\n }\n\n public receiveKey<R>(key: string): GuestObjectType<R> {\n this.keysKnown.add(key);\n return new Guest((value) => {\n // Обернул в очередь чтобы можно было синхронно наполнить очередь известных ключей\n queueMicrotask(() => {\n this.theChain.value(\n new Guest((chain: Record<string, unknown>) => {\n this.keysFilled.add(key);\n const lastChain = {\n ...chain,\n [key]: value,\n };\n this.theChain.give(lastChain);\n if (this.isChainFilled()) {\n this.filledChainPool.give(lastChain);\n }\n }),\n );\n });\n });\n }\n\n private isChainFilled() {\n return (\n this.keysFilled.size > 0 && this.keysFilled.size === this.keysKnown.size\n );\n }\n}\n","import { GuestObjectType } from \"./Guest\";\n\nexport interface GuestValueType<T = unknown> extends GuestObjectType<T> {\n value(): T;\n}\n\nexport class GuestSync<T> implements GuestValueType<T> {\n public constructor(private theValue: T) {}\n\n public give(value: T): this {\n this.theValue = value;\n return this;\n }\n\n public value() {\n return this.theValue;\n }\n}\n","import { give, GuestObjectType, GuestType, GiveOptions } from \"../Guest/Guest\";\n\nexport class Patron<T> implements GuestObjectType<T> {\n public constructor(private willBePatron: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public give(value: T, options?: GiveOptions): this {\n give(value, this.willBePatron, options);\n return this;\n }\n}\n","import { PoolType } from \"./PatronPool\";\nimport { give, GuestObjectType, GuestType, GiveOptions } from \"../Guest/Guest\";\n\ntype PoolAware = {\n pool?: PoolType;\n};\n\nexport class PatronOnce<T> implements GuestObjectType<T> {\n private received = false;\n\n public constructor(private baseGuest: GuestType<T>) {}\n\n public introduction() {\n return \"patron\" as const;\n }\n\n public give(value: T, options?: GiveOptions): this {\n if (!this.received) {\n give(value, this.baseGuest, options);\n }\n const data = options?.data as PoolAware;\n if (data?.pool) {\n data.pool.remove(this);\n }\n return this;\n }\n}\n","import { give, GuestType } from \"./../Guest/Guest\";\nimport { GuestMiddle } from \"./../Guest/GuestMiddle\";\nimport { Source, SourceType } from \"./Source\";\n\nexport class SourceEmpty<T> implements SourceType<T> {\n private baseSource = new Source<T | null>(null);\n\n public value(guest: GuestType<T>) {\n this.baseSource.value(\n new GuestMiddle(guest as GuestType, (value) => {\n if (value !== null) {\n give(value, guest);\n }\n }),\n );\n return this;\n }\n\n public give(value: T): this {\n this.baseSource.give(value);\n return this;\n }\n}\n","interface Constructable<T> {\n new (...args: unknown[]): T;\n}\n\ninterface Prototyped<T> {\n prototype: T;\n}\n\nexport interface FactoryType<T> {\n create<R extends unknown[], CT = null>(...args: R): CT extends null ? T : CT;\n}\n\nexport class Factory<T> implements FactoryType<T> {\n public constructor(\n private constructorFn: Prototyped<T>,\n private factories: Record<string, unknown> = {},\n ) {}\n\n public create<R extends unknown[], CT = null>(\n ...args: R\n ): CT extends null ? T : CT {\n return new (this.constructorFn as Constructable<T>)(\n ...args,\n this.factories,\n ) as CT extends null ? T : CT;\n }\n}\n"],"names":["__publicField"],"mappings":"AAMO,MAAM,UAAqD,CAAA;AAAA,EACzD,YAAoB,aAA8C,EAAA;AAA9C,IAAA,IAAA,CAAA,aAAA,GAAA,aAAA,CAAA;AAAA,GAA+C;AAAA,EAEnE,MAAM,KAAmC,EAAA;AAC9C,IAAA,IAAA,CAAK,cAAc,KAAK,CAAA,CAAA;AACxB,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AACF;;ACKgB,SAAA,IAAA,CAAQ,IAAS,EAAA,KAAA,EAAqB,OAAuB,EAAA;AAC3E,EAAI,IAAA,OAAO,UAAU,UAAY,EAAA;AAC/B,IAAA,KAAA,CAAM,MAAM,OAAO,CAAA,CAAA;AAAA,GACd,MAAA;AACL,IAAM,KAA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AAO,IAAK,IAAK,CAAA,aAAA;AAAA,MACf,GAAG,IAAA;AAAA,MACH,IAAK,CAAA,SAAA;AAAA,KACP,CAAA;AAAA,GACF;AACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "patron-oop",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/patron.js",
@@ -3,38 +3,40 @@ import { GuestType } from "src/Guest/Guest";
3
3
  import { Source, SourceType } from "src/Source/Source";
4
4
  import { expect, test } from "vitest";
5
5
 
6
- test('factory', () => {
7
- const sourceFactory = new Factory(Source);
6
+ test("factory", () => {
7
+ const sourceFactory = new Factory(Source);
8
+ const source = sourceFactory.create(42);
8
9
 
9
- const source = sourceFactory.create(42);
10
-
11
- source.receiving((value) => {
12
- expect(value).toBe(42);
13
- });
10
+ source.value((value) => {
11
+ expect(value).toBe(42);
12
+ });
14
13
  });
15
14
 
16
15
  class TestFactory {
17
- private source: SourceType;
18
-
19
- public constructor(baseNum: number, private factories: {mainFactory: FactoryType<SourceType>}) {
20
- this.source = factories.mainFactory.create(baseNum + 55);
21
- }
22
-
23
- public value(guest: GuestType) {
24
- this.source.receiving(guest);
25
- return this;
26
- }
16
+ private source: SourceType;
17
+
18
+ public constructor(
19
+ baseNum: number,
20
+ private factories: { mainFactory: FactoryType<SourceType> },
21
+ ) {
22
+ this.source = factories.mainFactory.create(baseNum + 55);
23
+ }
24
+
25
+ public value(guest: GuestType) {
26
+ this.source.value(guest);
27
+ return this;
28
+ }
27
29
  }
28
30
 
29
- test('factory with factories', () => {
30
- const mainFactory = new Factory(Source);
31
- const sourceFactory = new Factory(TestFactory, {
32
- mainFactory
33
- });
31
+ test("factory with factories", () => {
32
+ const mainFactory = new Factory(Source);
33
+ const sourceFactory = new Factory(TestFactory, {
34
+ mainFactory,
35
+ });
34
36
 
35
- const source = sourceFactory.create(42);
37
+ const source = sourceFactory.create(42);
36
38
 
37
- source.value((value) => {
38
- expect(value).toBe(97);
39
- });
39
+ source.value((value) => {
40
+ expect(value).toBe(97);
41
+ });
40
42
  });
@@ -1,22 +1,27 @@
1
1
  interface Constructable<T> {
2
- new(...args: unknown[]): T;
2
+ new (...args: unknown[]): T;
3
3
  }
4
4
 
5
5
  interface Prototyped<T> {
6
- prototype: T
6
+ prototype: T;
7
7
  }
8
8
 
9
9
  export interface FactoryType<T> {
10
- create<R extends unknown[], CT = null>(...args: R): CT extends null ? T : CT;
10
+ create<R extends unknown[], CT = null>(...args: R): CT extends null ? T : CT;
11
11
  }
12
12
 
13
13
  export class Factory<T> implements FactoryType<T> {
14
- public constructor(
15
- private constructorFn: Prototyped<T>,
16
- private factories: Record<string, unknown> = {},
17
- ) { }
14
+ public constructor(
15
+ private constructorFn: Prototyped<T>,
16
+ private factories: Record<string, unknown> = {},
17
+ ) {}
18
18
 
19
- public create<R extends unknown[], CT = null>(...args: R): CT extends null ? T : CT {
20
- return new (this.constructorFn as Constructable<T>)(...args, this.factories) as CT extends null ? T : CT;
21
- }
19
+ public create<R extends unknown[], CT = null>(
20
+ ...args: R
21
+ ): CT extends null ? T : CT {
22
+ return new (this.constructorFn as Constructable<T>)(
23
+ ...args,
24
+ this.factories,
25
+ ) as CT extends null ? T : CT;
26
+ }
22
27
  }
@@ -4,7 +4,7 @@ import { Source } from "../Source/Source";
4
4
  test("guest callback", () => {
5
5
  const one = new Source(1);
6
6
 
7
- one.receiving((value) => {
7
+ one.value((value) => {
8
8
  expect(value).toBe(1);
9
9
  });
10
10
  });
@@ -1,37 +1,33 @@
1
1
  type GuestIntroduction = "guest" | "patron";
2
2
 
3
- export interface ReceiveOptions {
3
+ export interface GiveOptions {
4
4
  data?: unknown;
5
5
  }
6
6
 
7
7
  export type GuestExecutorType<T = unknown> = (
8
8
  value: T,
9
- options?: ReceiveOptions,
9
+ options?: GiveOptions,
10
10
  ) => void;
11
11
 
12
12
  export interface GuestObjectType<T = unknown> {
13
- receive(value: T, options?: ReceiveOptions): this;
13
+ give(value: T, options?: GiveOptions): this;
14
14
  introduction?(): GuestIntroduction;
15
15
  }
16
16
 
17
17
  export type GuestType<T = unknown> = GuestExecutorType<T> | GuestObjectType<T>;
18
18
 
19
- export function give<T>(
20
- data: T,
21
- guest: GuestType<T>,
22
- options?: ReceiveOptions,
23
- ) {
19
+ export function give<T>(data: T, guest: GuestType<T>, options?: GiveOptions) {
24
20
  if (typeof guest === "function") {
25
21
  guest(data, options);
26
22
  } else {
27
- guest.receive(data, options);
23
+ guest.give(data, options);
28
24
  }
29
25
  }
30
26
 
31
27
  export class Guest<T> implements GuestObjectType<T> {
32
28
  public constructor(private receiver: GuestExecutorType<T>) {}
33
29
 
34
- public receive(value: T, options?: ReceiveOptions) {
30
+ public give(value: T, options?: GiveOptions) {
35
31
  this.receiver(value, options);
36
32
  return this;
37
33
  }
@@ -7,7 +7,7 @@ test("guest aware", () => {
7
7
  give(111, guest);
8
8
  });
9
9
 
10
- aware.receiving((value) => {
10
+ aware.value((value) => {
11
11
  expect(value).toBe(111);
12
12
  });
13
13
  });
@@ -1,13 +1,13 @@
1
1
  import { GuestType } from "./Guest";
2
2
 
3
3
  export interface GuestAwareType<T = unknown> {
4
- receiving(guest: GuestType<T>): unknown;
4
+ value(guest: GuestType<T>): unknown;
5
5
  }
6
6
 
7
7
  export class GuestAware<T = unknown> implements GuestAwareType<T> {
8
8
  public constructor(private guestReceiver: (guest: GuestType<T>) => void) {}
9
9
 
10
- public receiving(guest: GuestType<T>): GuestType<T> {
10
+ public value(guest: GuestType<T>): GuestType<T> {
11
11
  this.guestReceiver(guest);
12
12
  return guest;
13
13
  }
@@ -20,8 +20,8 @@ test("chain guest returns 2 values after result guest", () => {
20
20
  }),
21
21
  );
22
22
 
23
- source.receiving(mainGuest);
24
- source.receiving(secondGuest);
23
+ source.value(mainGuest);
24
+ source.value(secondGuest);
25
25
 
26
26
  give(2, source);
27
27