diff --git a/SECURITY.md b/SECURITY.md index 1e37aa0..38590c3 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -6,7 +6,7 @@ The following versions are currently supported: | Version | Supported | | ------- | ------------------ | -| 0.1.1 | :white_check_mark: | +| 0.1.2 | :white_check_mark: | ## Reporting a Vulnerability diff --git a/package.json b/package.json index 0fe04e9..7aebb0e 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { "name": "@tragedy-labs/sprite", - "version": "0.1.1", + "version": "0.1.2", "description": "A TypeScript driver for ArcadeDB", - "main": "./dist/index.js", - "module": "./dist/index.js", - "type": "module", "homepage": "https://sprite.tragedy.dev", "repository": { "type": "git", "url": "https://github.com/tragedy-labs/sprite.git" }, + "main": "./dist/index.js", + "module": "./dist/index.js", + "type": "module", "scripts": { "dev": "nodemon --watch ./ --ext ts --exec 'rimraf ./dist && tsc && node ./dist/index.js'", "build": "rimraf ./dist && tsc -p ./tsconfig.build.json", diff --git a/src/index.ts b/src/index.ts index 4e25f7f..9b58134 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,4 @@ -import { CreateDocumentType, SpriteDatabase } from './api.js'; - export { SpriteServer } from './server/SpriteServer.js'; export { SpriteDatabase } from './database/SpriteDatabase.js'; export * from './types/index.js'; - -const db = new SpriteDatabase({ - address: 'localhost', - username: '', - password: '', - databaseName: 'test' -}); diff --git a/src/types/database.ts b/src/types/database.ts index 3fd4d6f..8235e7a 100644 --- a/src/types/database.ts +++ b/src/types/database.ts @@ -1,5 +1,3 @@ -import { ValidSuperTypeKey } from './type.js'; - export type ArcadeSelectTimeoutStrategy = 'EXCEPTION' | 'RETURN'; /** @@ -8,189 +6,6 @@ export type ArcadeSelectTimeoutStrategy = 'EXCEPTION' | 'RETURN'; */ export type ArcadeRecordType = 'document' | 'edge' | 'vertex'; -/** - * Options to create a new type with. - */ -export interface ISpriteCreateTypeOptions> { - /** - * When set to true, the type creation will be ignored if the - * type already exists (instead of failing with an error). - * @default false - */ - ifNotExists?: boolean; - /** - * Defines a super-type you want to extend with this type. - */ - extends?: ValidSuperTypeKey; - /** - * A bucket-name, or an array of bucket-names you want this type to use. - */ - buckets?: string | Array; - /** - * Defines the total number of buckets you want to create for this type. The - * @default 1 - */ - totalBuckets?: number; -} - -/** - * Options for a `deleteFrom` operation as executed - * via a `SpriteDatabase` repository. - */ -export interface ISpriteDeleteFromOptions< - S, - N extends TypeNames, - P extends keyof WithRid -> { - /** - * Designates conditions to filter the result-set. - */ - where: SpriteWhereClause; - /** - * The duration of the timeout in milliseconds. - */ - timeout?: number; - /** - * Defines the maximum number of records in the result-set. - * @default undefined - */ - limit?: number; - /** - * Defines what is returned following the command: the count of the records before (`BEFORE`) or following deletion (`COUNT`). - * @default 'COUNT' - */ - return?: 'COUNT' | 'BEFORE'; -} - -/** - * Options for a database.dropType() command - */ -export interface ISpriteDropTypeOptions { - /** - * Prevent errors if the type does not exits when attempting to drop it. - * @default false; - */ - ifExists?: boolean; - /** - * Defines whether the command drops non-empty edge and vertex types. Note, this can - * disrupt data consistency. Be sure to create a backup before running it. - * @default: false - */ - unsafe?: boolean; -} - -/** Options to insert a new record with */ -export interface ISpriteInsertRecordOptions { - /** The data to populate the newly created reacord with */ - data?: OmitMeta | OmitMeta[]; - /** The bucket to store the record in */ - bucket?: string; -} - -// TODO: have not checked these for compatibility with ArcadeDB -export declare const COMPARISON_OPERATORS: readonly [ - '=', - '==', - '!=', - '<>', - '>', - '>=', - '<', - '<=', - 'in', - 'not in', - 'is', - 'is not', - 'like', - 'not like', - 'match', - 'ilike', - 'not ilike', - '@>', - '<@', - '&&', - '?', - '?&', - '!<', - '!>', - '<=>', - '!~', - '~', - '~*', - '!~*', - '@@', - '@@@', - '!!', - '<->', - 'regexp', - 'is distinct from', - 'is not distinct from' -]; - -/** Operators for a `WHERE` sql statement */ -export type SpriteOperators = (typeof COMPARISON_OPERATORS)[number]; - -/** - * An array with three items used to describe a `where` statement. - * @example ['@rid', '==', '#0:0'] - */ -export type SpriteWhereClause< - S, - N extends TypeNames, - P extends keyof WithRid -> = [P, SpriteOperators, WithRid[P]]; - -/** Options for a `selectFrom` operation, as executed via a `SpriteDatabase` repository. */ -export interface ISpriteSelectFromOptions< - S, - N extends keyof S, - P extends keyof WithRid -> { - /** - * Designates conditions to filter the result-set. - */ - where?: SpriteWhereClause; - /** - * Designates the field with which to order the result-set. - * Use the optional 'ASC' and 'DESC' operators to define the direction of the order. - */ - orderBy?: { - field: keyof S[N]; - /** - * Defines the direction to sort the result (ASCending or DESCending). - * @default 'ASC'. - */ - direction?: 'ASC' | 'DESC'; - }; - /** - * Defines the number of records you want to skip from the start of the result-set. - * You mayfind this useful in Pagination, when using it in conjunction with the - * limit `option`. - */ - skip?: number; - /** - * Defines the maximum number of records in the result-set. You may find this useful in - * Pagination, when using it in conjunction with the `skip` option. - */ - limit?: number; - /** - * Defines the maximum time in milliseconds for the query, and optionally the - * exception strategy to use. - */ - timeout?: { - /** - * The duration of the timeout in milliseconds. - */ - duration: number; - /** - * The timeout strategy to use.\ - * `RETURN` Truncates the result-set, returning the data collected up to the timeout.\ - * `EXCEPTION` Raises an exception. - */ - strategy?: ArcadeSelectTimeoutStrategy; - }; -} - /** * The possible categories of a record in ArcadeDB, * as they appear in the record's `@cat` property. @@ -226,14 +41,6 @@ export type RecordMeta = export type OmitMeta = Omit; -/** Options to insert a new record with */ -export interface ISpriteInsertRecordOptions { - /** The data to populate the newly created reacord with */ - data?: OmitMeta | OmitMeta[]; - /** The bucket to store the record in */ - bucket?: string; -} - /** * The TypeNames in a supplied schema. */ diff --git a/src/types/edge.ts b/src/types/edge.ts deleted file mode 100644 index 8d8f6d7..0000000 --- a/src/types/edge.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { OmitMeta, TypeNames } from './database.js'; - -export interface ISpriteIndexdescriptor> { - /** - * The type of the record to select an index for. - */ - type: N; - /** - * The key of the property to select an index for. - */ - key: keyof S[N]; - /** - * The value of the property key to select an index for. - */ - value: S[N][keyof S[N]]; -} - -/** - * Describes a `to` or `from` point of an edge, either as a string (the record's `@rid`), - * or, by providing an object which describes an index of a vertex to use a - * `to`/`from` point (i.e. `{type: 'user', key: 'name', value: 'Jeremiah'}`) - */ -export type SpriteEdgeVertexDescriptor = - | ISpriteIndexdescriptor - | string; - -/** - * Options associated with creating a new edge. - */ -export interface ISpriteEdgeOptions { - /** - * Data to populate the edge with. - */ - data?: OmitMeta; - /** - * The bucket to store the edge in. - * @default undefined - */ - bucket?: string; - /** - * Skip creation if the edge already exists between two vertices (i.e. the edge - * must be unique between the vertices). This works only if the edge type has a - * `UNIQUE` index on `from`/`to` fields, otherwise the creation fails. - * @default false - */ - upsert?: boolean; - /** - * Creates a unidirectional edge; by default edges are bidirectional - * @default false - */ - unidirectional?: boolean; - /** - * When set to `true`, skips the creation of the edge in another edge already exists with the same - * direction (same from/to) and same edge type, instead of throwing an error. - * @default false - */ - ifNotExists?: boolean; - retry?: { - /** - * The number of retries to attempt in the event of conflict, (optimistic approach). - */ - attempts?: number; - /** - * The wait time (in ms), between retries. - */ - wait?: number; - }; - /** - * Defines whether it breaks the command down into smaller blocks and the size of - * the batches. This helps to avoid memory issues when the number of vertices is - * too high. - * @default 100 - */ - batchSize?: number; -} diff --git a/src/types/index.ts b/src/types/index.ts index 0b4f175..90c708b 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,6 +1,5 @@ export * from './commands.js'; export * from './database.js'; -export * from './edge.js'; export * from './operators.js'; export * from './queries.js'; export * from './type.js'; diff --git a/test/unit/transaction/instance/crud.test.ts b/test/unit/transaction/instance/crud.test.ts index df194d0..de5fc9b 100644 --- a/test/unit/transaction/instance/crud.test.ts +++ b/test/unit/transaction/instance/crud.test.ts @@ -1,18 +1,11 @@ // Lib import { Dialect } from '@/database/Database.js'; -import { Routes } from '@/database/routes.js'; import { Rest } from '@/rest/Rest.js'; import { SpriteTransaction } from '@/transaction/SpriteTransaction.js'; import { Transaction } from '@/transaction/Transaction.js'; // Testing -import { - TestDatabaseSession as SESSION, - headersWithTransaction as headers, - variables -} from '@test/variables.js'; - -const ENDPOINT = `${variables.address}${variables.apiRoute}${Routes.COMMAND}/${variables.databaseName}`; +import { TestDatabaseSession as SESSION, variables } from '@test/variables.js'; describe('SpriteTransaction.crud()', () => { it(`should call Transaction.crud with session, transaction, language, command, and parameters`, async () => {