### Download and Run Deep Foundation Unix Starter (Bash) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-macos.md Creates a directory, navigates into it, downloads the unix-start.sh script, makes it executable, and then runs it to start the Deep Foundation components. ```bash mkdir deep && cd deep && curl > ./unix-start.sh && chmod +x unix-start.sh && ./unix-start.sh ``` -------------------------------- ### Install nvm using wget (Bash) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-linux.md Downloads and executes the nvm installation script using the wget command. This provides an alternative method for installing the Node Version Manager. ```bash wget -qO- | bash ``` -------------------------------- ### Install nvm using curl (Bash) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-linux.md Downloads and executes the nvm installation script using the curl command. This is one method to install the Node Version Manager. ```bash curl -o- | bash ``` -------------------------------- ### Install NVM using Wget (Bash) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-macos.md Downloads and executes the NVM installation script using the Wget command. This is an alternative method to install Node Version Manager. ```bash wget -qO- | bash ``` -------------------------------- ### Install Deep using Shell Script (PowerShell) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-windows.md Downloads the `windows-start.ps1` script from the Deep Foundation GitHub repository, creates a 'deep' directory, changes into it, saves the script, sets the execution policy to allow running local scripts, and then executes the downloaded script to install Deep. ```powershell mkdir deep; cd deep; wget -Uri "" -OutFile ".\windows-start.ps1"; Set-ExecutionPolicy -Scope CurrentUser RemoteSigned -Force; .\windows-start.ps1 ``` -------------------------------- ### Install NVM using cURL (Bash) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-macos.md Downloads and executes the NVM installation script using the cURL command. This is one method to install Node Version Manager. ```bash curl -o- | bash ``` -------------------------------- ### Download and run Deep unix starter script (Bash) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-linux.md Creates a directory, navigates into it, downloads the unix-start.sh script from GitHub, makes it executable, and then runs it. This script initializes the Deep environment. ```bash mkdir deep && cd deep && curl > ./unix-start.sh && chmod +x unix-start.sh && ./unix-start.sh ``` -------------------------------- ### Install Node.js Version 14.15.0 using nvm (PowerShell) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-windows.md Installs Node.js version 14.15.0 using the nvm (Node Version Manager) for Windows. This command should be executed in a command prompt or PowerShell with administrative privileges. Note that the command appears twice in the provided snippet. ```powershell nvm install 14.15.0 nvm install 14.15.0 ``` -------------------------------- ### Restarting Deep Foundation Services in GitPod (npm) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-gitpod_env.md These commands restart the core `deeplinks` and `deepcase` services. Use `gitpod-start` when there are no local changes in the packages, and `gitpod-wakeup` when changes exist in the `packages/deeplinks` folder to ensure syncing. ```bash npm run gitpod-start ``` ```bash npm run gitpod-wakeup ``` -------------------------------- ### Install specific Node.js version with nvm (Bash) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-linux.md Uses nvm to download and install a specific version of Node.js (14.15.0). This ensures compatibility with the Deep application requirements. ```bash nvm install 14.15.0 ``` -------------------------------- ### Initializing DeepClient with Admin Authentication (TypeScript) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md This code initializes a DeepClient instance by first creating an unauthenticated client, then authenticating as a guest, and finally logging in as the 'admin' user. It uses environment variables for the GraphQL path and handles SSL configuration. This setup provides a DeepClient instance with full administrative privileges. ```TypeScript import { DeepClient } from "@deep-foundation/deeplinks/imports/client"; import { generateApolloClient } from '@deep-foundation/hasura/client'; import * as dotenv from 'dotenv'; dotenv.config(); async function installPackage() { const apolloClient = generateApolloClient({ path: process.env.NEXT_PUBLIC_GQL_PATH || '', // <<= HERE PATH TO UPDATE ssl: !!~process.env.NEXT_PUBLIC_GQL_PATH.indexOf('localhost') ? false : true, }); const unloginedDeep = new DeepClient({ apolloClient }); const guest = await unloginedDeep.guest(); const guestDeep = new DeepClient({ deep: unloginedDeep, ...guest }); const admin = await guestDeep.login({ linkId: await guestDeep.id('deep', 'admin'), }); const deep = new DeepClient({ deep: guestDeep, ...admin }); } installPackage(); ``` -------------------------------- ### Load nvm into current session (Bash) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-linux.md Sets the NVM_DIR environment variable and sources the nvm.sh script to load nvm into the current shell session. This is necessary after installation or in a new terminal. ```bash export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \\. "$NVM_DIR/nvm.sh" # This loads nvm ``` -------------------------------- ### Defining JavaScript Handler Code (Deep Foundation) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/guide.md This JavaScript arrow function provides the code that will be executed when a Deep Foundation handler is triggered. It is stored within a `SyncTextFile` link. For `dockerSupportsJs` handlers, the function should ideally be `async`, although this simple example is not. The function returns a string "Hello Deep!". ```JavaScript () => { return "Hello Deep!" } ``` -------------------------------- ### Remigrating Deep Foundation Database in GitPod (npm) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-gitpod_env.md These commands are used to clear and reapply database migrations in the GitPod environment. First, run `gitpod-unmigrate` to drop the existing database, and then run `gitpod-migrate` to apply the latest migrations. ```bash npm run gitpod-unmigrate ``` ```bash npm run gitpod-migrate ``` -------------------------------- ### Initializing JavaScript DeepClient (TS) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Provides a comprehensive example of initializing the Deep Foundation JavaScript client. It sets up an Apollo Client, creates an unauthenticated client, logs in as a guest, and then logs in as the admin user to obtain a fully authenticated client instance. ```ts import { DeepClient } from "@deep-foundation/deeplinks/imports/client"; import { generateApolloClient } from "@deep-foundation/hasura/client"; const graphQlPath: string = /* process.env.GQL_URL_WITHOUT_PROTOCOL*/; const ssl: boolean = /* !!~process.env.GQL_URL_WITHOUT_PROTOCOL.indexOf('localhost') ? false : true */; const apolloClient = generateApolloClient({ path: graphQlPath, ssl: ssl, }); const unloginedDeep = new DeepClient({ apolloClient }); const guest = await unloginedDeep.guest(); const guestDeep = new DeepClient({ deep: unloginedDeep, ...guest }); const admin = await guestDeep.login({ linkId: await guestDeep.id('deep', 'admin'), }); const deep = new DeepClient({ deep: guestDeep, ...admin }); ``` -------------------------------- ### Install Specific Node.js Version with NVM (Bash) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-macos.md Uses NVM to download and install Node.js version 14.15.0. This ensures the correct Node.js version is available for the project. ```bash nvm install 14.15.0 ``` -------------------------------- ### Configure NVM Environment Variables (Bash) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-macos.md Sets the NVM directory and sources the NVM script to load its functions into the current shell session. This makes NVM commands available. ```bash export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm ``` -------------------------------- ### Delete PackageQuery and Install Links via ContainTree - TypeScript Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Attempts to delete 'PackageQuery' and 'Install' links by traversing up the 'containTree'. Note: The accompanying text warns against using this as it may delete installed packages. ```TypeScript await deep.delete({ up: { tree_id: { _id: ['@deep-foundation/core', 'containTree'] }, parent: { type_id: { _id: ['@deep-foundation/core', 'Contain'] }, to: { _or: [ { type_id: { _id: ['@deep-foundation/npm-packager', 'Install'] } }, { type_id: { _id: ['@deep-foundation/core', 'PackageQuery'] } } ] } } } }) ``` -------------------------------- ### Querying for dockerSupportsJs Link (Deep Foundation Query) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/guide.md This object represents a Deep Foundation query used to find the link that signifies support for the `dockerSupportsJs` execution environment. The query targets a link by its identifier, specifying the package "@deep-foundation/core" and the name "dockerSupportsJs". This link is required to connect the handler code to its execution environment. ```JSON/JS Object { id: { _id: ["@deep-foundation/core", "dockerSupportsJs"] } } ``` -------------------------------- ### Source ksh profile (Bash) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-linux.md Reloads the ksh profile configuration file. This command is used to apply changes made to the ~/.profile file without closing and reopening the terminal. ```bash . ~/.profile ``` -------------------------------- ### Source bash profile (Bash) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-linux.md Reloads the bash profile configuration file. This command is used to apply changes made to the ~/.bashrc file without closing and reopening the terminal. ```bash source ~/.bashrc ``` -------------------------------- ### Source zsh profile (Bash) Source: https://github.com/deep-foundation/documentation/blob/main/ivansglazunov/install-linux.md Reloads the zsh profile configuration file. This command is used to apply changes made to the ~/.zshrc file without closing and reopening the terminal. ```bash source ~/.zshrc ``` -------------------------------- ### Publish Package (TypeScript) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Inserts multiple links (PackageNamespace, PackageQuery, PackageVersion, Publish) to represent and trigger the publication of a package. It uses deep.reserve to get IDs for new links and links them together appropriately. ```TypeScript const packageNamespaceTypeLinkId = await deep.id("@deep-foundation/npm-packager", "PackageNamespace"); const packageQueryTypeLinkId = await deep.id("@deep-foundation/npm-packager", "PackageQuery"); const packageVersionTypeLinkId = await deep.id("@deep-foundation/npm-packager", "PackageVersion"); const publishTypeLinkId = await deep.id("@deep-foundation/npm-packager", "Publish"); const packageNamespace = ; const packageVersion = ; const packageLinkId = ; const reservedIds = await deep.reserve(2); const packageNamespaceInsertData = { id: reservedIds.pop(), type_id: packageNamespaceTypeLinkId, string: { data: { value: packageNamespace } } }; const packageQueryInsertData = { id: reservedIds.pop(), type_id: packageQueryTypeLinkId, string: { data: { value: packageNamespace } } }; const packageVersionInsertData = { type_id: packageVersionTypeLinkId, string: { data: { value: packageVersion } } } const publishInsertData = { type_id: publishTypeLinkId, from_id: packageLinkId, to_id: packageQueryInsertData.id } await deep.insert([ packageNamespaceInsertData, packageQueryInsertData, packageVersionInsertData, publishInsertData ]) ``` -------------------------------- ### Inserting Router, Route, Handler, and Port Links in Deep Foundation (TypeScript) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md This snippet shows how to create a set of interconnected links in the Deep Foundation graph database to represent a web router configuration. It defines links for a port, route, handler (with code loaded from a file), router, and their relationships (RouterListening, HandleRoute, RouterStringUse, Contain). It uses deep.reserve to get IDs and deep.insert to commit the changes. ```TypeScript const port: number = ; const route: string = ; const handlerCode: string = fs.readFileSync('./routeHandler.js', {encoding: 'utf-8'}); // // Handler file must contain async function like this: async ({req, res, next, deep}) => {} const ownerLinkId = deep.linkId; // Type IDs const portTypeLinkId = await deep.id('@deep-foundation/core', 'Port'); const containTypeLinkId = await deep.id('@deep-foundation/core', 'Contain'); const routerListeningLinkId = await deep.id('@deep-foundation/core', 'RouterListening'); const routerTypeLinkId = await deep.id('@deep-foundation/core', 'Router'); const routerStringUseLinkId = await deep.id('@deep-foundation/core', 'RouterStringUse'); const routeTypeLinkId = await deep.id('@deep-foundation/core', 'Route'); const handleRouteLinkId = await deep.id('@deep-foundation/core', 'HandleRoute'); const handlerTypeLinkId = await deep.id('@deep-foundation/core', 'Handler'); const supportsJsLinkId = await deep.id('@deep-foundation/core', 'dockerSupportsJs'); const syncTextFileTypeLinkId = await deep.id('@deep-foundation/core', 'SyncTextFile'); const reservedIds = await deep.reserve(1); const syncTextFileData: MutationInputLink = { id: reservedIds.pop(), type_id: syncTextFileTypeLinkId, string: { data: { value: handlerCode } }, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } } }; const handlerInsertData: MutationInputLink = { id: reservedIds.pop(), type_id: handlerTypeLinkId, from_id: supportsJsLinkId, to_id: syncTextFileData.id, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } } }; const routeInsertData: MutationInputLink = { id: reservedIds.pop(), type_id: routeTypeLinkId, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } }, }; const routerInsertData: MutationInputLink = { type_id: routerTypeLinkId, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } }, }; const portInsertData: MutationInputLink = { id: reservedIds.pop(), type_id: portTypeLinkId, number: { data: { value: port } }, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } }, }; const routerStringUseData: MutationInputLink = { type_id: routerStringUseLinkId, from: routeInsertData.id, to_id: routerInsertData.id, string: { data: { value: route } }, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } }, }; const routerListeningInsertData: MutationInputLink = { type_id: routerListeningLinkId, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } }, from: { data: routerInsertData }, to_id: portInsertData.id }; const handleRouteInsertData: MutationInputLink = { type_id: handleRouteLinkId, from_id: routeInsertData.id, to_id: handlerInsertData.id, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } }, }; await deep.insert([ syncTextFileData, handlerInsertData, handleRouteInsertData, routeInsertData, routerStringUseData, routerInsertData, routerListeningInsertData, portInsertData ]); ``` -------------------------------- ### Update Deep Foundation Project - Shell Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Performs a full update of the Deep Foundation project. It pulls the latest changes including submodules, installs root dependencies, and then iterates through subdirectories to install dependencies for each package. ```Shell git pull --recurse-submodules && npm install && $( for directory in */ ; do cd ${directory} npm install done ) ``` -------------------------------- ### Delete Contain Links to PackageQuery or Install - TypeScript Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Deletes links of type 'Contain' that point to links of type 'PackageQuery' or 'Install'. This is useful for cleaning up containment relationships related to package management operations. ```TypeScript await deep.delete({ type_id: { _id: ["@deep-foundation/core", "Contain"] }, to: { _or: [ { type_id: { _id: ["@deep-foundation/core", "PackageQuery"] } }, { type_id: { _id: ["@deep-foundation/npm-packager", "Install"] } } ] } }) ``` -------------------------------- ### Querying Users in Deep Foundation (JSON) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/guide.md This JSON-like structure represents a query used within the Deepcase GUI to find all links that have a type link pointing to the 'User' type defined in the '@deep-foundation/core' package. It is typically entered into the editor of a 'Query' link. ```JSON { type_id: { _id: ["@deep-foundation/core", "User"] } } ``` -------------------------------- ### Create Deeplinks Snapshot - Shell Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Navigates to the packages/deeplinks directory, creates a snapshot using an npm script, and then returns to the parent directory. This captures the current state of the deeplinks. ```Shell cd packages/deeplinks && npm run snapshot:create && cd ../..; ``` -------------------------------- ### Creating Deep Foundation Task Type and Instance (JS) Source: https://github.com/deep-foundation/documentation/blob/main/drakonard/gpt4-prompts_to_use-deep.md Demonstrates how to create a new 'Task' type link and subsequently create an instance of that task using the DeepClient `insert` method. It shows how to establish relationships like `Contain` and set string values using nested inserts. ```javascript const typeTypeId = await deep.id('@deep-foundation/core', 'Type'); const containTypeId = await deep.id('@deep-foundation/core', 'Contain'); const valueTypeId = await deep.id('@deep-foundation/core', 'Value'); const stringTypeId = await deep.id('@deep-foundation/core', 'String'); const createTaskType = async (containerId) => { const newTaskType = await deep.insert({ type_id: typeTypeId, in: { data: { type_id: containTypeId, from_id: containerId, string: { data: { value: 'Task' } }, }, }, }); const newValueLink = await deep.insert({ from_id: newTaskType.data[0].id, to_id: stringTypeId, type_id: valueTypeId, }); return newTaskType.data[0]; }; const createTask = async (containerId, taskTypeId, description) => { const newTaskInstance = await deep.insert({ type_id: taskTypeId, string: { data: { value: description } }, in: { data: { type_id: containTypeId, from_id: containerId, }, }, }); return newTaskInstance.data[0]; }; ``` -------------------------------- ### Deep Foundation Link Position Usage Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/npm-packager.md Illustrates how a specific link 'a' can be used in the 'from', 'type', or 'to' positions within another link structure. ```Deep Foundation Notation (a 0 0) ``` ```Deep Foundation Notation (0 a 0) ``` ```Deep Foundation Notation (0 0 a) ``` -------------------------------- ### Deep Foundation Link Basic Notation Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/npm-packager.md Shows the fundamental structure of a Deep Foundation link. ```Deep Foundation Notation (from type to) ``` -------------------------------- ### Creating Router, Route, Handler, and Port using Serial Operations in Deep Foundation (TypeScript) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md This snippet demonstrates how to create a set of interconnected Deep Foundation links and objects atomically using `deep.serial`. It reserves necessary IDs, then defines a series of `createSerialOperation` calls to insert links for a SyncTextFile (containing handler code), a Handler, a Route, a Router, a RouterStringUse (connecting the route to the router with a string value), and a Port (with a number value), finally linking the router to the port. This ensures all operations succeed or fail together. ```TypeScript const portTypeLinkId = await deep.id('@deep-foundation/core', 'Port'); const containTypeLinkId = await deep.id('@deep-foundation/core', 'Contain'); const routerListeningLinkId = await deep.id('@deep-foundation/core', 'RouterListening'); const routerTypeLinkId = await deep.id('@deep-foundation/core', 'Router'); const routerStringUseLinkId = await deep.id('@deep-foundation/core', 'RouterStringUse'); const routeTypeLinkId = await deep.id('@deep-foundation/core', 'Route'); const handleRouteLinkId = await deep.id('@deep-foundation/core', 'HandleRoute'); const handlerTypeLinkId = await deep.id('@deep-foundation/core', 'Handler'); const supportsJsLinkId = await deep.id('@deep-foundation/core', 'dockerSupportsJs'); const syncTextFileTypeLinkId = await deep.id('@deep-foundation/core', 'SyncTextFile'); const code = ; const route = ; const port = ; const ownerLinkId = ; const reservedIds = await deep.reserve(6); const syncTextFileLinkId = reservedIds.pop(); const handlerLinkId = reservedIds.pop(); const routeLinkId = reservedIds.pop(); const routerStringUseLinkId = reservedIds.pop(); const routerLinkId = reservedIds.pop(); const portLinkId = reservedIds.pop(); await deep.serial({ operations: [ createSerialOperation({ table: 'links', type: 'insert', objects: { id: syncTextFileLinkId, type_id: syncTextFileTypeLinkId, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } } } }), createSerialOperation({ table: 'strings', type: 'insert', objects: { link_id: syncTextFileLinkId, value: code } }), createSerialOperation({ table: 'links', type: 'insert', objects: { id: handlerLinkId, type_id: handlerTypeLinkId, from_id: supportsJsLinkId, to_id: syncTextFileLinkId, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } } } }), createSerialOperation({ table: 'links', type: 'insert', objects: { id: routeLinkId, type_id: routeTypeLinkId, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } }, } }), createSerialOperation({ table: 'links', type: 'insert', objects: { type_id: handleRouteLinkId, from_id: routeLinkId, to_id: handlerLinkId, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } }, } }), createSerialOperation({ table: 'links', type: 'insert', objects: { id: routerLinkId, type_id: routerTypeLinkId, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } }, } }), createSerialOperation({ table: 'links', type: 'insert', objects: { id: routerStringUseLinkId, type_id: routerStringUseTypeLinkId, from: routeLinkId, to_id: routerLinkId, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } }, } }), createSerialOperation({ table: 'strings', type: 'insert', objects: { link_id: routerStringUseLinkId, value: route } }), createSerialOperation({ table: 'links', type: 'insert', objects: { id: portLinkId, type_id: portTypeLinkId, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } }, } }), createSerialOperation({ table: 'numbers', type: 'insert', objects: { link_id: portLinkId, value: port } }), createSerialOperation({ table: 'links', type: 'insert', objects: { type_id: routerListeningLinkId, from_id: routerLinkId, to_id: portLinkId, in: { data: { type_id: containTypeLinkId, from_id: ownerLinkId } }, } }), ] }); ``` -------------------------------- ### Deleting Deep Foundation Package and Version Links (JS) Source: https://github.com/deep-foundation/documentation/blob/main/drakonard/gpt4-prompts_to_use-deep.md Illustrates how to delete a specific package link and its associated incoming `PackageVersion` links in a single operation using the DeepClient `delete` method. It highlights the use of the `_or` condition within the `where` clause to target multiple links simultaneously. ```javascript const deletePackage = async (packageId) => { const packageTypeId = await deep.id('@deep-foundation/core', 'Package'); const packageVersionTypeId = await deep.id('@deep-foundation/core', 'PackageVersion'); // Delete the Package link and the PackageVersion link in a single deep.delete call const deletedLinks = await deep.delete({ _or: [ { to: { id: packageId }, type_id: packageVersionTypeId }, // Delete PackageVersion links { id: packageId, type_id: packageTypeId }, // Delete the Package link ], }); return deletedLinks; }; ``` -------------------------------- ### Defining Task Creation Functions (JavaScript) Source: https://github.com/deep-foundation/documentation/blob/main/drakonard/gpt4-prompts_to_use-deep.md This snippet defines the asynchronous function signatures for `createTaskType` and `createTask`. `createTaskType` is designed to create the `Task` node type itself, while `createTask` is intended to create an instance of a `Task` link, associating it with a container and a description. The implementation details for creating the links are omitted. ```JavaScript const createTaskType = async (containerId) => { ... } const createTask = async (containerId, taskTypeId, description) => { ... } ``` -------------------------------- ### Inserting Deep Foundation Handler using Serial Operations (TypeScript) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Shows how to insert a handler configuration using a serial transaction. It creates links for the handler code (`SyncTextFile`), the handler itself (`Handler`), and the trigger (`HandleInsert`), linking them appropriately and containing them within a package. ```TypeScript const syncTextFileTypeLinkId = await deep.id("@deep-foundation/core", "SyncTextFile") const containTypeLinkId = await deep.id("@deep-foundation/core", "Contain") const supportsJsLinkId = await deep.id("@deep-foundation/core", "dockerSupportsJs" /* | "plv8SupportsJs" */ ) const handlerTypeLinkId = await deep.id("@deep-foundation/core", "Handler") const handleOperationLinkId = await deep.id("@deep-foundation/core", "HandleInsert" /* | HandleUpdate | HandleDelete */); const triggerTypeLinkId = ; const packageLinkId = ; const reservedIds = await deep.reserve(2); const syncTextFileLinkId = reservedIds.pop(); const handlerLinkId = reservedIds.pop(); await deep.serial({ operations: [ createSerialOperation({ table: 'links', type: 'insert', objects: { id: syncTextFileLinkId, type_id: syncTextFileTypeLinkId, in: { data: { type_id: containTypeLinkId, from_id: packageLinkId, string: { data: { value: "MyInsertHandlerCode" } }, } } } }), createSerialOperation({ table: 'strings', type: 'insert', objects: { link_id: syncTextFileLinkId, value: fs.readFileSync(path.join(__dirname, 'handler.js'), { encoding: 'utf-8' }), // Handler file must contain async function like this: async ({deep, data: {oldLink, newLink, triggeredByLinkId}}) => {}, } }), createSerialOperation({ table: 'links', type: 'insert', objects: { id: handlerLinkId, type_id: handlerTypeLinkId, from_id: supportsJsLinkId, to_id: syncTextFileLinkId, in: { data: { type_id: containTypeLinkId, from_id: packageLinkId, string: { data: { value: "MyInsertHandler" } }, } } } }), createSerialOperation({ table: 'links', type: 'insert', objects: { type_id: handleOperationLinkId, from_id: triggerTypeLinkId, to_id: handlerLinkId, in: { data: { type_id: containTypeLinkId, from_id: packageLinkId, string: { data: { value: "HandleOperation" } }, } } } }), ] }) ``` -------------------------------- ### Set Gitpod GQL Path Environment Variable - Shell Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Sets the NEXT_PUBLIC_GQL_PATH environment variable in a Gitpod environment by extracting the protocol and path from the Gitpod URL for port 3006 and appending '/gql'. This is necessary for configuring the GraphQL endpoint. ```Shell NEXT_PUBLIC_GQL_PATH_WITH_PROTOCOL=$(gp url 3006) export NEXT_PUBLIC_GQL_PATH="${NEXT_PUBLIC_GQL_PATH_WITH_PROTOCOL#*://}/gql" ``` -------------------------------- ### Deep Foundation Package Dependency Notation Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/npm-packager.md Demonstrates the current method for specifying a dependency on 'package1' from 'package2' by using links from 'package1' within the structure of links contained by 'package2'. ```Deep Foundation Notation (package2 Contain (a 0 0)) ``` ```Deep Foundation Notation (package2 Contain (a 0 a 0)) ``` ```Deep Foundation Notation (package2 Contain (0 0 a)) ``` -------------------------------- ### Load Last Deeplinks Snapshot - Shell Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Navigates to the packages/deeplinks directory, loads the most recent snapshot using an npm script, and then returns to the parent directory. This restores the deeplinks state from a previous snapshot. ```Shell cd packages/deeplinks && npm run snapshot:last && cd ../..; ``` -------------------------------- ### Querying Specific Package Link by ID (JSON) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md A simple JSON query structure to select a specific package link using its unique identifier, which is an array containing the package name. ```json { "id": { "_id": [ "@deep-foundation/core" ] } } ``` -------------------------------- ### Inserting Deep Foundation Handler using Reserved IDs and Insert (TypeScript) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Provides an alternative method for inserting a handler configuration. It reserves IDs beforehand and then uses a single `deep.insert` call with pre-constructed link objects (`MutationInputLink`) to create the handler code, handler, and trigger links. ```TypeScript const syncTextFileTypeLinkId = await deep.id("@deep-foundation/core", "SyncTextFile") const containTypeLinkId = await deep.id("@deep-foundation/core", "Contain") const supportsJsLinkId = await deep.id("@deep-foundation/core", "dockerSupportsJs" /* | "plv8SupportsJs" */ ) const handlerTypeLinkId = await deep.id("@deep-foundation/core", "Handler") const handleOperationLinkId = await deep.id("@deep-foundation/core", "HandleInsert" /* | HandleUpdate | HandleDelete */); const reservedIds = await deep.reserve(2); const syncTextFileInsertData: MutationInputLink = { id: reservedIds.pop(), type_id: syncTextFileTypeLinkId, string: { data: { value: fs.readFileSync(path.join(__dirname, 'notifyInsertHandler.js'), { encoding: 'utf-8' }); // Handler file must contain async function like this: async ({deep, data: {oldLink, newLink, triggeredByLinkId}}) => {} }, }, in: { data: { type_id: containTypeLinkId, from_id: packageLinkId, string: { data: { value: "MyInsertHandlerCode" } }, } } } const handlerInsertData: MutationInputLink = { id: reservedIds.pop(), type_id: handlerTypeLinkId, from_id: supportsJsLinkId, to_id: syncTextFileInsertData.id, in: { data: { type_id: containTypeLinkId, from_id: packageLinkId, string: { data: { value: "MyInsertHandler" } }, } } }; const handleOperationData: MutationInputLink = { type_id: handleOperationLinkId, from_id: triggerTypeLinkId, to_id: handlerInsertData.id, in: { data: { type_id: containTypeLinkId, from_id: packageLinkId, string: { data: { value: "HandleOperation" } }, } } } await deep.insert([ syncTextFileInsertData, handlerInsertData, handleOperationData ]) ``` -------------------------------- ### Logging In as Admin with DeepClient (TS) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Illustrates the process of logging into the Deep Foundation client as the 'admin' user. It first retrieves the link ID for the 'admin' user using `deep.id` and then calls the `deep.login` method. ```ts const adminLinkId = await deep.id('deep', 'admin'); await deep.login({ linkId: adminLinkId, }); ``` -------------------------------- ### Deleting Package and Instance Links (TS) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Provides two separate `deep.delete` calls to remove a package and its associated instance links. The first query targets links contained by a link whose type is contained by a link from the package string value. The second targets the package link itself. ```ts const packageName = "@deep-foundation/action-sheet"; await deep.delete({ up: { "tree_id": { "_id": [ "@deep-foundation/core", "containTree" ] }, parent: { type_id: { _id: ["@deep-foundation/core", "Contain"] }, to: { type: { in: { type_id: { _id: ["@deep-foundation/core", "Contain"] }, from: { string: { value: { _eq: packageName } } } } } } } } }) await deep.delete({ up: { "tree_id": { "_id": [ "@deep-foundation/core", "containTree" ] }, parent: { type_id: { _id: ["@deep-foundation/core", "Contain"] }, to: { type_id: { _id: ["@deep-foundation/core", "Package"] }, string: { value: packageName } } } } }) ``` -------------------------------- ### Remigrate Deep Foundation - Shell Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Runs the npm script to remigrate the Deep Foundation database. This command should be executed while the Deep Foundation engine is running to apply database schema changes. ```Shell npm run gitpod-remigrate ``` -------------------------------- ### Perform Multiple Operations Serially with DeepClient (TypeScript) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/deep-client.md Demonstrates how to use `deep.serial` to execute multiple database operations (insert, update, delete) in a single network request. Each operation is defined using `createSerialOperation`, specifying the table, type, and relevant data or conditions. This approach optimizes performance by minimizing network round trips. ```TypeScript await deep.serial({ operations: [ createSerialOperation({ table: 'links', type: 'insert', objects: [ { type_id: typeTypeLinkId, }, ], }), createSerialOperation({ table: 'strings', type: 'update', exp: { id: linkId, }, value: { value: 'newStringValue', }, }), createSerialOperation({ table: 'links', type: 'delete', exp: { id: linkId, }, }), createSerialOperation({ table: 'strings', type: 'insert', objects: { link_id, value, }, }), ], }); ``` -------------------------------- ### Querying Package Links via Contain Tree (JSON) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md A JSON query structure to find links contained within the 'containTree' where the parent link has an ID corresponding to a specific package name. ```json { "up": { "parent": { "id": { "_id": ["@freephoenix888/boolean"] } }, "tree_id": { "_id": ["@deep-foundation/core", "containTree"] } } } ``` -------------------------------- ### Grant Admin Permissions to All Packages (TypeScript) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Inserts a Join link from deep:users:packages to deep:admin using a variable for the Join type ID, granting admin permissions to all packages. ```TypeScript const joinTypeLinkId = await deep.id("@deep-foundation/core", "Join"); await deep.insert([ { type_id: joinTypeLinkId, from_id: await deep.id('deep', 'users', 'packages'), to_id: await deep.id('deep', 'admin'), }, ]) ``` -------------------------------- ### Inserting Link with Value (TS) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Shows how to insert a new link that also carries a value (string, number, or object). The `deep.insert` method is used, specifying the link ID and the value. The value table is determined by the type of the provided value. ```ts const value = /* "Value" / 123 / {property: value} */; const linkId = ; await deep.insert( { link_id: linkId, value: value }, { table: `${typeof value}s` } ); ``` -------------------------------- ### Grant Admin Permissions to All Packages (TypeScript) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Inserts a Join link between the deep:users:packages group and the deep:admin group, effectively granting admin permissions to all packages. ```TypeScript await deep.insert([ { type_id: await deep.id("@deep-foundation/core", "Join"), from_id: await deep.id('deep', 'users', 'packages'), to_id: await deep.id('deep', 'admin'), }, ]) ``` -------------------------------- ### Querying Publish Links via Contain Tree (JSON) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md A JSON query structure to find links that are contained within the 'containTree' and whose parent link is of the type 'Publish' from the '@deep-foundation/npm-packager' package. ```json { "up": { "tree_id": { "_id": ["@deep-foundation/core", "containTree"] }, "parent": { "type_id": { "_id": ["@deep-foundation/npm-packager", "Publish"] } } } } ``` -------------------------------- ### Grant Admin and Package Permissions to Specific Package (TypeScript) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Inserts two Join links from a specific packageLinkId: one to deep:users:packages and one to deep:admin. This grants the specific package membership in both groups. ```TypeScript const joinTypeLinkId = await deep.id("@deep-foundation/core", "Join"); const packageLinkId = ; await deep.insert([ { type_id: joinTypeLinkId, from_id: packageLinkId, to_id: await deep.id('deep', 'users', 'packages'), }, { type_id: joinTypeLinkId, from_id: packageLinkId, to_id: await deep.id('deep', 'admin'), }, ]) ``` -------------------------------- ### Selecting Link by Object Value Content (TS) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Shows how to query for a link whose value (specifically an object value) contains a specified sub-object or property using the `_contains` operator within the `deep.select` method. ```ts const value = PLACEHOLDER; await deep.select({ [typeof value]: { value: { _contains: value, }, }, }); ``` -------------------------------- ### Retrieving Core Deep Link Type IDs (JavaScript) Source: https://github.com/deep-foundation/documentation/blob/main/drakonard/gpt4-prompts_to_use-deep.md This snippet retrieves the unique identifiers (IDs) for the core `Type`, `Contain`, and `Value` link types from the `@deep-foundation/core` package using the `deep.id` method. These IDs are essential for creating instances of these types or defining relationships involving them within the Deep system. ```JavaScript const typeTypeId = await deep.id('@deep-foundation/core', 'Type'); const containTypeId = await deep.id('@deep-foundation/core', 'Contain'); const valueTypeId = await deep.id('@deep-foundation/core', 'Value'); ``` -------------------------------- ### Updating Link Value with DeepClient (TS) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Demonstrates how to update the value of an existing link using the `deep.update` method. It requires the link's ID and the new value. The table for the value is inferred from the value's type. ```ts const linkId = PLACEHOLDER; const value = PLACEHOLDER; await deep.update( { link_id: linkId }, { value: value }, { table: (typeof value) + 's' } ) ``` -------------------------------- ### Perform Hard Cleaning - Shell Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Executes a sequence of npm scripts for a hard clean of the Deep Foundation environment. This typically involves unmigrating, clearing Docker containers, removing migration files, restarting the engine, and remigrating. ```Shell npm run gitpod-unmigrate; npm run docker-clear; npm run rm-migrates; npm run gitpod-engine; npm run gitpod-migrate; ``` -------------------------------- ### Querying Links Up to Tree and Parent Link (TS) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md A query object structure (used within `deep.select`) to find links that are related upwards (`up`) through a specified tree (`treeId`) to a particular parent link (`parent_id`). ```ts { up: { tree_id: treeId, parent_id: parentId } } ``` -------------------------------- ### Querying Links Up to Tree and Link (TS) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md A query object structure (used within `deep.select`) to find links that are related upwards (`up`) through a specified tree (`treeId`) to a particular target link (`link_id`). ```ts { up: { tree_id: treeId, link_id: parentId } } ``` -------------------------------- ### Insert Link and Contain It - TypeScript Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Performs a serial operation to insert a new link and immediately create a 'Contain' link from the current deep link ID to the newly inserted link. This is a common pattern for organizing links. ```TypeScript await deep.serial({ operations: [ { table: 'links', type: 'insert', objects: [ { from_id: deep.linkId, type_id: await deep.id("@freephoenix888/object-to-types-async-converter", "Convert"), to_id: 1140, in: { data: { type_id: await deep.id("@deep-foundation/core", "Contain"), from_id: deep.linkId } } } ] } ] }) ``` -------------------------------- ### Deleting Package Instance Links Contained by deep.linkId (TS) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Deletes links that are instances of a specific package and are contained directly by the current client's link (`deep.linkId`). It uses a complex query targeting links contained by `deep.linkId` whose type is contained by a link from the specified package string value. ```ts const PACKAGE_NAME = "@deep-foundation/device"; await deep.delete({ up: { parent: { type_id: { _id: ["@deep-foundation/core", "Contain"] }, from_id: deep.linkId, to: { type: { in: { type_id: { _id: ["@deep-foundation/core", "Contain"] }, from: { string: { value: { _eq: PACKAGE_NAME } } } } } } } } }) ``` -------------------------------- ### Query Contain Link Pointing to Specific Link (TypeScript) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md Uses deep.select to find Contain links where the to_id matches a given linkId. This retrieves the links that contain the specified link. ```TypeScript const linkId = ; await deep.select( { to_id: linkId, type_id: { _id: [ '@deep-foundation/core', 'Contain' ] } } ); ``` -------------------------------- ### Querying Links Down to Tree and Link (TS) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md A query object structure (used within `deep.select`) to find links that are related downwards (`down`) through a specified tree (`treeId`) to a particular target link (`link_id`). ```ts { down: { tree_id: treeId, link_id: parentId } } ``` -------------------------------- ### Querying Links Down to Tree and Parent Link (TS) Source: https://github.com/deep-foundation/documentation/blob/main/freephoenix888/cheatsheet.md A query object structure (used within `deep.select`) to find links that are related downwards (`down`) through a specified tree (`treeId`) to a particular parent link (`parent_id`). ```ts { down: { tree_id: treeId, parent_id: parentId } } ```