Skip to content

Commit

Permalink
0.0.400
Browse files Browse the repository at this point in the history
  • Loading branch information
ivansglazunov committed Jul 28, 2024
1 parent b52fd19 commit af4e147
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 8 deletions.
84 changes: 79 additions & 5 deletions imports/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,10 @@ export interface DeepClientInstance<L extends Link<Id> = Link<Id>> {
id(start: DeepClientStartItem | Exp, ...path: DeepClientPathItem[]): Promise<Id>;
idLocal(start: DeepClientStartItem, ...path: DeepClientPathItem[]): Id;

name(input: Link<Id> | Id): Promise<string | undefined>;
nameLocal(input: Link<Id> | Id): string | undefined;
name(input: Link<Id> | Id): Promise<string | null>;
nameLocal(input: Link<Id> | Id): string | null;
symbol(input: Link<Id> | Id): Promise<string | null>;
symbolLocal(input: Link<Id> | Id): string | null;

guest(options: DeepClientGuestOptions): Promise<DeepClientAuthResult>;

Expand All @@ -511,6 +513,9 @@ export interface DeepClientInstance<L extends Link<Id> = Link<Id>> {
useMinilinksQuery: (query: Exp, options?: MinilinksQueryOptions) => L[];
useMinilinksSubscription: (query: Exp, options?: MinilinksQueryOptions) => L[];
useMinilinksApply(data, name: string);
useLocalQuery: (query: Exp, options?: MinilinksQueryOptions) => L[];
useLocalSubscription: (query: Exp, options?: MinilinksQueryOptions) => L[];
useLocalApply(data, name: string);
useDeep: typeof useDeep;
DeepProvider: typeof DeepProvider;
DeepContext: typeof DeepContext;
Expand Down Expand Up @@ -811,6 +816,9 @@ export class DeepClient<L extends Link<Id> = Link<Id>> implements DeepClientInst
useMinilinksQuery: (query: Exp, options?: MinilinksQueryOptions) => L[];
useMinilinksSubscription: (query: Exp, options?: MinilinksQueryOptions) => L[];
useMinilinksApply: (data, name: string) => void;
useLocalQuery: (query: Exp, options?: MinilinksQueryOptions) => L[];
useLocalSubscription: (query: Exp, options?: MinilinksQueryOptions) => L[];
useLocalApply: (data, name: string) => void;
local?: boolean;
remote?: boolean;

Expand Down Expand Up @@ -915,6 +923,9 @@ export class DeepClient<L extends Link<Id> = Link<Id>> implements DeepClientInst
this.useMinilinksSubscription = (query: Exp, options?: MinilinksQueryOptions) => useMinilinksSubscription(deep.minilinks, query, options)
// @ts-ignore
this.useMinilinksApply = (data, name: string) => useMinilinksApply(deep.minilinks, name, data)
this.useLocalQuery = this.useMinilinksQuery;
this.useLocalSubscription = this.useMinilinksSubscription;
this.useLocalApply = this.useMinilinksApply;
}

stringify(any?: any): string {
Expand Down Expand Up @@ -1867,6 +1878,40 @@ export class DeepClient<L extends Link<Id> = Link<Id>> implements DeepClientInst
return !!result?.data?.length;
}

/**
* Returns a symbol icon of a link {@link input} that is located in a value of a Symbol link to type of the link {@link input}
*
* @example
* ```
* const userTypeLinkId = await deep.id("@deep-foundation/core", "User");
* const userTypeLinkSymbol = await deep.symbol(userTypeLinkId);
* ```
*/
async symbol(input: Link<Id> | Id): Promise<string | undefined> {
const id = typeof(input) === 'number' || typeof(input) === 'string' ? input : input.id;

// if ((this.minilinks.byId[id] as Link<Id>)?.type_id === this.idLocal('@deep-foundation/core', 'Package')) return (this.minilinks.byId[id] as Link<Id>)?.value?.value;
const {data: [symbol]} = await this.select({
type_id: { _id: ['@deep-foundation/core', 'Symbol'] },
to: { typed: { id } },
});
// @ts-ignore
return symbol?.value?.value || '📍';
};

/**
* Returns a symbol icon of a link {@link input} that is located in a value of a Symbol link to type of the link {@link input} according to links stored in minilinks
*
* @example
* ```
* const userTypeLinkId = await deep.id("@deep-foundation/core", "User");
* const userTypeLinkSymbol = deep.symbolLocal(userTypeLinkId);
* ```
*/
symbolLocal(input: Link<Id> | Id): string | undefined {
return this.minilinks.symbol(input);
}

/**
* Returns a name of a link {@link input} that is located in a value of a contain link pointing to the link {@link input}
*
Expand Down Expand Up @@ -1958,11 +2003,15 @@ export class DeepClient<L extends Link<Id> = Link<Id>> implements DeepClientInst
isolation_provider_id?: number;
}): Promise<void | Handler> {
if (handlerId) {
const { data: handlers }: { data: Handler[] } = await this.select({
const { data: handlers }: { data: Handler[] } = await this.select(({
execution_provider_id: { _eq: execution_provider_id || this.idLocal('@deep-foundation/core', 'JSExecutionProvider'), },
...(isolation_provider_id ? { isolation_provider_id: { _eq: isolation_provider_id, } } : {}),
handler_id: { _eq: handlerId },
}, { table: 'handlers', returning: 'handler_id dist_id src_id' },);
_or: [
{ handler_id: { _eq: handlerId } },
{ dist_id: { _eq: handlerId } },
({ src_id: { _eq: handlerId } } as BoolExpHandler),
],
} as BoolExpHandler), { table: 'handlers', returning: 'handler_id dist_id src_id' },);
if (handlers?.[0]) return handlers?.[0];
} else {
const { data: handlers }: { data: Handler[] } = await this.select({
Expand Down Expand Up @@ -2137,6 +2186,31 @@ export function useDeepGenerator(generatorOptions?: DeepClientOptions<Link<Id>>)
return deep;
}

// export const DeepQueriesContext = createContext<any>(undefined);
// export const DeepQueriesActionsContext = createContext<any>(undefined);
// export function usDeepeQueries() {

// }
// export function usDeepeActions() {

// }
// export const DeepQueriesProvider = React.memo(function DeepQueriesProvider({
// linkId,
// children = null,
// }: {
// linkId: Id;
// children?: any;
// }) {
// const prevA = useContext(DeepQueriesActionsContext);
// const nextQ = useState({
// linkId,
// useQuery: {}, useSubscription: {},
// select: {}, subscription: {}, insert: {}, update: {}, delete: {}, children: {}
// });
// if (prevA)
// return <DeepQueriesActionsContext.Provider value={nextQ}>children</DeepQueriesActionsContext.Provider>;
// }, () => true)

export function DeepProvider({
apolloClient: apolloClientProps,
minilinks: inputMinilinks,
Expand Down
25 changes: 23 additions & 2 deletions imports/minilinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ export interface MinilinksResult<L extends Link<Id>> {
select(query: QueryLink | Id, options?: MinilinksQueryOptions): L[] | any;
id(start: DeepClientStartItem, ...path: DeepClientPathItem[]): Id;
name(input: Link<Id> | Id): string | undefined;
symbol(input: Link<Id> | Id): string | null;
subscribe(query: QueryLink | Id, options?: MinilinksQueryOptions): Observable<L[] | any>;
add(linksArray: any[]): {
add(linksArray: any[], applyName?: string): {
anomalies?: MinilinkError[];
errors?: MinilinkError[];
};
Expand Down Expand Up @@ -187,6 +188,9 @@ export class MinilinksLink<Ref extends Id> {
get name(): string {
return this.ml?.name(this.id);
}
get symbol(): string {
return this.ml?.symbol(this.id);
}
string?: any;
number?: any;
object?: any;
Expand Down Expand Up @@ -384,12 +388,29 @@ export class MinilinkCollection<MGO extends MinilinksGeneratorOptions = typeof M
*/
name(input: Link<Id> | Id): string | undefined {
const id = typeof(input) === 'number' || typeof(input) === 'string' ? input : input?.id;
if (!id) return;
if (!id) return null;
// @ts-ignore
if (this.byId[id]?.type_id === this.id('@deep-foundation/core', 'Package')) return this.byId[id]?.value?.value;
return (this.byType[this.id('@deep-foundation/core', 'Contain')]?.find((c: any) => c?.to_id === id) as any)?.value?.value;
}

/**
* Returns a symbol of a link {@link input} that is located in a value of a contain link pointing to the link {@link input} according to links stored in minilinks
*
* @example
* ```
* const userTypeLinkId = await deep.id("@deep-foundation/core", "User");
* const userTypeLinkName = deep.minilinks.name(userTypeLinkId);
* ```
* Note: "@deep-foundation/core" package, "User" link, Contain link pointing from "@deep-foundation/core" to "User" must be in minilinks
*/
symbol(input: Link<Id> | Id): string | null {
const id = typeof(input) === 'number' || typeof(input) === 'string' ? input : input?.id;
if (!id) return null;
// @ts-ignore
return this.byId[id]?.type?.inByType?.[this.id('@deep-foundation/core', 'Symbol')]?.[0]?.value?.value || '📍';
}

/**
* minilinks.subscribe
* @example
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deep-foundation/deeplinks",
"version": "0.0.399",
"version": "0.0.400",
"license": "Unlicense",
"type": "module",
"scripts": {
Expand Down

0 comments on commit af4e147

Please sign in to comment.