-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c18af1
commit e8e3fc7
Showing
11 changed files
with
505 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum Handle { | ||
Insert, | ||
Update, | ||
Delete, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |