{
  "name": "cyypher",
  "version": "0.1.0",
  "description": "Cypher ORM + client for redis-graph",
  "author": "Ian Hunter <ian@rel.run>",
  "license": "ISC",
  "main": "dist/index.mjs",
  "tsup": {
    "entry": [
      "src/index.ts"
    ],
    "splitting": false,
    "sourcemap": true,
    "clean": true
  },
  "dependencies": {
    "@ptkdev/logger": "^1.8.0",
    "lodash": "^4.17.21",
    "redisgraph.js": "^2.3.0",
    "uuid": "^8.3.2"
  },
  "devDependencies": {
    "tsup": "^5.11.13"
  },
  "scripts": {
    "clean": "rm -rf ./dist",
    "build": "tsup --format esm",
    "build:watch": "tsup --watch --format esm"
  },
  "readme": "# cyypher\n\nCypher ORM + client for redis-graph.\n\n## Inspiration\n\nThis project powers the [Rel](https://github.com/rel-js/rel) backend framework. We needed a more robust, relational client for redis-graph.\n\nIf you are looking for a more complete schema -> GraphQL server, definitely take a look at our framework.\n\n## Quickstart\n\n### 1. Install npm package\n\nAdd the cyypher npm package via your package manager of choice.\n\n```sh\nnpm install cyypher\n```\n\n```sh\nyarn add cyypher\n```\n\n```sh\npnpm add cyypher\n```\n\n### 2. Initialize the client\n\n```\nimport cyypher from \"cyypher\"\n```\n\nor with custom connection\n\n```\nimport { Client } from \"cyypher\"\n\nconst cyypher = new Client({\n  host: \"...\",\n  port: 1234,\n  auth: {\n    username: \"redis\",\n    password: \"1234\n  }\n})\n```\n\n## Usage\n\n### `find(label, where)`\n\nFinds a single node by label and params.\n\n```ts\ncyypher.find('Person', { _id: '123' })\ncyypher.find('Person', { name: 'Ian' })\n```\n\n### `list(label, where)`\n\nList multiple nodes by label and params.\n\n```ts\n// List everyone\ncyypher.list('Person', {})\n\n// List only admins\ncyypher.list('Person', { where: { admin: true } })\n```\n\n### `count(label, where)`\n\nCount number of matching nodes.\n\n```ts\n// total count of a label\ncyypher.count('Person')\n\n// with where params\ncyypher.count('Person', { where: { admin: true } })\n```\n\n### `create(label, where)`\n\n```ts\ncyypher.create('Person', { name: 'Inigo Montoya' })\n```\n\nEnsure uniqueness across a field:\n\n```ts\ncyypher.create('Person', { name: 'Inigo Montoya' })\n\n// this call is idempotent\ncyypher.create('Person', { name: 'Inigo Montoya', __unique: 'name' })\n```\n\n### `findOrCreate(label, where, updateParams)`\n\nA find() and then create() call that will return an existing node if found.\n\n```ts\ncyypher.findOrCreate('Person', { name: 'Inigo Montoya' })\n// this won't create a new node\ncyypher.findOrCreate('Person', { name: 'Inigo Montoya' })\n// this will create a new node\ncyypher.findOrCreate('Person', { name: 'Vizzini' })\n```\n\nOptional: `create` params:\n\n```ts\ncyypher.findOrCreate(\n  'Person',\n  { _id: '1xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' },\n  { name: 'Inigo Montoya' }\n)\n```\n\n> Note: It is not necessary to re-specify find params in the create params, the two will be merged together.\n\n### `merge(label, where, updateParams)`\n\nSimilar to `findOrCreate` but uses cypher's native merge command:\n\n```ts\ncyypher.merge('Person', { name: 'Inigo Montoya' })\n```\n\n### `update(label, id, updateParams)`\n\nUpdate a node based on ID.\n\n```ts\ncyypher.merge('Person', '123', { name: 'Inigo Montoya' })\n```\n\n### `updateBy(label, where, updateParams)`\n\nUpdate multiple nodes by params.\n\n```ts\ncyypher.updateBy(\n  'Person',\n  { name: 'Inigo Montoya' },\n  { name: 'Mandy Patinkin' }\n)\n```\n\n### `delete(label, id)`\n\nDelete a node by ID.\n\n```ts\ncyypher.delete('Person', '123')\n```\n\n### `deleteBy(label, params)`\n\nDelete multiple nodes by params.\n\n```ts\ncyypher.deleteBy('Person', { name: 'Inigo Montoya' })\n```\n\n### `listRelationship(from, rel, to, opts)`\n\nList relationships between nodes.\n\n| Param      | Type                           | Required | Description                    | Default |\n| :--------- | :----------------------------- | -------- | ------------------------------ | ------- |\n| `from`     | `string` \\| `object` \\| `Node` | yes      | From node                      |\n| `rel`      | `string` \\| `object` \\| `Node` | yes      | Relationship                   |\n| `to`       | `string` \\| `object` \\| `Node` | yes      | To node                        |\n| Options    |                                |          |                                |         |\n| `singular` | `boolean`                      |          | Singular relationship?         | false   |\n| `skip`     | `number`                       |          | Skip offset                    | 0       |\n| `limit`    | `number`                       |          | Number of results              |\n| `order`    | `object`                       |          | Order the results              |\n| `orderRaw` | `string`                       |          | Direct order string to pass in |\n\n```ts\n// List N-1 between many nodes\ncyypher.listRelationship('Person', 'FRIEND', { _id: '456' })\n\n// List all FRIEND relationships between Persons\ncyypher.listRelationship('Person', 'FRIEND', 'Person')\n\n// List 1-1 between two nodes\ncyypher.listRelationship({ _id: '123' }, 'FRIEND', { _id: '456' })\n\n// You can also pass a node instance\nimport { ref } from 'cyypher'\nconst fromNode = await cyypher.find('Person', 'ID')\nconst toNode = await cyypher.find('Person', 'ID2')\n\ncyypher.listRelationship(ref(fromNode), 'FRIEND', ref(toNode))\n\n// List 1-1 between two nodes with types\ncyypher.listRelationship({ __typename: 'Person', _id: '123' }, 'FRIEND', {\n  __typename: 'Person',\n  _id: '456',\n})\n\n// List 1-1 between two nodes with relation params\ncyypher.listRelationship(\n  { _id: '123' },\n  { __typename: 'FRIEND', relation: 'close', metAt: new Date() },\n  { _id: '456' }\n)\n\n// List directed relationship (IN, OUT, NONE)\ncyypher.listRelationship(\n  { _id: '123' },\n  { __typename: 'FRIEND', __direction: 'OUT' },\n  { _id: '456' }\n)\n```\n\n### `createRelationship(from, rel, to, opts)`\n\nCreate relationship(s) between two or more nodes.\n\n| Param      | Type                           | Required | Description            | Default |\n| :--------- | :----------------------------- | -------- | ---------------------- | ------- |\n| `from`     | `string` \\| `object` \\| `Node` | yes      | From node              |\n| `rel`      | `string` \\| `object` \\| `Node` | yes      | Relationship           |\n| `to`       | `string` \\| `object` \\| `Node` | yes      | To node                |\n| Options    |                                |          |                        |         |\n| `singular` | `boolean`                      |          | Singular relationship? | false   |\n\n```ts\n// Using params\ncyypher.createRelationship({ _id: '123' }, 'FRIEND', { _id: '456' })\n\n// Using node references\nimport { ref } from 'cyypher'\nconst fromNode = await cyypher.find('Person', 'ID')\nconst toNode = await cyypher.find('Person', 'ID2')\ncyypher.createRelationship(ref(fromNode), 'FRIEND', ref(toNode))\n\n// Singular\ncyypher.createRelationship(\n  { _id: '123' },\n  'FRIEND',\n  { _id: '456' },\n  { singular: true }\n)\n```\n\n### `clearRelationship()`\n\nClear all relationships between two or more nodes.\n\n| Param  | Type                           | Required | Description  | Default |\n| :----- | :----------------------------- | -------- | ------------ | ------- |\n| `from` | `string` \\| `object` \\| `Node` | yes      | From node    |\n| `rel`  | `string` \\| `object` \\| `Node` | yes      | Relationship |\n\n```ts\n// Using params\ncyypher.clearRelationship({ _id: '123' }, 'FRIEND')\n```\n\n### `deleteRelationship()`\n\nDelete relationship(s) between two or more nodes.\n\n| Param  | Type                           | Required | Description  | Default |\n| :----- | :----------------------------- | -------- | ------------ | ------- |\n| `from` | `string` \\| `object` \\| `Node` | yes      | From node    |\n| `rel`  | `string` \\| `object` \\| `Node` | yes      | Relationship |\n| `to`   | `string` \\| `object` \\| `Node` | yes      | To node      |\n\n```ts\n// Using params\ncyypher.deleteRelationship({ _id: '123' }, 'FRIEND', { _id: '456' })\n\n// Using node references\nimport { ref } from 'cyypher'\nconst fromNode = await cyypher.find('Person', 'ID')\nconst toNode = await cyypher.find('Person', 'ID2')\ncyypher.deleteRelationship(ref(fromNode), 'FRIEND', ref(toNode))\n```\n"
}