@sudobility/entity_client 0.0.2
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/dist/hooks/index.cjs +30 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useCurrentEntity.cjs +69 -0
- package/dist/hooks/useCurrentEntity.d.ts +44 -0
- package/dist/hooks/useCurrentEntity.d.ts.map +1 -0
- package/dist/hooks/useCurrentEntity.js +65 -0
- package/dist/hooks/useCurrentEntity.js.map +1 -0
- package/dist/hooks/useEntities.cjs +113 -0
- package/dist/hooks/useEntities.d.ts +40 -0
- package/dist/hooks/useEntities.d.ts.map +1 -0
- package/dist/hooks/useEntities.js +105 -0
- package/dist/hooks/useEntities.js.map +1 -0
- package/dist/hooks/useEntityMembers.cjs +77 -0
- package/dist/hooks/useEntityMembers.d.ts +33 -0
- package/dist/hooks/useEntityMembers.d.ts.map +1 -0
- package/dist/hooks/useEntityMembers.js +71 -0
- package/dist/hooks/useEntityMembers.js.map +1 -0
- package/dist/hooks/useInvitations.cjs +132 -0
- package/dist/hooks/useInvitations.d.ts +45 -0
- package/dist/hooks/useInvitations.d.ts.map +1 -0
- package/dist/hooks/useInvitations.js +123 -0
- package/dist/hooks/useInvitations.js.map +1 -0
- package/dist/index.cjs +58 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/network/EntityClient.cjs +158 -0
- package/dist/network/EntityClient.d.ts +90 -0
- package/dist/network/EntityClient.d.ts.map +1 -0
- package/dist/network/EntityClient.js +154 -0
- package/dist/network/EntityClient.js.map +1 -0
- package/dist/network/index.cjs +9 -0
- package/dist/network/index.d.ts +5 -0
- package/dist/network/index.d.ts.map +1 -0
- package/dist/network/index.js +5 -0
- package/dist/network/index.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Hook Exports
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CurrentEntityProvider = exports.useCurrentEntity = exports.invitationKeys = exports.useDeclineInvitation = exports.useAcceptInvitation = exports.useCancelInvitation = exports.useCreateInvitation = exports.useEntityInvitations = exports.useMyInvitations = exports.memberKeys = exports.useRemoveMember = exports.useUpdateMemberRole = exports.useEntityMembers = exports.entityKeys = exports.useDeleteEntity = exports.useUpdateEntity = exports.useCreateEntity = exports.useEntity = exports.useEntities = void 0;
|
|
7
|
+
var useEntities_1 = require("./useEntities");
|
|
8
|
+
Object.defineProperty(exports, "useEntities", { enumerable: true, get: function () { return useEntities_1.useEntities; } });
|
|
9
|
+
Object.defineProperty(exports, "useEntity", { enumerable: true, get: function () { return useEntities_1.useEntity; } });
|
|
10
|
+
Object.defineProperty(exports, "useCreateEntity", { enumerable: true, get: function () { return useEntities_1.useCreateEntity; } });
|
|
11
|
+
Object.defineProperty(exports, "useUpdateEntity", { enumerable: true, get: function () { return useEntities_1.useUpdateEntity; } });
|
|
12
|
+
Object.defineProperty(exports, "useDeleteEntity", { enumerable: true, get: function () { return useEntities_1.useDeleteEntity; } });
|
|
13
|
+
Object.defineProperty(exports, "entityKeys", { enumerable: true, get: function () { return useEntities_1.entityKeys; } });
|
|
14
|
+
var useEntityMembers_1 = require("./useEntityMembers");
|
|
15
|
+
Object.defineProperty(exports, "useEntityMembers", { enumerable: true, get: function () { return useEntityMembers_1.useEntityMembers; } });
|
|
16
|
+
Object.defineProperty(exports, "useUpdateMemberRole", { enumerable: true, get: function () { return useEntityMembers_1.useUpdateMemberRole; } });
|
|
17
|
+
Object.defineProperty(exports, "useRemoveMember", { enumerable: true, get: function () { return useEntityMembers_1.useRemoveMember; } });
|
|
18
|
+
Object.defineProperty(exports, "memberKeys", { enumerable: true, get: function () { return useEntityMembers_1.memberKeys; } });
|
|
19
|
+
var useInvitations_1 = require("./useInvitations");
|
|
20
|
+
Object.defineProperty(exports, "useMyInvitations", { enumerable: true, get: function () { return useInvitations_1.useMyInvitations; } });
|
|
21
|
+
Object.defineProperty(exports, "useEntityInvitations", { enumerable: true, get: function () { return useInvitations_1.useEntityInvitations; } });
|
|
22
|
+
Object.defineProperty(exports, "useCreateInvitation", { enumerable: true, get: function () { return useInvitations_1.useCreateInvitation; } });
|
|
23
|
+
Object.defineProperty(exports, "useCancelInvitation", { enumerable: true, get: function () { return useInvitations_1.useCancelInvitation; } });
|
|
24
|
+
Object.defineProperty(exports, "useAcceptInvitation", { enumerable: true, get: function () { return useInvitations_1.useAcceptInvitation; } });
|
|
25
|
+
Object.defineProperty(exports, "useDeclineInvitation", { enumerable: true, get: function () { return useInvitations_1.useDeclineInvitation; } });
|
|
26
|
+
Object.defineProperty(exports, "invitationKeys", { enumerable: true, get: function () { return useInvitations_1.invitationKeys; } });
|
|
27
|
+
var useCurrentEntity_1 = require("./useCurrentEntity");
|
|
28
|
+
Object.defineProperty(exports, "useCurrentEntity", { enumerable: true, get: function () { return useCurrentEntity_1.useCurrentEntity; } });
|
|
29
|
+
Object.defineProperty(exports, "CurrentEntityProvider", { enumerable: true, get: function () { return useCurrentEntity_1.CurrentEntityProvider; } });
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Hook Exports
|
|
3
|
+
*/
|
|
4
|
+
export { useEntities, useEntity, useCreateEntity, useUpdateEntity, useDeleteEntity, entityKeys, } from './useEntities';
|
|
5
|
+
export { useEntityMembers, useUpdateMemberRole, useRemoveMember, memberKeys, } from './useEntityMembers';
|
|
6
|
+
export { useMyInvitations, useEntityInvitations, useCreateInvitation, useCancelInvitation, useAcceptInvitation, useDeclineInvitation, invitationKeys, } from './useInvitations';
|
|
7
|
+
export { useCurrentEntity, CurrentEntityProvider, type CurrentEntityContextValue, type CurrentEntityProviderProps, } from './useCurrentEntity';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,WAAW,EACX,SAAS,EACT,eAAe,EACf,eAAe,EACf,eAAe,EACf,UAAU,GACX,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,UAAU,GACX,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,GAChC,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Hook Exports
|
|
3
|
+
*/
|
|
4
|
+
export { useEntities, useEntity, useCreateEntity, useUpdateEntity, useDeleteEntity, entityKeys, } from './useEntities';
|
|
5
|
+
export { useEntityMembers, useUpdateMemberRole, useRemoveMember, memberKeys, } from './useEntityMembers';
|
|
6
|
+
export { useMyInvitations, useEntityInvitations, useCreateInvitation, useCancelInvitation, useAcceptInvitation, useDeclineInvitation, invitationKeys, } from './useInvitations';
|
|
7
|
+
export { useCurrentEntity, CurrentEntityProvider, } from './useCurrentEntity';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,WAAW,EACX,SAAS,EACT,eAAe,EACf,eAAe,EACf,eAAe,EACf,UAAU,GACX,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,UAAU,GACX,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,gBAAgB,EAChB,qBAAqB,GAGtB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrentEntityProvider = CurrentEntityProvider;
|
|
4
|
+
exports.useCurrentEntity = useCurrentEntity;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
/**
|
|
7
|
+
* @fileoverview Current Entity Context Hook
|
|
8
|
+
* @description React context and hook for managing current entity selection
|
|
9
|
+
*/
|
|
10
|
+
const react_1 = require("react");
|
|
11
|
+
const useEntities_1 = require("./useEntities");
|
|
12
|
+
const CurrentEntityContext = (0, react_1.createContext)(null);
|
|
13
|
+
/**
|
|
14
|
+
* Storage key for persisting selected entity.
|
|
15
|
+
*/
|
|
16
|
+
const STORAGE_KEY = 'currentEntitySlug';
|
|
17
|
+
/**
|
|
18
|
+
* Provider component for current entity context.
|
|
19
|
+
*/
|
|
20
|
+
function CurrentEntityProvider({ client, children, defaultEntitySlug, }) {
|
|
21
|
+
const [selectedSlug, setSelectedSlug] = (0, react_1.useState)(() => {
|
|
22
|
+
// Try to restore from storage
|
|
23
|
+
if (typeof window !== 'undefined') {
|
|
24
|
+
return localStorage.getItem(STORAGE_KEY) || defaultEntitySlug || null;
|
|
25
|
+
}
|
|
26
|
+
return defaultEntitySlug || null;
|
|
27
|
+
});
|
|
28
|
+
const { data: entities = [], isLoading, error, refetch, } = (0, useEntities_1.useEntities)(client);
|
|
29
|
+
// Determine current entity
|
|
30
|
+
const currentEntity = entities.find(e => e.entitySlug === selectedSlug) || entities[0] || null;
|
|
31
|
+
// Persist selection
|
|
32
|
+
(0, react_1.useEffect)(() => {
|
|
33
|
+
if (currentEntity && typeof window !== 'undefined') {
|
|
34
|
+
localStorage.setItem(STORAGE_KEY, currentEntity.entitySlug);
|
|
35
|
+
}
|
|
36
|
+
}, [currentEntity]);
|
|
37
|
+
// Auto-select first entity if none selected
|
|
38
|
+
(0, react_1.useEffect)(() => {
|
|
39
|
+
if (!selectedSlug && entities.length > 0) {
|
|
40
|
+
setSelectedSlug(entities[0].entitySlug);
|
|
41
|
+
}
|
|
42
|
+
}, [entities, selectedSlug]);
|
|
43
|
+
const selectEntity = (0, react_1.useCallback)((entitySlug) => {
|
|
44
|
+
setSelectedSlug(entitySlug);
|
|
45
|
+
}, []);
|
|
46
|
+
const refresh = (0, react_1.useCallback)(() => {
|
|
47
|
+
refetch();
|
|
48
|
+
}, [refetch]);
|
|
49
|
+
const value = {
|
|
50
|
+
currentEntity,
|
|
51
|
+
entities,
|
|
52
|
+
isLoading,
|
|
53
|
+
error: error,
|
|
54
|
+
selectEntity,
|
|
55
|
+
refresh,
|
|
56
|
+
};
|
|
57
|
+
return ((0, jsx_runtime_1.jsx)(CurrentEntityContext.Provider, { value: value, children: children }));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Hook to access current entity context.
|
|
61
|
+
*/
|
|
62
|
+
function useCurrentEntity() {
|
|
63
|
+
const context = (0, react_1.useContext)(CurrentEntityContext);
|
|
64
|
+
if (!context) {
|
|
65
|
+
throw new Error('useCurrentEntity must be used within CurrentEntityProvider');
|
|
66
|
+
}
|
|
67
|
+
return context;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=useCurrentEntity.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Current Entity Context Hook
|
|
3
|
+
* @description React context and hook for managing current entity selection
|
|
4
|
+
*/
|
|
5
|
+
import { type ReactNode } from 'react';
|
|
6
|
+
import type { EntityWithRole } from '@sudobility/types';
|
|
7
|
+
import { EntityClient } from '../network/EntityClient';
|
|
8
|
+
/**
|
|
9
|
+
* Context value for current entity.
|
|
10
|
+
*/
|
|
11
|
+
export interface CurrentEntityContextValue {
|
|
12
|
+
/** Currently selected entity */
|
|
13
|
+
currentEntity: EntityWithRole | null;
|
|
14
|
+
/** All user's entities */
|
|
15
|
+
entities: EntityWithRole[];
|
|
16
|
+
/** Whether entities are loading */
|
|
17
|
+
isLoading: boolean;
|
|
18
|
+
/** Error if any */
|
|
19
|
+
error: Error | null;
|
|
20
|
+
/** Select a different entity */
|
|
21
|
+
selectEntity: (entitySlug: string) => void;
|
|
22
|
+
/** Refresh entities list */
|
|
23
|
+
refresh: () => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Props for CurrentEntityProvider.
|
|
27
|
+
*/
|
|
28
|
+
export interface CurrentEntityProviderProps {
|
|
29
|
+
/** Entity API client */
|
|
30
|
+
client: EntityClient;
|
|
31
|
+
/** Child components */
|
|
32
|
+
children: ReactNode;
|
|
33
|
+
/** Optional default entity slug */
|
|
34
|
+
defaultEntitySlug?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Provider component for current entity context.
|
|
38
|
+
*/
|
|
39
|
+
export declare function CurrentEntityProvider({ client, children, defaultEntitySlug, }: CurrentEntityProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
40
|
+
/**
|
|
41
|
+
* Hook to access current entity context.
|
|
42
|
+
*/
|
|
43
|
+
export declare function useCurrentEntity(): CurrentEntityContextValue;
|
|
44
|
+
//# sourceMappingURL=useCurrentEntity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCurrentEntity.d.ts","sourceRoot":"","sources":["../../src/hooks/useCurrentEntity.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEL,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGvD;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,gCAAgC;IAChC,aAAa,EAAE,cAAc,GAAG,IAAI,CAAC;IACrC,0BAA0B;IAC1B,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,mCAAmC;IACnC,SAAS,EAAE,OAAO,CAAC;IACnB,mBAAmB;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,gCAAgC;IAChC,YAAY,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,4BAA4B;IAC5B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAWD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,wBAAwB;IACxB,MAAM,EAAE,YAAY,CAAC;IACrB,uBAAuB;IACvB,QAAQ,EAAE,SAAS,CAAC;IACpB,mCAAmC;IACnC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,MAAM,EACN,QAAQ,EACR,iBAAiB,GAClB,EAAE,0BAA0B,2CAwD5B;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,yBAAyB,CAQ5D"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Current Entity Context Hook
|
|
4
|
+
* @description React context and hook for managing current entity selection
|
|
5
|
+
*/
|
|
6
|
+
import { createContext, useCallback, useContext, useEffect, useState, } from 'react';
|
|
7
|
+
import { useEntities } from './useEntities';
|
|
8
|
+
const CurrentEntityContext = createContext(null);
|
|
9
|
+
/**
|
|
10
|
+
* Storage key for persisting selected entity.
|
|
11
|
+
*/
|
|
12
|
+
const STORAGE_KEY = 'currentEntitySlug';
|
|
13
|
+
/**
|
|
14
|
+
* Provider component for current entity context.
|
|
15
|
+
*/
|
|
16
|
+
export function CurrentEntityProvider({ client, children, defaultEntitySlug, }) {
|
|
17
|
+
const [selectedSlug, setSelectedSlug] = useState(() => {
|
|
18
|
+
// Try to restore from storage
|
|
19
|
+
if (typeof window !== 'undefined') {
|
|
20
|
+
return localStorage.getItem(STORAGE_KEY) || defaultEntitySlug || null;
|
|
21
|
+
}
|
|
22
|
+
return defaultEntitySlug || null;
|
|
23
|
+
});
|
|
24
|
+
const { data: entities = [], isLoading, error, refetch, } = useEntities(client);
|
|
25
|
+
// Determine current entity
|
|
26
|
+
const currentEntity = entities.find(e => e.entitySlug === selectedSlug) || entities[0] || null;
|
|
27
|
+
// Persist selection
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (currentEntity && typeof window !== 'undefined') {
|
|
30
|
+
localStorage.setItem(STORAGE_KEY, currentEntity.entitySlug);
|
|
31
|
+
}
|
|
32
|
+
}, [currentEntity]);
|
|
33
|
+
// Auto-select first entity if none selected
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!selectedSlug && entities.length > 0) {
|
|
36
|
+
setSelectedSlug(entities[0].entitySlug);
|
|
37
|
+
}
|
|
38
|
+
}, [entities, selectedSlug]);
|
|
39
|
+
const selectEntity = useCallback((entitySlug) => {
|
|
40
|
+
setSelectedSlug(entitySlug);
|
|
41
|
+
}, []);
|
|
42
|
+
const refresh = useCallback(() => {
|
|
43
|
+
refetch();
|
|
44
|
+
}, [refetch]);
|
|
45
|
+
const value = {
|
|
46
|
+
currentEntity,
|
|
47
|
+
entities,
|
|
48
|
+
isLoading,
|
|
49
|
+
error: error,
|
|
50
|
+
selectEntity,
|
|
51
|
+
refresh,
|
|
52
|
+
};
|
|
53
|
+
return (_jsx(CurrentEntityContext.Provider, { value: value, children: children }));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Hook to access current entity context.
|
|
57
|
+
*/
|
|
58
|
+
export function useCurrentEntity() {
|
|
59
|
+
const context = useContext(CurrentEntityContext);
|
|
60
|
+
if (!context) {
|
|
61
|
+
throw new Error('useCurrentEntity must be used within CurrentEntityProvider');
|
|
62
|
+
}
|
|
63
|
+
return context;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=useCurrentEntity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCurrentEntity.js","sourceRoot":"","sources":["../../src/hooks/useCurrentEntity.tsx"],"names":[],"mappings":";AAAA;;;GAGG;AAEH,OAAO,EACL,aAAa,EAEb,WAAW,EACX,UAAU,EACV,SAAS,EACT,QAAQ,GACT,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAoB5C,MAAM,oBAAoB,GAAG,aAAa,CACxC,IAAI,CACL,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAcxC;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,EACpC,MAAM,EACN,QAAQ,EACR,iBAAiB,GACU;IAC3B,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAgB,GAAG,EAAE;QACnE,8BAA8B;QAC9B,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YAClC,OAAO,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,iBAAiB,IAAI,IAAI,CAAC;QACxE,CAAC;QACD,OAAO,iBAAiB,IAAI,IAAI,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,MAAM,EACJ,IAAI,EAAE,QAAQ,GAAG,EAAE,EACnB,SAAS,EACT,KAAK,EACL,OAAO,GACR,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IAExB,2BAA2B;IAC3B,MAAM,aAAa,GACjB,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,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,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Entity Hooks
|
|
4
|
+
* @description React Query hooks for entity management
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.entityKeys = void 0;
|
|
8
|
+
exports.useEntities = useEntities;
|
|
9
|
+
exports.useEntity = useEntity;
|
|
10
|
+
exports.useCreateEntity = useCreateEntity;
|
|
11
|
+
exports.useUpdateEntity = useUpdateEntity;
|
|
12
|
+
exports.useDeleteEntity = useDeleteEntity;
|
|
13
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
14
|
+
/**
|
|
15
|
+
* Query keys for entity-related queries.
|
|
16
|
+
*/
|
|
17
|
+
exports.entityKeys = {
|
|
18
|
+
all: ['entities'],
|
|
19
|
+
lists: () => [...exports.entityKeys.all, 'list'],
|
|
20
|
+
list: () => [...exports.entityKeys.lists()],
|
|
21
|
+
details: () => [...exports.entityKeys.all, 'detail'],
|
|
22
|
+
detail: (slug) => [...exports.entityKeys.details(), slug],
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Hook to list all entities for the current user.
|
|
26
|
+
*/
|
|
27
|
+
function useEntities(client) {
|
|
28
|
+
return (0, react_query_1.useQuery)({
|
|
29
|
+
queryKey: exports.entityKeys.list(),
|
|
30
|
+
queryFn: async () => {
|
|
31
|
+
const response = await client.listEntities();
|
|
32
|
+
if (!response.success) {
|
|
33
|
+
throw new Error(response.error || 'Failed to fetch entities');
|
|
34
|
+
}
|
|
35
|
+
return response.data;
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Hook to get a single entity by slug.
|
|
41
|
+
*/
|
|
42
|
+
function useEntity(client, entitySlug) {
|
|
43
|
+
return (0, react_query_1.useQuery)({
|
|
44
|
+
queryKey: entitySlug ? exports.entityKeys.detail(entitySlug) : ['disabled'],
|
|
45
|
+
queryFn: async () => {
|
|
46
|
+
if (!entitySlug)
|
|
47
|
+
return null;
|
|
48
|
+
const response = await client.getEntity(entitySlug);
|
|
49
|
+
if (!response.success) {
|
|
50
|
+
throw new Error(response.error || 'Failed to fetch entity');
|
|
51
|
+
}
|
|
52
|
+
return response.data;
|
|
53
|
+
},
|
|
54
|
+
enabled: !!entitySlug,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Hook to create a new organization entity.
|
|
59
|
+
*/
|
|
60
|
+
function useCreateEntity(client) {
|
|
61
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
62
|
+
return (0, react_query_1.useMutation)({
|
|
63
|
+
mutationFn: async (request) => {
|
|
64
|
+
const response = await client.createEntity(request);
|
|
65
|
+
if (!response.success) {
|
|
66
|
+
throw new Error(response.error || 'Failed to create entity');
|
|
67
|
+
}
|
|
68
|
+
return response.data;
|
|
69
|
+
},
|
|
70
|
+
onSuccess: () => {
|
|
71
|
+
queryClient.invalidateQueries({ queryKey: exports.entityKeys.lists() });
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Hook to update an entity.
|
|
77
|
+
*/
|
|
78
|
+
function useUpdateEntity(client) {
|
|
79
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
80
|
+
return (0, react_query_1.useMutation)({
|
|
81
|
+
mutationFn: async ({ entitySlug, request, }) => {
|
|
82
|
+
const response = await client.updateEntity(entitySlug, request);
|
|
83
|
+
if (!response.success) {
|
|
84
|
+
throw new Error(response.error || 'Failed to update entity');
|
|
85
|
+
}
|
|
86
|
+
return response.data;
|
|
87
|
+
},
|
|
88
|
+
onSuccess: (_, variables) => {
|
|
89
|
+
queryClient.invalidateQueries({
|
|
90
|
+
queryKey: exports.entityKeys.detail(variables.entitySlug),
|
|
91
|
+
});
|
|
92
|
+
queryClient.invalidateQueries({ queryKey: exports.entityKeys.lists() });
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Hook to delete an entity.
|
|
98
|
+
*/
|
|
99
|
+
function useDeleteEntity(client) {
|
|
100
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
101
|
+
return (0, react_query_1.useMutation)({
|
|
102
|
+
mutationFn: async (entitySlug) => {
|
|
103
|
+
const response = await client.deleteEntity(entitySlug);
|
|
104
|
+
if (!response.success) {
|
|
105
|
+
throw new Error(response.error || 'Failed to delete entity');
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
onSuccess: () => {
|
|
109
|
+
queryClient.invalidateQueries({ queryKey: exports.entityKeys.lists() });
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=useEntities.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Entity Hooks
|
|
3
|
+
* @description React Query hooks for entity management
|
|
4
|
+
*/
|
|
5
|
+
import type { CreateEntityRequest, UpdateEntityRequest } from '@sudobility/types';
|
|
6
|
+
import { EntityClient } from '../network/EntityClient';
|
|
7
|
+
/**
|
|
8
|
+
* Query keys for entity-related queries.
|
|
9
|
+
*/
|
|
10
|
+
export declare const entityKeys: {
|
|
11
|
+
all: readonly ["entities"];
|
|
12
|
+
lists: () => readonly ["entities", "list"];
|
|
13
|
+
list: () => readonly ["entities", "list"];
|
|
14
|
+
details: () => readonly ["entities", "detail"];
|
|
15
|
+
detail: (slug: string) => readonly ["entities", "detail", string];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Hook to list all entities for the current user.
|
|
19
|
+
*/
|
|
20
|
+
export declare function useEntities(client: EntityClient): import("@tanstack/react-query").UseQueryResult<import("@sudobility/types").EntityWithRole[], Error>;
|
|
21
|
+
/**
|
|
22
|
+
* Hook to get a single entity by slug.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useEntity(client: EntityClient, entitySlug: string | null): import("@tanstack/react-query").UseQueryResult<import("@sudobility/types").EntityWithRole | null, Error>;
|
|
25
|
+
/**
|
|
26
|
+
* Hook to create a new organization entity.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useCreateEntity(client: EntityClient): import("@tanstack/react-query").UseMutationResult<import("@sudobility/types").Entity, Error, CreateEntityRequest, unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* Hook to update an entity.
|
|
31
|
+
*/
|
|
32
|
+
export declare function useUpdateEntity(client: EntityClient): import("@tanstack/react-query").UseMutationResult<import("@sudobility/types").Entity, Error, {
|
|
33
|
+
entitySlug: string;
|
|
34
|
+
request: UpdateEntityRequest;
|
|
35
|
+
}, unknown>;
|
|
36
|
+
/**
|
|
37
|
+
* Hook to delete an entity.
|
|
38
|
+
*/
|
|
39
|
+
export declare function useDeleteEntity(client: EntityClient): import("@tanstack/react-query").UseMutationResult<void, Error, string, unknown>;
|
|
40
|
+
//# sourceMappingURL=useEntities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEntities.d.ts","sourceRoot":"","sources":["../../src/hooks/useEntities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;mBAKN,MAAM;CACtB,CAAC;AAEF;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,YAAY,uGAW/C;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,4GAaxE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,8HAenD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY;gBAQlC,MAAM;aACT,mBAAmB;YAejC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,mFAcnD"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Entity Hooks
|
|
3
|
+
* @description React Query hooks for entity management
|
|
4
|
+
*/
|
|
5
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
6
|
+
/**
|
|
7
|
+
* Query keys for entity-related queries.
|
|
8
|
+
*/
|
|
9
|
+
export const entityKeys = {
|
|
10
|
+
all: ['entities'],
|
|
11
|
+
lists: () => [...entityKeys.all, 'list'],
|
|
12
|
+
list: () => [...entityKeys.lists()],
|
|
13
|
+
details: () => [...entityKeys.all, 'detail'],
|
|
14
|
+
detail: (slug) => [...entityKeys.details(), slug],
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Hook to list all entities for the current user.
|
|
18
|
+
*/
|
|
19
|
+
export function useEntities(client) {
|
|
20
|
+
return useQuery({
|
|
21
|
+
queryKey: entityKeys.list(),
|
|
22
|
+
queryFn: async () => {
|
|
23
|
+
const response = await client.listEntities();
|
|
24
|
+
if (!response.success) {
|
|
25
|
+
throw new Error(response.error || 'Failed to fetch entities');
|
|
26
|
+
}
|
|
27
|
+
return response.data;
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Hook to get a single entity by slug.
|
|
33
|
+
*/
|
|
34
|
+
export function useEntity(client, entitySlug) {
|
|
35
|
+
return useQuery({
|
|
36
|
+
queryKey: entitySlug ? entityKeys.detail(entitySlug) : ['disabled'],
|
|
37
|
+
queryFn: async () => {
|
|
38
|
+
if (!entitySlug)
|
|
39
|
+
return null;
|
|
40
|
+
const response = await client.getEntity(entitySlug);
|
|
41
|
+
if (!response.success) {
|
|
42
|
+
throw new Error(response.error || 'Failed to fetch entity');
|
|
43
|
+
}
|
|
44
|
+
return response.data;
|
|
45
|
+
},
|
|
46
|
+
enabled: !!entitySlug,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Hook to create a new organization entity.
|
|
51
|
+
*/
|
|
52
|
+
export function useCreateEntity(client) {
|
|
53
|
+
const queryClient = useQueryClient();
|
|
54
|
+
return useMutation({
|
|
55
|
+
mutationFn: async (request) => {
|
|
56
|
+
const response = await client.createEntity(request);
|
|
57
|
+
if (!response.success) {
|
|
58
|
+
throw new Error(response.error || 'Failed to create entity');
|
|
59
|
+
}
|
|
60
|
+
return response.data;
|
|
61
|
+
},
|
|
62
|
+
onSuccess: () => {
|
|
63
|
+
queryClient.invalidateQueries({ queryKey: entityKeys.lists() });
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Hook to update an entity.
|
|
69
|
+
*/
|
|
70
|
+
export function useUpdateEntity(client) {
|
|
71
|
+
const queryClient = useQueryClient();
|
|
72
|
+
return useMutation({
|
|
73
|
+
mutationFn: async ({ entitySlug, request, }) => {
|
|
74
|
+
const response = await client.updateEntity(entitySlug, request);
|
|
75
|
+
if (!response.success) {
|
|
76
|
+
throw new Error(response.error || 'Failed to update entity');
|
|
77
|
+
}
|
|
78
|
+
return response.data;
|
|
79
|
+
},
|
|
80
|
+
onSuccess: (_, variables) => {
|
|
81
|
+
queryClient.invalidateQueries({
|
|
82
|
+
queryKey: entityKeys.detail(variables.entitySlug),
|
|
83
|
+
});
|
|
84
|
+
queryClient.invalidateQueries({ queryKey: entityKeys.lists() });
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Hook to delete an entity.
|
|
90
|
+
*/
|
|
91
|
+
export function useDeleteEntity(client) {
|
|
92
|
+
const queryClient = useQueryClient();
|
|
93
|
+
return useMutation({
|
|
94
|
+
mutationFn: async (entitySlug) => {
|
|
95
|
+
const response = await client.deleteEntity(entitySlug);
|
|
96
|
+
if (!response.success) {
|
|
97
|
+
throw new Error(response.error || 'Failed to delete entity');
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
onSuccess: () => {
|
|
101
|
+
queryClient.invalidateQueries({ queryKey: entityKeys.lists() });
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=useEntities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEntities.js","sourceRoot":"","sources":["../../src/hooks/useEntities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAO9E;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,GAAG,EAAE,CAAC,UAAU,CAAU;IAC1B,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,EAAE,MAAM,CAAU;IACjD,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,CAAU;IAC5C,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAU;IACrD,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,OAAO,EAAE,EAAE,IAAI,CAAU;CACnE,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,MAAoB;IAC9C,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,UAAU,CAAC,IAAI,EAAE;QAC3B,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,YAAY,EAAE,CAAC;YAC7C,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;gBACtB,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,IAAI,0BAA0B,CAAC,CAAC;Y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;YACd,WAAW,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,UAAU,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClE,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Entity Member Hooks
|
|
4
|
+
* @description React Query hooks for entity member management
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.memberKeys = void 0;
|
|
8
|
+
exports.useEntityMembers = useEntityMembers;
|
|
9
|
+
exports.useUpdateMemberRole = useUpdateMemberRole;
|
|
10
|
+
exports.useRemoveMember = useRemoveMember;
|
|
11
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
12
|
+
const useEntities_1 = require("./useEntities");
|
|
13
|
+
/**
|
|
14
|
+
* Query keys for member-related queries.
|
|
15
|
+
*/
|
|
16
|
+
exports.memberKeys = {
|
|
17
|
+
all: (entitySlug) => [...useEntities_1.entityKeys.detail(entitySlug), 'members'],
|
|
18
|
+
list: (entitySlug) => [...exports.memberKeys.all(entitySlug), 'list'],
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Hook to list members of an entity.
|
|
22
|
+
*/
|
|
23
|
+
function useEntityMembers(client, entitySlug) {
|
|
24
|
+
return (0, react_query_1.useQuery)({
|
|
25
|
+
queryKey: entitySlug ? exports.memberKeys.list(entitySlug) : ['disabled'],
|
|
26
|
+
queryFn: async () => {
|
|
27
|
+
if (!entitySlug)
|
|
28
|
+
return [];
|
|
29
|
+
const response = await client.listMembers(entitySlug);
|
|
30
|
+
if (!response.success) {
|
|
31
|
+
throw new Error(response.error || 'Failed to fetch members');
|
|
32
|
+
}
|
|
33
|
+
return response.data;
|
|
34
|
+
},
|
|
35
|
+
enabled: !!entitySlug,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Hook to update a member's role.
|
|
40
|
+
*/
|
|
41
|
+
function useUpdateMemberRole(client) {
|
|
42
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
43
|
+
return (0, react_query_1.useMutation)({
|
|
44
|
+
mutationFn: async ({ entitySlug, memberId, role, }) => {
|
|
45
|
+
const response = await client.updateMemberRole(entitySlug, memberId, role);
|
|
46
|
+
if (!response.success) {
|
|
47
|
+
throw new Error(response.error || 'Failed to update member role');
|
|
48
|
+
}
|
|
49
|
+
return response.data;
|
|
50
|
+
},
|
|
51
|
+
onSuccess: (_, variables) => {
|
|
52
|
+
queryClient.invalidateQueries({
|
|
53
|
+
queryKey: exports.memberKeys.list(variables.entitySlug),
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Hook to remove a member from an entity.
|
|
60
|
+
*/
|
|
61
|
+
function useRemoveMember(client) {
|
|
62
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
63
|
+
return (0, react_query_1.useMutation)({
|
|
64
|
+
mutationFn: async ({ entitySlug, memberId, }) => {
|
|
65
|
+
const response = await client.removeMember(entitySlug, memberId);
|
|
66
|
+
if (!response.success) {
|
|
67
|
+
throw new Error(response.error || 'Failed to remove member');
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
onSuccess: (_, variables) => {
|
|
71
|
+
queryClient.invalidateQueries({
|
|
72
|
+
queryKey: exports.memberKeys.list(variables.entitySlug),
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=useEntityMembers.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Entity Member Hooks
|
|
3
|
+
* @description React Query hooks for entity member management
|
|
4
|
+
*/
|
|
5
|
+
import type { EntityRole } from '@sudobility/types';
|
|
6
|
+
import { EntityClient } from '../network/EntityClient';
|
|
7
|
+
/**
|
|
8
|
+
* Query keys for member-related queries.
|
|
9
|
+
*/
|
|
10
|
+
export declare const memberKeys: {
|
|
11
|
+
all: (entitySlug: string) => readonly ["entities", "detail", string, "members"];
|
|
12
|
+
list: (entitySlug: string) => readonly ["entities", "detail", string, "members", "list"];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Hook to list members of an entity.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useEntityMembers(client: EntityClient, entitySlug: string | null): import("@tanstack/react-query").UseQueryResult<import("@sudobility/types").EntityMember[], Error>;
|
|
18
|
+
/**
|
|
19
|
+
* Hook to update a member's role.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useUpdateMemberRole(client: EntityClient): import("@tanstack/react-query").UseMutationResult<import("@sudobility/types").EntityMember, Error, {
|
|
22
|
+
entitySlug: string;
|
|
23
|
+
memberId: string;
|
|
24
|
+
role: EntityRole;
|
|
25
|
+
}, unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Hook to remove a member from an entity.
|
|
28
|
+
*/
|
|
29
|
+
export declare function useRemoveMember(client: EntityClient): import("@tanstack/react-query").UseMutationResult<void, Error, {
|
|
30
|
+
entitySlug: string;
|
|
31
|
+
memberId: string;
|
|
32
|
+
}, unknown>;
|
|
33
|
+
//# sourceMappingURL=useEntityMembers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEntityMembers.d.ts","sourceRoot":"","sources":["../../src/hooks/useEntityMembers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGvD;;GAEG;AACH,eAAO,MAAM,UAAU;sBACH,MAAM;uBAEL,MAAM;CAE1B,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,YAAY,EACpB,UAAU,EAAE,MAAM,GAAG,IAAI,qGAc1B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY;gBAStC,MAAM;cACR,MAAM;UACV,UAAU;YAkBrB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY;gBAQlC,MAAM;cACR,MAAM;YAarB"}
|