@actualwave/deferred-data-access 2.0.0
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.
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/command/index.d.ts +3 -0
- package/command/index.js +4 -0
- package/command/index.js.map +1 -0
- package/command/package.json +4 -0
- package/command/src/command-chain.d.ts +12 -0
- package/command/src/command-chain.js +46 -0
- package/command/src/command-chain.js.map +1 -0
- package/command/src/command-handler.d.ts +7 -0
- package/command/src/command-handler.js +12 -0
- package/command/src/command-handler.js.map +1 -0
- package/command/src/command.d.ts +11 -0
- package/command/src/command.js +31 -0
- package/command/src/command.js.map +1 -0
- package/core/core.d.ts +3 -0
- package/core/core.js +100 -0
- package/core/core.js.map +1 -0
- package/core/index.d.ts +1 -0
- package/core/index.js +2 -0
- package/core/index.js.map +1 -0
- package/dist/deferred-data-access.js +528 -0
- package/dist/deferred-data-access.js.map +1 -0
- package/dist/deferred-data-access.umd.js +2 -0
- package/dist/deferred-data-access.umd.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/index.js.map +1 -0
- package/interface/index.d.ts +6 -0
- package/interface/index.js +7 -0
- package/interface/index.js.map +1 -0
- package/interface/package.json +4 -0
- package/interface/src/handshake.d.ts +2 -0
- package/interface/src/handshake.js +51 -0
- package/interface/src/handshake.js.map +1 -0
- package/interface/src/helpers.d.ts +8 -0
- package/interface/src/helpers.js +44 -0
- package/interface/src/helpers.js.map +1 -0
- package/interface/src/intialize.d.ts +14 -0
- package/interface/src/intialize.js +120 -0
- package/interface/src/intialize.js.map +1 -0
- package/interface/src/request.d.ts +3 -0
- package/interface/src/request.js +51 -0
- package/interface/src/request.js.map +1 -0
- package/interface/src/types.d.ts +53 -0
- package/interface/src/types.js +2 -0
- package/interface/src/types.js.map +1 -0
- package/interface/src/utils.d.ts +27 -0
- package/interface/src/utils.js +111 -0
- package/interface/src/utils.js.map +1 -0
- package/package.json +18 -0
- package/proxy/index.d.ts +5 -0
- package/proxy/index.js +5 -0
- package/proxy/index.js.map +1 -0
- package/proxy/package.json +4 -0
- package/proxy/src/command.d.ts +12 -0
- package/proxy/src/command.js +19 -0
- package/proxy/src/command.js.map +1 -0
- package/proxy/src/proxy.d.ts +6 -0
- package/proxy/src/proxy.js +19 -0
- package/proxy/src/proxy.js.map +1 -0
- package/proxy/src/traps.d.ts +4 -0
- package/proxy/src/traps.js +67 -0
- package/proxy/src/traps.js.map +1 -0
- package/proxy/src/types.d.ts +19 -0
- package/proxy/src/types.js +11 -0
- package/proxy/src/types.js.map +1 -0
- package/proxy/src/utils.d.ts +5 -0
- package/proxy/src/utils.js +25 -0
- package/proxy/src/utils.js.map +1 -0
- package/record/index.d.ts +1 -0
- package/record/index.js +2 -0
- package/record/index.js.map +1 -0
- package/record/package.json +4 -0
- package/record/record.d.ts +5 -0
- package/record/record.js +17 -0
- package/record/record.js.map +1 -0
- package/resource/index.d.ts +5 -0
- package/resource/index.js +6 -0
- package/resource/index.js.map +1 -0
- package/resource/package.json +4 -0
- package/resource/src/default-resource-pool.d.ts +2 -0
- package/resource/src/default-resource-pool.js +9 -0
- package/resource/src/default-resource-pool.js.map +1 -0
- package/resource/src/resource-pool-registry.d.ts +27 -0
- package/resource/src/resource-pool-registry.js +55 -0
- package/resource/src/resource-pool-registry.js.map +1 -0
- package/resource/src/resource-pool.d.ts +16 -0
- package/resource/src/resource-pool.js +58 -0
- package/resource/src/resource-pool.js.map +1 -0
- package/resource/src/resource.d.ts +16 -0
- package/resource/src/resource.js +21 -0
- package/resource/src/resource.js.map +1 -0
- package/resource/src/utils.d.ts +3 -0
- package/resource/src/utils.js +9 -0
- package/resource/src/utils.js.map +1 -0
- package/utils/index.d.ts +2 -0
- package/utils/index.js +3 -0
- package/utils/index.js.map +1 -0
- package/utils/package.json +4 -0
- package/utils/src/types.d.ts +24 -0
- package/utils/src/types.js +2 -0
- package/utils/src/types.js.map +1 -0
- package/utils/src/utils.d.ts +13 -0
- package/utils/src/utils.js +22 -0
- package/utils/src/utils.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../../packages/deferred-data-access/proxy/src/proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5D,MAAM,CAAC,MAAM,aAAa,GAAG;AAC3B,8DAA8D;AAC9D,MAAW,EACX,KAAoC,EACpC,MAAiB,EAAE,EACnB,EAAE;IACF,MAAM,OAAO,GAAiB,MAAM,CAAC,MAAM,CACzC,OAAO,MAAM,KAAK,UAAU;QAC1B,CAAC,CAAC,SAAS,UAAU,CAAY,GAAG,IAAO;YACvC,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAClC,CAAC;QACH,CAAC,CAAC,SAAS,QAAQ;YACf,UAAU;QACZ,CAAC,EACL;QACE,MAAM;QACN,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,GAAG,EAAE;KAChD,CACF,CAAC;IAEF,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAQ,EAAW,EAAE,CACtD,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;AAE3B,MAAM,CAAC,MAAM,WAAW,GAAG,CAAc,GAAQ,EAAK,EAAE,CACtD,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAK,GAAG,CAAC,QAAQ,CAAe,CAAC,SAAS,EAAE,IAAI,GAAG,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ProxyCommand } from './command';
|
|
2
|
+
import { EXCLUSIONS } from './types';
|
|
3
|
+
import { isNameExcluded } from './utils';
|
|
4
|
+
const createGetTrap = (handler) => (wrapper, name) => {
|
|
5
|
+
const { target } = wrapper;
|
|
6
|
+
if (isNameExcluded(name)) {
|
|
7
|
+
return wrapper[name];
|
|
8
|
+
}
|
|
9
|
+
// We expect that user of the lib will wrap with Proxy explicitly whatever they want
|
|
10
|
+
return handler(ProxyCommand.GET, name, undefined, target);
|
|
11
|
+
};
|
|
12
|
+
const createApplyTrap = (handler) => ({ target }, thisValue, args) => {
|
|
13
|
+
// thisValue is being ignored for now
|
|
14
|
+
// target is a function that should be applied
|
|
15
|
+
return handler(ProxyCommand.APPLY, undefined, args, target);
|
|
16
|
+
};
|
|
17
|
+
const createSetTrap = (handler) => ({ target }, name, value) => {
|
|
18
|
+
if (isNameExcluded(name)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
/* TODO why this might be needed?
|
|
22
|
+
if (isNameSymbol(name)) {
|
|
23
|
+
target.then((context: any) => {
|
|
24
|
+
context[name] = value;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
*/
|
|
30
|
+
handler(ProxyCommand.SET, name, value, target);
|
|
31
|
+
return true;
|
|
32
|
+
};
|
|
33
|
+
const createDeletePropertyTrap = (handler) => (wrapper, name) => {
|
|
34
|
+
if (isNameExcluded(name)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
handler(ProxyCommand.DELETE_PROPERTY, name, undefined, wrapper.target);
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
const proxyHasTrap = (wrapper, name) => {
|
|
41
|
+
if (isNameExcluded(name)) {
|
|
42
|
+
return wrapper[name];
|
|
43
|
+
}
|
|
44
|
+
// because of this Promise does not call ProxyWrapper.then() and just returns it.
|
|
45
|
+
// if change to true, it will subscribe to ProxyWrapper.then() and wait for it to resolve
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
const proxyOwnKeysTrap = () => Object.getOwnPropertyNames(EXCLUSIONS);
|
|
49
|
+
// INFO You cannot enumerate properties of request object, this may possibly require processing a lot of data
|
|
50
|
+
const proxyEnumerateTrap = () => Object.getOwnPropertyNames(EXCLUSIONS)[Symbol.iterator]();
|
|
51
|
+
const proxyGetOwnPropertyDescriptorTrap = (wrapper, name) => {
|
|
52
|
+
if (isNameExcluded(name)) {
|
|
53
|
+
return Object.getOwnPropertyDescriptor(wrapper, name);
|
|
54
|
+
}
|
|
55
|
+
return Object.getOwnPropertyDescriptor(wrapper.target, name);
|
|
56
|
+
};
|
|
57
|
+
export const createProxyTrapsObject = (handler) => ({
|
|
58
|
+
get: createGetTrap(handler),
|
|
59
|
+
apply: createApplyTrap(handler),
|
|
60
|
+
set: createSetTrap(handler),
|
|
61
|
+
deleteProperty: createDeletePropertyTrap(handler),
|
|
62
|
+
has: proxyHasTrap,
|
|
63
|
+
ownKeys: proxyOwnKeysTrap,
|
|
64
|
+
enumerate: proxyEnumerateTrap,
|
|
65
|
+
getOwnPropertyDescriptor: proxyGetOwnPropertyDescriptorTrap,
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=traps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traps.js","sourceRoot":"","sources":["../../../../packages/deferred-data-access/proxy/src/traps.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,UAAU,EAA8B,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,cAAc,EAAgB,MAAM,SAAS,CAAC;AAEvD,MAAM,aAAa,GACjB,CAAC,OAAqB,EAAE,EAAE,CAAC,CAAC,OAAqB,EAAE,IAAkB,EAAE,EAAE;IACvE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAE3B,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,OAAQ,OAAe,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,oFAAoF;IACpF,OAAO,OAAO,CAAC,YAAY,CAAC,GA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AC;AAEF,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAEtE,6GAA6G;AAC7G,MAAM,kBAAkB,GAAG,GAAG,EAAE,CAC9B,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;AAE5D,MAAM,iCAAiC,GAAG,CACxC,OAAqB,EACrB,IAAkB,EAClB,EAAE;IACF,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,MAAM,CAAC,wBAAwB,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC/D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,OAAqB,EAC6B,EAAE,CAAC,CAAC;IACtD,GAAG,EAAE,aAAa,CAAC,OAAO,CAAC;IAC3B,KAAK,EAAE,eAAe,CAAC,OAAO,CAAC;IAC/B,GAAG,EAAE,aAAa,CAAC,OAAO,CAAC;IAC3B,cAAc,EAAE,wBAAwB,CAAC,OAAO,CAAC;IACjD,GAAG,EAAE,YAAY;IACjB,OAAO,EAAE,gBAAgB;IACzB,SAAS,EAAE,kBAAkB;IAC7B,wBAAwB,EAAE,iCAAiC;CAC5D,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PropertyName, CommandContext } from '@actualwave/deferred-data-access/utils';
|
|
2
|
+
import { ProxyCommand } from './command';
|
|
3
|
+
export declare const EXCLUSIONS: {
|
|
4
|
+
arguments: boolean;
|
|
5
|
+
caller: boolean;
|
|
6
|
+
prototype: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const API_PROP: unique symbol;
|
|
9
|
+
export type APIObject = {
|
|
10
|
+
[key: string]: () => unknown;
|
|
11
|
+
};
|
|
12
|
+
export type APIOwner = {
|
|
13
|
+
[API_PROP]: APIObject;
|
|
14
|
+
};
|
|
15
|
+
export type ProxyWrapper = APIOwner & {
|
|
16
|
+
(): void;
|
|
17
|
+
target: CommandContext;
|
|
18
|
+
};
|
|
19
|
+
export type ProxyHandler = (type: ProxyCommand, name: PropertyName | undefined, value: unknown, context: CommandContext) => unknown;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const EXCLUSIONS = {
|
|
2
|
+
/*
|
|
3
|
+
INFO arguments and caller were included because they are required function properties
|
|
4
|
+
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/arguments
|
|
5
|
+
*/
|
|
6
|
+
arguments: true,
|
|
7
|
+
caller: true,
|
|
8
|
+
prototype: true,
|
|
9
|
+
};
|
|
10
|
+
export const API_PROP = Symbol('P:api');
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../packages/deferred-data-access/proxy/src/types.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB;;;OAGG;IACH,SAAS,EAAE,IAAI;IACf,MAAM,EAAE,IAAI;IACZ,SAAS,EAAE,IAAI;CAChB,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PropertyName } from '@actualwave/deferred-data-access/utils';
|
|
2
|
+
import { CommandChain } from '@actualwave/deferred-data-access/command';
|
|
3
|
+
export declare const isNameExcluded: (name: PropertyName) => boolean;
|
|
4
|
+
export declare const isNameSymbol: (name: PropertyName) => name is symbol;
|
|
5
|
+
export declare const followCommandChain: <T = unknown>(head: CommandChain, context?: any) => Promise<T>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { hasOwn } from '@actualwave/has-own';
|
|
2
|
+
import { ProxyCommand, getMethodCallContext } from './command';
|
|
3
|
+
import { API_PROP, EXCLUSIONS } from './types';
|
|
4
|
+
export const isNameExcluded = (name) => name === API_PROP || hasOwn(EXCLUSIONS, name);
|
|
5
|
+
export const isNameSymbol = (name) => typeof name === 'symbol';
|
|
6
|
+
export const followCommandChain = async (head,
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
context) => {
|
|
9
|
+
let target = context;
|
|
10
|
+
if (!context) {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
target = head.prev
|
|
13
|
+
? await followCommandChain(head.prev)
|
|
14
|
+
: head.context;
|
|
15
|
+
}
|
|
16
|
+
const { type, name, value } = head;
|
|
17
|
+
switch (type) {
|
|
18
|
+
case ProxyCommand.GET:
|
|
19
|
+
return target[name];
|
|
20
|
+
case ProxyCommand.APPLY:
|
|
21
|
+
return target.apply(getMethodCallContext(head), value);
|
|
22
|
+
}
|
|
23
|
+
throw new Error(`Unknown command "${type}" cannot be followed, only ProxyCommand.GET and APPLY are allowed.`);
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../packages/deferred-data-access/proxy/src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAkB,EAAE,EAAE,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AAEpG,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAkB,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC;AAE7E,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,IAAkB;AAClB,8DAA8D;AAC9D,OAAa,EACD,EAAE;IACd,IAAI,MAAM,GAAG,OAAO,CAAC;IAErB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,8DAA8D;QAC9D,MAAM,GAAG,IAAI,CAAC,IAAI;YAChB,CAAC,CAAC,MAAM,kBAAkB,CAAC,IAAI,CAAC,IAAoB,CAAC;YACrD,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;IACnB,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAEnC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,YAAY,CAAC,GAAG;YACnB,OAAO,MAAM,CAAC,IAAoB,CAAC,CAAC;QACtC,KAAK,YAAY,CAAC,KAAK;YACrB,OAAO,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,KAAgB,CAAC,CAAC;IACtE,CAAC;IAED,MAAM,IAAI,KAAK,CACb,oBAAoB,IAAI,oEAAoE,CAC7F,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './record';
|
package/record/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/deferred-data-access/record/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CommandContext, CommandHandler, ICommandChain, ICommandList } from '@actualwave/deferred-data-access/utils';
|
|
2
|
+
export declare const latestCall: () => Promise<unknown>;
|
|
3
|
+
export declare const latestCallFor: (context: Promise<unknown>) => Promise<unknown> | undefined;
|
|
4
|
+
export declare const clearLatestCalls: () => void;
|
|
5
|
+
export declare const recordHandlerCalls: (handler: CommandHandler) => (command: ICommandList, context: CommandContext | undefined, wrap: (context: CommandContext, command?: ICommandChain | undefined) => unknown) => Promise<unknown>;
|
package/record/record.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { unwrapProxy } from '@actualwave/deferred-data-access/proxy';
|
|
2
|
+
const calls = new Map();
|
|
3
|
+
let latest = Promise.resolve();
|
|
4
|
+
const noop = () => null;
|
|
5
|
+
export const latestCall = () => latest;
|
|
6
|
+
export const latestCallFor = (context) => calls.get(unwrapProxy(context));
|
|
7
|
+
export const clearLatestCalls = () => calls.clear();
|
|
8
|
+
export const recordHandlerCalls = (handler) => (command, context, wrap) => {
|
|
9
|
+
const promise = handler(command, context, wrap);
|
|
10
|
+
if (context && !calls.has(context)) {
|
|
11
|
+
calls.set(context, promise);
|
|
12
|
+
promise.catch(noop).then(() => calls.delete(context));
|
|
13
|
+
}
|
|
14
|
+
latest = promise;
|
|
15
|
+
return promise;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["../../../packages/deferred-data-access/record/record.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AAQrE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAoC,CAAC;AAC1D,IAAI,MAAM,GAAqB,OAAO,CAAC,OAAO,EAAE,CAAC;AAEjD,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;AAExB,MAAM,CAAC,MAAM,UAAU,GAAG,GAAqB,EAAE,CAAC,MAAM,CAAC;AACzD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAyB,EAAE,EAAE,CACzD,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;AAClC,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;AAEpD,MAAM,CAAC,MAAM,kBAAkB,GAC7B,CAAC,OAAuB,EAAE,EAAE,CAC5B,CACE,OAAqB,EACrB,OAAmC,EACnC,IAGY,EACZ,EAAE;IACF,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAEhD,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QACnC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAE5B,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,GAAG,OAAO,CAAC;IACjB,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/deferred-data-access/resource/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ResourcePool } from "./resource-pool";
|
|
2
|
+
const generateGetDefaultResourcePool = (pool) => () => {
|
|
3
|
+
if (!pool) {
|
|
4
|
+
pool = new ResourcePool();
|
|
5
|
+
}
|
|
6
|
+
return pool;
|
|
7
|
+
};
|
|
8
|
+
export const getDefaultResourcePool = generateGetDefaultResourcePool();
|
|
9
|
+
//# sourceMappingURL=default-resource-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-resource-pool.js","sourceRoot":"","sources":["../../../../packages/deferred-data-access/resource/src/default-resource-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,8BAA8B,GAClC,CAAC,IAAmB,EAAE,EAAE,CAAC,GAAiB,EAAE;IAC1C,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,IAAI,GAAG,IAAI,YAAY,EAAE,CAAC;IAC5B,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,8BAA8B,EAAE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IdOwner } from '@actualwave/deferred-data-access/utils';
|
|
2
|
+
import { ResourcePool } from './resource-pool';
|
|
3
|
+
export declare class ResourcePoolRegistry extends IdOwner {
|
|
4
|
+
private readonly pools;
|
|
5
|
+
constructor();
|
|
6
|
+
/**
|
|
7
|
+
* Create and register ResourcePool
|
|
8
|
+
*/
|
|
9
|
+
createPool(): ResourcePool;
|
|
10
|
+
/**
|
|
11
|
+
* Register ResourcePool instance.
|
|
12
|
+
*/
|
|
13
|
+
register(pool: ResourcePool): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Retrieve ResourcePool instance from registry by its Id.
|
|
16
|
+
*/
|
|
17
|
+
get(poolId: string): ResourcePool | null;
|
|
18
|
+
/**
|
|
19
|
+
* Check if ResourcePool registered in this registry instance.
|
|
20
|
+
*/
|
|
21
|
+
isRegistered(pool: ResourcePool): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Remove ResourcePool from current registry instance.
|
|
24
|
+
*/
|
|
25
|
+
remove(pool: string | ResourcePool): boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare const getRegistry: () => ResourcePoolRegistry;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { hasOwn } from '@actualwave/has-own';
|
|
2
|
+
import { IdOwner } from '@actualwave/deferred-data-access/utils';
|
|
3
|
+
import { getDefaultResourcePool } from './default-resource-pool';
|
|
4
|
+
import { ResourcePool } from './resource-pool';
|
|
5
|
+
export class ResourcePoolRegistry extends IdOwner {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.pools = {};
|
|
9
|
+
this.register(getDefaultResourcePool());
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create and register ResourcePool
|
|
13
|
+
*/
|
|
14
|
+
createPool() {
|
|
15
|
+
const pool = new ResourcePool();
|
|
16
|
+
this.register(pool);
|
|
17
|
+
return pool;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Register ResourcePool instance.
|
|
21
|
+
*/
|
|
22
|
+
register(pool) {
|
|
23
|
+
if (hasOwn(this.pools, pool.id))
|
|
24
|
+
return false;
|
|
25
|
+
this.pools[pool.id] = pool;
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Retrieve ResourcePool instance from registry by its Id.
|
|
30
|
+
*/
|
|
31
|
+
get(poolId) {
|
|
32
|
+
return this.pools[poolId] || null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Check if ResourcePool registered in this registry instance.
|
|
36
|
+
*/
|
|
37
|
+
isRegistered(pool) {
|
|
38
|
+
return hasOwn(this.pools, pool.id);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Remove ResourcePool from current registry instance.
|
|
42
|
+
*/
|
|
43
|
+
remove(pool) {
|
|
44
|
+
const poolId = typeof pool === 'string' ? pool : pool.id;
|
|
45
|
+
return delete this.pools[poolId];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const generateGetRegistry = (registry) => () => {
|
|
49
|
+
if (!registry) {
|
|
50
|
+
registry = new ResourcePoolRegistry();
|
|
51
|
+
}
|
|
52
|
+
return registry;
|
|
53
|
+
};
|
|
54
|
+
export const getRegistry = generateGetRegistry();
|
|
55
|
+
//# sourceMappingURL=resource-pool-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-pool-registry.js","sourceRoot":"","sources":["../../../../packages/deferred-data-access/resource/src/resource-pool-registry.ts"],"names":[],"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AAC;IACnC,CAAC;CACF;AAED,MAAM,mBAAmB,GACvB,CAAC,QAA+B,EAAE,EAAE,CAAC,GAAyB,EAAE;IAC9D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,IAAI,oBAAoB,EAAE,CAAC;IACxC,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IdOwner } from '@actualwave/deferred-data-access/utils';
|
|
2
|
+
import { Resource } from './resource';
|
|
3
|
+
export declare class ResourcePool extends IdOwner {
|
|
4
|
+
private refs;
|
|
5
|
+
private resources;
|
|
6
|
+
get active(): boolean;
|
|
7
|
+
set(target: object, type?: string): Resource | null;
|
|
8
|
+
has(target: object): boolean;
|
|
9
|
+
get({ id }: {
|
|
10
|
+
id: string;
|
|
11
|
+
}): unknown;
|
|
12
|
+
getById(id: string): unknown;
|
|
13
|
+
getResource(target: object): Resource;
|
|
14
|
+
remove(target: object): boolean;
|
|
15
|
+
clear(): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
+
import { IdOwner } from '@actualwave/deferred-data-access/utils';
|
|
3
|
+
import { WeakValueMap } from '@actualwave/weak-storage';
|
|
4
|
+
import { createResource } from './resource';
|
|
5
|
+
import { isValidTarget } from './utils';
|
|
6
|
+
export class ResourcePool extends IdOwner {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
// { [string]: weakref }
|
|
10
|
+
this.refs = new WeakValueMap();
|
|
11
|
+
// { [weakref]: Resource }
|
|
12
|
+
this.resources = new WeakMap();
|
|
13
|
+
}
|
|
14
|
+
get active() {
|
|
15
|
+
return !!this.resources;
|
|
16
|
+
}
|
|
17
|
+
set(target, type) {
|
|
18
|
+
let resource = null;
|
|
19
|
+
if (!isValidTarget(target)) {
|
|
20
|
+
return resource;
|
|
21
|
+
}
|
|
22
|
+
resource = this.resources.get(target);
|
|
23
|
+
if (!resource) {
|
|
24
|
+
resource = createResource(this, target, type);
|
|
25
|
+
this.refs.set(resource.id, target);
|
|
26
|
+
this.resources.set(target, resource);
|
|
27
|
+
}
|
|
28
|
+
return resource;
|
|
29
|
+
}
|
|
30
|
+
has(target) {
|
|
31
|
+
return this.resources.has(target);
|
|
32
|
+
}
|
|
33
|
+
get({ id }) {
|
|
34
|
+
return this.getById(id);
|
|
35
|
+
}
|
|
36
|
+
getById(id) {
|
|
37
|
+
return this.refs.get(id);
|
|
38
|
+
}
|
|
39
|
+
getResource(target) {
|
|
40
|
+
return this.resources.get(target);
|
|
41
|
+
}
|
|
42
|
+
remove(target) {
|
|
43
|
+
const resource = this.resources.get(target);
|
|
44
|
+
if (resource) {
|
|
45
|
+
this.refs.delete(resource.id);
|
|
46
|
+
return this.resources.delete(target);
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
clear() {
|
|
51
|
+
for (const key of this.refs.keys()) {
|
|
52
|
+
const target = this.refs.get(key);
|
|
53
|
+
this.resources.delete(target);
|
|
54
|
+
}
|
|
55
|
+
this.refs.clear();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=resource-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-pool.js","sourceRoot":"","sources":["../../../../packages/deferred-data-access/resource/src/resource-pool.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAY,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,OAAO,YAAa,SAAQ,OAAO;IAAzC;;Q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AAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAE5C,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YAC9B,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACvC,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK;QACH,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YACnC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAClC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IdOwner } from '@actualwave/deferred-data-access/utils';
|
|
2
|
+
import { ResourcePool } from './resource-pool';
|
|
3
|
+
export declare class Resource extends IdOwner {
|
|
4
|
+
readonly pool: ResourcePool;
|
|
5
|
+
readonly type: string;
|
|
6
|
+
constructor(pool: ResourcePool, type: string);
|
|
7
|
+
toObject(): ResourceObject;
|
|
8
|
+
toJSON(): string;
|
|
9
|
+
}
|
|
10
|
+
export type ResourceObject = {
|
|
11
|
+
id: string;
|
|
12
|
+
poolId: string;
|
|
13
|
+
type: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const createResource: (pool: ResourcePool, target: unknown, type?: string) => Resource;
|
|
16
|
+
export declare const isResourceObject: (obj: any) => any;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IdOwner } from '@actualwave/deferred-data-access/utils';
|
|
2
|
+
export class Resource extends IdOwner {
|
|
3
|
+
constructor(pool, type) {
|
|
4
|
+
super();
|
|
5
|
+
this.pool = pool;
|
|
6
|
+
this.type = type;
|
|
7
|
+
}
|
|
8
|
+
toObject() {
|
|
9
|
+
return { id: this.id, poolId: this.pool.id, type: this.type };
|
|
10
|
+
}
|
|
11
|
+
toJSON() {
|
|
12
|
+
return JSON.stringify(this.toObject());
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export const createResource = (pool, target, type) => new Resource(pool, type || typeof target);
|
|
16
|
+
export const isResourceObject = (obj) => obj &&
|
|
17
|
+
// type signature is not enough for non-ts env
|
|
18
|
+
typeof obj === 'object' &&
|
|
19
|
+
typeof obj.id === 'string' &&
|
|
20
|
+
typeof obj.poolId === 'string';
|
|
21
|
+
//# sourceMappingURL=resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../../packages/deferred-data-access/resource/src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AAGjE,MAAM,OAAO,QAAS,SAAQ,OAAO;IACnC,YACkB,IAAkB,EAClB,IAAY;QAE5B,KAAK,EAAE,CAAC;QAHQ,SAAI,GAAJ,IAAI,CAAc;QAClB,SAAI,GAAJ,IAAI,CAAQ;IAG9B,CAAC;IAED,QAAQ;QACN,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;IAChE,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IACzC,CAAC;CACF;AAQD,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,IAAkB,EAClB,MAAe,EACf,IAAa,EACb,EAAE,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,IAAI,IAAI,OAAO,MAAM,CAAC,CAAC;AAE/C,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAE,EAAE,CAC3C,GAAG;IACH,8CAA8C;IAC9C,OAAO,GAAG,KAAK,QAAQ;IACvB,OAAO,GAAG,CAAC,EAAE,KAAK,QAAQ;IAC1B,OAAO,GAAG,CAAC,MAAM,KAAK,QAAQ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const validTargets = new Set();
|
|
2
|
+
export const getDefaultValidTargets = () => ['object', 'function'];
|
|
3
|
+
export const isValidTarget = (value) => validTargets.has(typeof value);
|
|
4
|
+
export const setValidTargets = (list) => {
|
|
5
|
+
validTargets.clear();
|
|
6
|
+
list.forEach((item) => validTargets.add(item));
|
|
7
|
+
};
|
|
8
|
+
setValidTargets(getDefaultValidTargets());
|
|
9
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../packages/deferred-data-access/resource/src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;AAE/B,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAc,EAAW,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC;AAEzF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAe,EAAQ,EAAE;IACvD,YAAY,CAAC,KAAK,EAAE,CAAC;IACrB,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AACjD,CAAC,CAAC;AAEF,eAAe,CAAC,sBAAsB,EAAE,CAAC,CAAC"}
|
package/utils/index.d.ts
ADDED
package/utils/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/deferred-data-access/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type PropertyName = string | symbol;
|
|
2
|
+
export interface IResource {
|
|
3
|
+
id: string;
|
|
4
|
+
poolId: string;
|
|
5
|
+
type: string;
|
|
6
|
+
}
|
|
7
|
+
export type CommandContext = Promise<unknown | IResource>;
|
|
8
|
+
export interface ICommand {
|
|
9
|
+
type: string;
|
|
10
|
+
name?: PropertyName;
|
|
11
|
+
value?: unknown;
|
|
12
|
+
context?: CommandContext;
|
|
13
|
+
}
|
|
14
|
+
export interface ICommandChain extends ICommand {
|
|
15
|
+
prev?: ICommandChain;
|
|
16
|
+
toObject(): ICommand;
|
|
17
|
+
}
|
|
18
|
+
export interface ICommandList extends ICommandChain {
|
|
19
|
+
isTail(): boolean;
|
|
20
|
+
forEach(callback: (item: ICommandChain) => void): void;
|
|
21
|
+
map<T = unknown>(callback: (item: ICommandChain) => T): Array<T>;
|
|
22
|
+
reduce<T = unknown>(callback: (result: T, item: ICommandChain) => T, base: T): T;
|
|
23
|
+
}
|
|
24
|
+
export type CommandHandler = (command: ICommandList, context: CommandContext | undefined, wrap: (context: CommandContext, command?: ICommandChain) => unknown) => Promise<unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../packages/deferred-data-access/utils/src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PropertyName } from "./types";
|
|
2
|
+
export declare enum ReservedPropertyNames {
|
|
3
|
+
THEN = "then",
|
|
4
|
+
CATCH = "catch"
|
|
5
|
+
}
|
|
6
|
+
export declare const isReservedPropertyName: (name: PropertyName) => name is ReservedPropertyNames;
|
|
7
|
+
export declare const reject: (message: string) => Promise<never>;
|
|
8
|
+
export declare const createUIDGenerator: (key?: string) => () => string;
|
|
9
|
+
export declare const generateId: () => string;
|
|
10
|
+
export declare class IdOwner {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
constructor(id?: string);
|
|
13
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const DATE_NOW = Date.now() - Math.floor(Math.random() * 1000);
|
|
2
|
+
let index = 0;
|
|
3
|
+
export var ReservedPropertyNames;
|
|
4
|
+
(function (ReservedPropertyNames) {
|
|
5
|
+
ReservedPropertyNames["THEN"] = "then";
|
|
6
|
+
ReservedPropertyNames["CATCH"] = "catch";
|
|
7
|
+
})(ReservedPropertyNames || (ReservedPropertyNames = {}));
|
|
8
|
+
export const isReservedPropertyName = (name) => name === ReservedPropertyNames.THEN || name === ReservedPropertyNames.CATCH;
|
|
9
|
+
export const reject = async (message) => {
|
|
10
|
+
throw message;
|
|
11
|
+
};
|
|
12
|
+
export const createUIDGenerator = (key = '') => {
|
|
13
|
+
const prefix = `${key ? `${key}/` : ''}${DATE_NOW}/`;
|
|
14
|
+
return () => `${prefix}${++index};`;
|
|
15
|
+
};
|
|
16
|
+
export const generateId = createUIDGenerator();
|
|
17
|
+
export class IdOwner {
|
|
18
|
+
constructor(id = generateId()) {
|
|
19
|
+
this.id = id;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../packages/deferred-data-access/utils/src/utils.ts"],"names":[],"mappings":"AAEA,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;AAC/D,IAAI,KAAK,GAAG,CAAC,CAAC;AAEd,MAAM,CAAN,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,sCAAa,CAAA;IACb,wCAAe,CAAA;AACjB,CAAC,EAHW,qBAAqB,KAArB,qBAAqB,QAGhC;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,IAAkB,EAAE,EAAE,CAC3D,IAAI,KAAK,qBAAqB,CAAC,IAAI,IAAI,IAAI,KAAK,qBAAqB,CAAC,KAAK,CAAC;AAE9E,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAE,OAAe,EAAkB,EAAE;IAC9D,MAAM,OAAO,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,GAAG,EAAE,EAAE,EAAE;IAC7C,MAAM,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,GAAG,CAAC;IAErD,OAAO,GAAG,EAAE,CAAC,GAAG,MAAM,GAAG,EAAE,KAAK,GAAG,CAAC;AACtC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,kBAAkB,EAAE,CAAC;AAE/C,MAAM,OAAO,OAAO;IAClB,YAA4B,KAAa,UAAU,EAAE;QAAzB,OAAE,GAAF,EAAE,CAAuB;IAAG,CAAC;CAC1D"}
|