Skip to content

Commit

Permalink
Add integrationsa nd deep.json
Browse files Browse the repository at this point in the history
  • Loading branch information
FreePhoenix888 committed Jun 17, 2023
1 parent 8c18af1 commit e8e3fc7
Show file tree
Hide file tree
Showing 11 changed files with 505 additions and 10 deletions.
293 changes: 293 additions & 0 deletions deep.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"name": "@deep-foundation/logger",
"keywords": [],
"keywords": [
"deep-package"
],
"version": "0.0.1",
"description": "",
"repository": {
Expand All @@ -18,6 +20,7 @@
"/dist",
"./deep.json"
],
"version": "1.0.0",
"dependencies": {
"@deep-foundation/core": "^0.0.2"
},
Expand All @@ -32,4 +35,4 @@
"peerDependencies": {
"@deep-foundation/deeplinks": "~0.0.164"
}
}
}
3 changes: 0 additions & 3 deletions src/fake-function.ts

This file was deleted.

128 changes: 128 additions & 0 deletions src/get-handle-insert-serial-operations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { DeepClient, SerialOperation } from '@deep-foundation/deeplinks/imports/client';
import { getHandlerLinkId } from './get-handler-link-id';
import { Handle } from './handle';
import { createSerialOperation } from '@deep-foundation/deeplinks/imports/gql';


/**
* Gets insert serial operations for handle
*
* @example
```ts
```
*/
export async function getHandleInsertSerialOperations(
param: GetHandleInsertSerialOperations
) {
const {
deep,
triggerTypeLinkId,
containerLinkId = deep.linkId,
containTypeLinkId = await deep.id('@deep-foundation/core', 'Contain'),
containValue,
} = param;

if (!deep) {
throw new Error(`DeepClient is required`);
}

if (!triggerTypeLinkId) {
throw new Error(`Trigger type link id is required`);
}

if (!containerLinkId) {
throw new Error(`Container link id is required`);
}

let linkIds = param.linkIds;
if (!linkIds) {
const reservedLinkIds = await deep.reserve(2);
linkIds = {
handleLinkId: reservedLinkIds[0],
containLinkId: reservedLinkIds[1],
};
}

const serialOperations = [];

const handleInsertSerialOperation = createSerialOperation({
type: 'insert',
table: 'links',
objects: {
id: linkIds.handleLinkId,
type_id: param.handleTypeLinkId,
from_id: triggerTypeLinkId,
to_id: param.handlerLinkId,
},
});
serialOperations.push(handleInsertSerialOperation);

const containInsertSerialOperation = createSerialOperation({
type: 'insert',
table: 'links',
objects: {
type_id: containTypeLinkId,
from_id: containerLinkId,
to_id: linkIds.handleLinkId,
},
});
serialOperations.push(containInsertSerialOperation);

if (containValue) {
const valueOfContainInsertSerialOperation = createSerialOperation({
type: 'insert',
table: 'strings',
objects: {
link_id: linkIds.containLinkId,
value: containValue,
},
});
serialOperations.push(valueOfContainInsertSerialOperation);
}

return serialOperations;
}

export type GetHandleInsertSerialOperations = {
/**
* DeepClient instance
*/
deep: DeepClient;
linkIds?: {
/**
* Link id of the handle that will be inserted
*/
handleLinkId?: number;
/**
* Link id of the contain that will be inserted
*/
containLinkId?: number;
};
/**
* Id of link that will be handled
*/
triggerTypeLinkId: number;
/**
* Link where handle will be contained
*/
containerLinkId?: number;
/**
* Contain type link id
*/
containTypeLinkId?: number;
/**
* Value of contain link that will be inserted
*/
containValue?: string;
/**
* Handle type link id
*/
handleTypeLinkId: number;
/**
* Link id of the handler
*/
handlerLinkId: number;
};


21 changes: 21 additions & 0 deletions src/get-handle-link-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { DeepClient } from "@deep-foundation/deeplinks/imports/client";
import { Handle } from "./handle";

export async function getHandleLinkId(param: GetHandleLinkIdParam) {
const {deep, handler} = param;

if(!deep) {
throw new Error(`DeepClient is required`)
}

if(!handler) {
throw new Error(`Handler is required`)
}

return await deep.id("@deep-foundation/core", `Handle${Handle[handler]}`)
}

export interface GetHandleLinkIdParam {
deep: DeepClient;
handler: Handle
}
14 changes: 14 additions & 0 deletions src/get-handler-link-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { DeepClient } from "@deep-foundation/deeplinks/imports/client";
import { Handle } from "./handle";
import { LOGGER_PACKAGE_NAME } from "./package-name";

export async function getHandlerLinkId(param: GetHandlerLinkParam) {
const {deep, handler} = param;

return deep.id(LOGGER_PACKAGE_NAME, `${Handle[handler]}Handler`)
}

export interface GetHandlerLinkParam {
deep: DeepClient;
handler: Handle;
}
5 changes: 5 additions & 0 deletions src/handle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum Handle {
Insert,
Update,
Delete,
}
33 changes: 33 additions & 0 deletions src/insert-handle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { DeepClient } from '@deep-foundation/deeplinks/imports/client';
import { Handle } from './handle';
import { MutationInputLink } from '@deep-foundation/deeplinks/imports/client_types';

export async function insertHandle(param: InsertHandleParam) {
const { deep, handle, triggerTypeLinkId, containerLinkId } = param;

const insertData: MutationInputLink = {
type_id: await deep.id('@deep-foundation/core', `Handle${Handle[handle]}`),
from_id: triggerTypeLinkId,
to_id: await deep.id('@deep-foundation/logger', `${Handle[handle]}Handler`),
in: {
data:
containerLinkId === null
? []
: [
{
type_id: await deep.id('@deep-foundation/core', 'Contain'),
from_id: containerLinkId ?? deep.linkId,
},
],
},
};

await deep.insert(insertData);
}

export interface InsertHandleParam {
deep: DeepClient;
handle: Handle;
triggerTypeLinkId: number;
containerLinkId?: number | null;
}
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export {fakeFunction} from './fake-function'
export {MY_PACKAGE_NAME} from './package-name'
export {insertHandle, InsertHandleParam} from './insert-handle'
export { LOGGER_PACKAGE_NAME } from "./package-name";
export { Handle } from "./handle";
2 changes: 1 addition & 1 deletion src/package-name.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const MY_PACKAGE_NAME = "@deep-foundation/logger";
export const LOGGER_PACKAGE_NAME = "@deep-foundation/logger";

0 comments on commit e8e3fc7

Please sign in to comment.