@rushdb/javascript-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +21 -0
  3. package/README.md +119 -0
  4. package/cjs/api/api.js +328 -0
  5. package/cjs/api/constants.js +7 -0
  6. package/cjs/api/create-api.js +258 -0
  7. package/cjs/api/index.js +8 -0
  8. package/cjs/api/rest-api-proxy.js +22 -0
  9. package/cjs/api/types.js +2 -0
  10. package/cjs/api/utils.js +154 -0
  11. package/cjs/common/constants.js +10 -0
  12. package/cjs/common/utils.js +46 -0
  13. package/cjs/index.cjs.node.js +24 -0
  14. package/cjs/index.cjs.worker.js +24 -0
  15. package/cjs/network/FetchHttpClient.js +138 -0
  16. package/cjs/network/HttpClient.js +59 -0
  17. package/cjs/network/NodeHttpClient.js +103 -0
  18. package/cjs/network/index.js +28 -0
  19. package/cjs/network/types.js +2 -0
  20. package/cjs/package.json +4 -0
  21. package/cjs/sdk/constants.js +12 -0
  22. package/cjs/sdk/errors.js +27 -0
  23. package/cjs/sdk/index.js +23 -0
  24. package/cjs/sdk/model.js +147 -0
  25. package/cjs/sdk/record.js +77 -0
  26. package/cjs/sdk/sdk.js +46 -0
  27. package/cjs/sdk/transaction.js +17 -0
  28. package/cjs/sdk/types.js +2 -0
  29. package/cjs/sdk/utils.js +103 -0
  30. package/cjs/types/expressions.js +2 -0
  31. package/cjs/types/index.js +21 -0
  32. package/cjs/types/query.js +2 -0
  33. package/cjs/types/schema.js +2 -0
  34. package/cjs/types/utils.js +2 -0
  35. package/cjs/types/value.js +2 -0
  36. package/esm/api/api.js +324 -0
  37. package/esm/api/constants.js +4 -0
  38. package/esm/api/create-api.js +254 -0
  39. package/esm/api/index.js +2 -0
  40. package/esm/api/rest-api-proxy.js +18 -0
  41. package/esm/api/types.js +1 -0
  42. package/esm/api/utils.js +138 -0
  43. package/esm/common/constants.js +7 -0
  44. package/esm/common/utils.js +37 -0
  45. package/esm/index.esm.node.js +6 -0
  46. package/esm/index.esm.worker.js +6 -0
  47. package/esm/network/FetchHttpClient.js +133 -0
  48. package/esm/network/HttpClient.js +53 -0
  49. package/esm/network/NodeHttpClient.js +98 -0
  50. package/esm/network/index.js +24 -0
  51. package/esm/network/types.js +1 -0
  52. package/esm/package.json +4 -0
  53. package/esm/sdk/constants.js +9 -0
  54. package/esm/sdk/errors.js +21 -0
  55. package/esm/sdk/index.js +7 -0
  56. package/esm/sdk/model.js +143 -0
  57. package/esm/sdk/record.js +70 -0
  58. package/esm/sdk/sdk.js +42 -0
  59. package/esm/sdk/transaction.js +13 -0
  60. package/esm/sdk/types.js +1 -0
  61. package/esm/sdk/utils.js +93 -0
  62. package/esm/types/expressions.js +1 -0
  63. package/esm/types/index.js +5 -0
  64. package/esm/types/query.js +1 -0
  65. package/esm/types/schema.js +1 -0
  66. package/esm/types/utils.js +1 -0
  67. package/esm/types/value.js +1 -0
  68. package/package.json +59 -0
  69. package/types/api/api.d.ts +43 -0
  70. package/types/api/constants.d.ts +4 -0
  71. package/types/api/create-api.d.ts +67 -0
  72. package/types/api/index.d.ts +3 -0
  73. package/types/api/rest-api-proxy.d.ts +6 -0
  74. package/types/api/types.d.ts +65 -0
  75. package/types/api/utils.d.ts +43 -0
  76. package/types/common/constants.d.ts +7 -0
  77. package/types/common/utils.d.ts +7 -0
  78. package/types/index.d.ts +72 -0
  79. package/types/network/FetchHttpClient.d.ts +26 -0
  80. package/types/network/HttpClient.d.ts +48 -0
  81. package/types/network/NodeHttpClient.d.ts +16 -0
  82. package/types/network/index.d.ts +6 -0
  83. package/types/network/types.d.ts +4 -0
  84. package/types/sdk/constants.d.ts +1 -0
  85. package/types/sdk/errors.d.ts +9 -0
  86. package/types/sdk/index.d.ts +7 -0
  87. package/types/sdk/model.d.ts +72 -0
  88. package/types/sdk/record.d.ts +109 -0
  89. package/types/sdk/sdk.d.ts +136 -0
  90. package/types/sdk/transaction.d.ts +11 -0
  91. package/types/sdk/types.d.ts +19 -0
  92. package/types/sdk/utils.d.ts +9 -0
  93. package/types/types/expressions.d.ts +23 -0
  94. package/types/types/index.d.ts +5 -0
  95. package/types/types/query.d.ts +102 -0
  96. package/types/types/schema.d.ts +48 -0
  97. package/types/types/utils.d.ts +9 -0
  98. package/types/types/value.d.ts +35 -0
@@ -0,0 +1,67 @@
1
+ import type { createFetcher } from '../network/index.js';
2
+ import type { DBRecord, DBRecordTarget, Relation, RelationDetachOptions, RelationOptions } from '../sdk/record.js';
3
+ import type { Transaction } from '../sdk/transaction.js';
4
+ import type { Property, PropertyValuesData, SearchQuery, Schema, MaybeArray } from '../types/index.js';
5
+ import type { ApiResponse } from './types.js';
6
+ import { DBRecordsBatchDraft, DBRecordDraft } from '../sdk/record.js';
7
+ export declare const createApi: (fetcher: ReturnType<typeof createFetcher>) => {
8
+ labels: {
9
+ find<S extends Schema = any>(searchParams: SearchQuery<S>, transaction?: Transaction | string): Promise<ApiResponse<Record<string, number>>>;
10
+ };
11
+ properties: {
12
+ delete: (id: string, transaction?: Transaction | string) => Promise<ApiResponse<Property>>;
13
+ find: <S extends Schema = any>(searchParams: SearchQuery<S>, transaction?: Transaction | string) => Promise<ApiResponse<Property[]>>;
14
+ findById: (id: string, transaction?: Transaction | string) => Promise<ApiResponse<Property>>;
15
+ values: (id: string, transaction?: Transaction | string) => Promise<ApiResponse<Property & PropertyValuesData>>;
16
+ };
17
+ records: {
18
+ attach: (source: DBRecordTarget, idOrIds: MaybeArray<string>, options?: RelationOptions, transaction?: Transaction | string) => Promise<ApiResponse<{
19
+ message: string;
20
+ }>>;
21
+ create<S extends Schema = any>(data: DBRecordDraft | S, transaction?: Transaction | string): Promise<ApiResponse<DBRecord<S> | undefined>>;
22
+ createMany<S extends Schema = any>(data: DBRecordsBatchDraft | S[], transaction?: Transaction | string): Promise<ApiResponse<DBRecord<S>[]>>;
23
+ delete<S extends Schema = any>(searchParams: SearchQuery<S>, transaction?: Transaction | string): Promise<ApiResponse<{
24
+ message: string;
25
+ }>>;
26
+ deleteById(idOrIds: MaybeArray<string>, transaction?: Transaction | string): Promise<ApiResponse<{
27
+ message: string;
28
+ }>>;
29
+ detach: (source: DBRecordTarget, idOrIds: MaybeArray<string>, options?: RelationDetachOptions, transaction?: Transaction | string) => Promise<ApiResponse<{
30
+ message: string;
31
+ }>>;
32
+ export<S extends Schema = any>(searchParams: SearchQuery<S>, transaction?: Transaction | string): Promise<ApiResponse<{
33
+ dateTime: string;
34
+ fileContent: string;
35
+ }>>;
36
+ find<S extends Schema = any>(params?: {
37
+ id?: string;
38
+ searchParams: SearchQuery<S>;
39
+ }, transaction?: Transaction | string): Promise<ApiResponse<DBRecord<S>[]>>;
40
+ findById<S extends Schema = any>(idOrIds: MaybeArray<string>, transaction?: Transaction | string): Promise<ApiResponse<DBRecord<S>[]>> | Promise<ApiResponse<DBRecord<S>>>;
41
+ findOne<S extends Schema = any>(searchParams: SearchQuery<S>, transaction?: Transaction | string): Promise<ApiResponse<DBRecord<S>>>;
42
+ findUniq<S extends Schema = any>(searchParams: SearchQuery<S>, transaction?: Transaction | string): Promise<ApiResponse<DBRecord<S>>>;
43
+ properties(target: string, transaction?: Transaction | string): Promise<ApiResponse<Property[]>>;
44
+ relations: (target: DBRecordTarget, transaction?: Transaction | string) => Promise<ApiResponse<Relation[]>>;
45
+ set<S extends Schema = any>(target: DBRecordTarget, data: DBRecordDraft | S, transaction?: Transaction | string): Promise<ApiResponse<DBRecord<S>>>;
46
+ update<S extends Schema = any>(target: DBRecordTarget, data: DBRecordDraft | S, transaction?: Transaction | string): Promise<ApiResponse<DBRecord<S>>>;
47
+ };
48
+ relations: {
49
+ find: <S extends Schema = any>(searchParams: SearchQuery<S>, pagination?: Pick<SearchQuery, "limit" | "skip">, transaction?: Transaction | string) => Promise<ApiResponse<Relation[]>>;
50
+ };
51
+ tx: {
52
+ begin(config?: Partial<{
53
+ ttl: number;
54
+ }>): Promise<ApiResponse<{
55
+ id: string;
56
+ }>>;
57
+ commit(id: string): Promise<ApiResponse<{
58
+ message: string;
59
+ }>>;
60
+ get(id: string): Promise<ApiResponse<{
61
+ id: string;
62
+ }>>;
63
+ rollback(id: string): Promise<ApiResponse<{
64
+ message: string;
65
+ }>>;
66
+ };
67
+ };
@@ -0,0 +1,3 @@
1
+ export { DBRecordsBatchDraft, DBRecordDraft } from '../sdk/record.js';
2
+ export { RestAPI } from './api.js';
3
+ export { ApiResponse } from './types.js';
@@ -0,0 +1,6 @@
1
+ import type { RestAPI } from './api.js';
2
+ export declare class RestApiProxy {
3
+ protected apiProxy: RestAPI;
4
+ constructor();
5
+ init(api: RestAPI, methodsWhiteList?: []): void;
6
+ }
@@ -0,0 +1,65 @@
1
+ import type { DBRecordsBatchDraft, DBRecordDraft, DBRecordInstance, DBRecordTarget, DBRecordsArrayInstance, Relation, RelationDetachOptions, RelationOptions, RelationTarget } from '../sdk/record.js';
2
+ import type { Transaction } from '../sdk/transaction.js';
3
+ import type { Property, SearchQuery, Schema, InferSchemaTypesWrite, MaybeArray } from '../types/index.js';
4
+ export type ApiResponse<T, E = Record<string, any>> = {
5
+ data: T;
6
+ success: boolean;
7
+ total?: number;
8
+ } & E;
9
+ export type RecordsApi = {
10
+ attach(source: DBRecordTarget, target: RelationTarget, options?: RelationOptions, transaction?: Transaction | string): Promise<ApiResponse<{
11
+ message: string;
12
+ }>>;
13
+ create<S extends Schema = any>(label: string, data: InferSchemaTypesWrite<S>, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
14
+ create<S extends Schema = any>(labelOrData: DBRecordDraft | string, maybeDataOrTransaction?: Transaction | InferSchemaTypesWrite<S> | string, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
15
+ createMany<S extends Schema = any>(label: string, data: InferSchemaTypesWrite<S>[], transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S>>;
16
+ createMany<S extends Schema = any>(labelOrData: DBRecordsBatchDraft | string, maybeDataOrTransaction?: Transaction | MaybeArray<InferSchemaTypesWrite<S>> | string, transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S>>;
17
+ delete<S extends Schema = any>(searchParams: SearchQuery<S>, transaction?: Transaction | string): Promise<ApiResponse<{
18
+ message: string;
19
+ }>>;
20
+ deleteById(idOrIds: MaybeArray<string>, transaction?: Transaction | string): Promise<ApiResponse<{
21
+ message: string;
22
+ }>>;
23
+ detach(source: DBRecordTarget, target: RelationTarget, options?: RelationDetachOptions, transaction?: Transaction | string): Promise<ApiResponse<{
24
+ message: string;
25
+ }>>;
26
+ export<S extends Schema = any>(searchParams?: SearchQuery<S>, transaction?: Transaction | string): Promise<ApiResponse<{
27
+ dateTime: string;
28
+ fileContent: string;
29
+ }>>;
30
+ find<S extends Schema = any>(label: string, searchParams?: SearchQuery<S>, transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S>>;
31
+ find<S extends Schema = any>(labelOrSearchParams: SearchQuery<S> | string, transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S>>;
32
+ find<S extends Schema = any>(searchParams: SearchQuery<S>, transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S>>;
33
+ findById<S extends Schema = any>(id: string, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
34
+ findById<S extends Schema = any>(ids: string[], transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S>>;
35
+ findOne<S extends Schema = any>(label: string, searchParams: SearchQuery<S> & {
36
+ labels?: never;
37
+ limit?: never;
38
+ skip?: never;
39
+ }, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
40
+ findOne<S extends Schema = any>(labelOrSearchParams: (SearchQuery<S> & {
41
+ limit?: never;
42
+ skip?: never;
43
+ }) | string, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
44
+ findOne<S extends Schema = any>(searchParams: SearchQuery<S> & {
45
+ limit?: never;
46
+ skip?: never;
47
+ }, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
48
+ findUniq<S extends Schema = any>(label: string, searchParams: SearchQuery<S> & {
49
+ labels?: never;
50
+ limit?: never;
51
+ skip?: never;
52
+ }, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
53
+ findUniq<S extends Schema = any>(labelOrSearchParams: (SearchQuery<S> & {
54
+ limit?: never;
55
+ skip?: never;
56
+ }) | string, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
57
+ findUniq<S extends Schema = any>(searchParams: SearchQuery<S> & {
58
+ limit?: never;
59
+ skip?: never;
60
+ }, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
61
+ properties(target: DBRecordTarget, transaction?: Transaction | string): Promise<ApiResponse<Property[]>>;
62
+ relations(target: DBRecordTarget, transaction?: Transaction | string): Promise<ApiResponse<Array<Relation>>>;
63
+ set<S extends Schema = any>(target: DBRecordTarget, data: DBRecordDraft | InferSchemaTypesWrite<S>, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
64
+ update<S extends Schema = any>(target: DBRecordTarget, data: DBRecordDraft | Partial<InferSchemaTypesWrite<S>>, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
65
+ };
@@ -0,0 +1,43 @@
1
+ import type { DBRecordTarget } from '../sdk';
2
+ import type { UserProvidedConfig } from '../sdk/types.js';
3
+ import type { PropertyType, PropertyValue, PropertyWithValue, SearchQuery, Schema } from '../types/index.js';
4
+ import { Transaction } from '../sdk/transaction.js';
5
+ export declare const buildTransactionHeader: (txId?: string) => {
6
+ "x-transaction-id": string;
7
+ } | undefined;
8
+ export declare const isTransaction: (input: any) => input is Transaction | string;
9
+ export declare const pickTransaction: (input: any) => string | Transaction | undefined;
10
+ export declare const pickTransactionId: (input: any) => string | undefined;
11
+ export declare const pickRecordId: (input: DBRecordTarget) => string | undefined;
12
+ export declare const createSearchParams: <S extends Schema = Schema>(labelOrSearchParams?: SearchQuery<S> | string, searchParamsOrTransaction?: SearchQuery<S> | Transaction | string) => {
13
+ id?: string;
14
+ searchParams: SearchQuery<S>;
15
+ };
16
+ export declare const isUUID: (value: any) => boolean;
17
+ export declare const arrayIsConsistent: (arr: Array<unknown>) => boolean;
18
+ export declare const getValueParameters: (value: PropertyValue) => {
19
+ isEmptyArray: boolean;
20
+ isEmptyStringsArray: boolean;
21
+ isInconsistentArray: boolean;
22
+ isEmptyString?: undefined;
23
+ } | {
24
+ isEmptyString: boolean;
25
+ isEmptyArray?: undefined;
26
+ isEmptyStringsArray?: undefined;
27
+ isInconsistentArray?: undefined;
28
+ };
29
+ export declare const suggestPropertyType: (value: PropertyValue) => PropertyType;
30
+ export declare const prepareProperties: (data: Record<string, PropertyValue>, options?: {
31
+ suggestTypes: boolean;
32
+ }) => PropertyWithValue[];
33
+ export declare const normalizeRecord: ({ label, options, payload }: {
34
+ label: string;
35
+ options?: {
36
+ suggestTypes: boolean;
37
+ };
38
+ payload: Record<string, PropertyValue>;
39
+ }) => {
40
+ label: string;
41
+ properties: PropertyWithValue[];
42
+ };
43
+ export declare const buildUrl: (props: UserProvidedConfig) => string;
@@ -0,0 +1,7 @@
1
+ export declare const ISO_8601_FULL: RegExp;
2
+ export declare const DEFAULT_TIMEOUT = 80000;
3
+ export declare const PROPERTY_TYPE_STRING: "string";
4
+ export declare const PROPERTY_TYPE_DATETIME: "datetime";
5
+ export declare const PROPERTY_TYPE_BOOLEAN: "boolean";
6
+ export declare const PROPERTY_TYPE_NUMBER: "number";
7
+ export declare const PROPERTY_TYPE_NULL: "null";
@@ -0,0 +1,7 @@
1
+ import type { PropertyValue } from '../types/index.js';
2
+ export declare const isArray: (item: any) => item is any[];
3
+ export declare const isObject: (input: unknown) => input is object;
4
+ export declare const isEmptyObject: (input: unknown) => boolean;
5
+ export declare const isObjectFlat: (input: any) => input is Record<string, PropertyValue>;
6
+ export declare const isString: (input: any) => input is string;
7
+ export declare const toBoolean: (value: any) => boolean;
@@ -0,0 +1,72 @@
1
+ import type {
2
+ InferType,
3
+ DBRecord,
4
+ UserProvidedConfig,
5
+ Relation
6
+ } from './sdk'
7
+
8
+ import {
9
+ DBRecordsBatchDraft,
10
+ DBRecordDraft,
11
+ RestAPI,
12
+ ApiResponse
13
+ } from './api'
14
+ import { HttpClient, HttpClientResponse } from './network/HttpClient'
15
+ import {
16
+ Model,
17
+ DBRecordInstance,
18
+ DBRecordsArrayInstance,
19
+ Transaction,
20
+ idToDate,
21
+ idToTimestamp,
22
+ EmptyTargetError,
23
+ UniquenessError,
24
+ NonUniqueResultError
25
+ } from './sdk'
26
+ import { Models, Schema } from './types'
27
+
28
+ declare module '@rushdb/javascript-sdk' {
29
+ export namespace RushDB {}
30
+
31
+ export class RushDB extends RestAPI {
32
+ static RushDB: typeof RushDB
33
+
34
+ constructor(token?: string, config?: UserProvidedConfig)
35
+ public api: RestAPI
36
+
37
+ public registerModel<Model extends Model = Model>(model: Model): Model //Model<T['schema']>
38
+ public getModel(label: string): Model
39
+ public getModels(): Map<string, Model>
40
+ public getInstance(token: string, config?: UserProvidedConfig): RushDB
41
+ public toInstance<Schema extends Schema = Schema>(
42
+ record: DBRecord<Schema>
43
+ ): DBRecordInstance
44
+ }
45
+
46
+ export {
47
+ DBRecordsBatchDraft,
48
+ Relation,
49
+ ApiResponse,
50
+ InferType,
51
+ Model,
52
+ Models,
53
+ DBRecord,
54
+ DBRecordDraft,
55
+ DBRecordInstance,
56
+ DBRecordsArrayInstance,
57
+ RestAPI,
58
+ Schema,
59
+ Transaction,
60
+ HttpClient,
61
+ HttpClientResponse,
62
+ EmptyTargetError,
63
+ NonUniqueResultError,
64
+ UniquenessError,
65
+ idToDate,
66
+ idToTimestamp
67
+ }
68
+
69
+ export * from './types'
70
+
71
+ export default RushDB
72
+ }
@@ -0,0 +1,26 @@
1
+ import type { HttpClientInterface, HttpClientResponseInterface, MakeRequestConfig } from './HttpClient.js';
2
+ import type { ResponseHeaders } from './types.js';
3
+ import { HttpClient, HttpClientGenericResponse } from './HttpClient.js';
4
+ /**
5
+ * HTTP client which uses a `fetch` function to issue requests.
6
+ *
7
+ * By default, relies on the global `fetch` function, but an optional function
8
+ * can be passed in. If passing in a function, it is expected to match the Web
9
+ * Fetch API. As an example, this could be the function provided by the
10
+ * node-fetch package (https://github.com/node-fetch/node-fetch).
11
+ */
12
+ export declare class FetchHttpClient extends HttpClient implements HttpClientInterface {
13
+ private readonly _fetchFn;
14
+ constructor(fetchFn?: typeof fetch);
15
+ private static makeFetchWithRaceTimeout;
16
+ private static makeFetchWithAbortTimeout;
17
+ makeRequest(url: string, { headers, method, protocol, requestData, timeout }: MakeRequestConfig): Promise<HttpClientResponseInterface>;
18
+ }
19
+ export declare class FetchHttpClientResponse extends HttpClientGenericResponse implements HttpClientResponseInterface {
20
+ _res: Response;
21
+ constructor(res: Response);
22
+ getRawResponse(): Response;
23
+ toStream(streamCompleteCallback: () => void): ReadableStream<Uint8Array> | null;
24
+ toJSON(): Promise<any>;
25
+ static _transformHeadersToObject(headers: Headers): ResponseHeaders;
26
+ }
@@ -0,0 +1,48 @@
1
+ import type { RequestData, RequestHeaders, ResponseHeaders } from './types.js';
2
+ type TimeoutError = TypeError & {
3
+ code?: string;
4
+ };
5
+ export interface HttpClientInterface {
6
+ makeRequest: (url: string, config: MakeRequestConfig) => Promise<HttpClientResponseInterface>;
7
+ }
8
+ export interface MakeRequestConfig<T extends Record<string, any> = Record<string, any>> {
9
+ credentials?: RequestCredentials;
10
+ headers?: RequestHeaders;
11
+ method: string;
12
+ protocol?: string;
13
+ requestData?: RequestData;
14
+ timeout?: number;
15
+ }
16
+ export interface HttpClientResponseInterface {
17
+ getHeaders: () => ResponseHeaders;
18
+ getRawResponse: () => unknown;
19
+ getStatusCode: () => number;
20
+ toJSON: () => Promise<any>;
21
+ toStream: (streamCompleteCallback: () => void) => unknown;
22
+ }
23
+ export declare class HttpClient implements HttpClientInterface {
24
+ static CONNECTION_CLOSED_ERROR_CODES: string[];
25
+ static TIMEOUT_ERROR_CODE: string;
26
+ makeRequest(url: string, { headers, method, protocol, requestData, timeout }: MakeRequestConfig): Promise<HttpClientResponseInterface>;
27
+ static makeTimeoutError(): TimeoutError;
28
+ }
29
+ export declare class HttpClientGenericResponse implements HttpClientResponseInterface {
30
+ _statusCode: number;
31
+ _headers: ResponseHeaders;
32
+ constructor(statusCode: number, headers: ResponseHeaders);
33
+ getStatusCode(): number;
34
+ getHeaders(): ResponseHeaders;
35
+ getRawResponse(): unknown;
36
+ toStream(streamCompleteCallback: () => void): unknown;
37
+ toJSON(): any;
38
+ }
39
+ export declare class HttpClientResponse<T = unknown> implements HttpClientResponseInterface {
40
+ _res: T;
41
+ constructor(response: T);
42
+ getStatusCode(): number;
43
+ getHeaders(): ResponseHeaders;
44
+ getRawResponse(): unknown;
45
+ toStream(streamCompleteCallback: () => void): unknown;
46
+ toJSON(): any;
47
+ }
48
+ export {};
@@ -0,0 +1,16 @@
1
+ import * as http_ from 'http';
2
+ import * as https_ from 'https';
3
+ import type { HttpClientResponseInterface, MakeRequestConfig } from './HttpClient.js';
4
+ import { HttpClient, HttpClientGenericResponse } from './HttpClient.js';
5
+ export declare class NodeHttpClient extends HttpClient {
6
+ _agent?: http_.Agent | https_.Agent | undefined;
7
+ constructor(agent?: http_.Agent | https_.Agent);
8
+ makeRequest(urlString: string, { headers, method, protocol, requestData, timeout }: MakeRequestConfig): Promise<HttpClientResponseInterface>;
9
+ }
10
+ export declare class NodeHttpClientResponse extends HttpClientGenericResponse implements HttpClientResponseInterface {
11
+ _res: http_.IncomingMessage;
12
+ constructor(res: http_.IncomingMessage);
13
+ getRawResponse(): http_.IncomingMessage;
14
+ toStream(streamCompleteCallback: () => void): http_.IncomingMessage;
15
+ toJSON(): any;
16
+ }
@@ -0,0 +1,6 @@
1
+ import type { HttpClient, MakeRequestConfig } from './HttpClient.js';
2
+ export declare const createFetcher: ({ httpClient, token, url }: {
3
+ httpClient: HttpClient;
4
+ token?: string;
5
+ url: string;
6
+ }) => <Data extends Record<string, any> = Record<string, any>>(input: URL | string, { headers: initHeaders, ...init }: MakeRequestConfig<Data>) => Promise<Data>;
@@ -0,0 +1,4 @@
1
+ export type RequestData<T extends Record<string, any> = Record<string, any>> = T;
2
+ export type RequestHeaders = Record<string, number | string | string[]>;
3
+ export type ResponseHeaderValue = string | string[];
4
+ export type ResponseHeaders = Record<string, ResponseHeaderValue>;
@@ -0,0 +1 @@
1
+ export declare const ALLOWED_CONFIG_PROPERTIES: string[];
@@ -0,0 +1,9 @@
1
+ export declare class UniquenessError extends Error {
2
+ constructor(label: string, properties: any);
3
+ }
4
+ export declare class EmptyTargetError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ export declare class NonUniqueResultError extends Error {
8
+ constructor(duplicateCount: number, searchParams: Record<string, any>);
9
+ }
@@ -0,0 +1,7 @@
1
+ export * from './sdk.js';
2
+ export * from './types.js';
3
+ export * from './errors.js';
4
+ export * from './transaction.js';
5
+ export * from './utils.js';
6
+ export * from './record.js';
7
+ export * from './model.js';
@@ -0,0 +1,72 @@
1
+ import type { SearchQuery, Schema, FlattenTypes, InferSchemaTypesRead, InferSchemaTypesWrite, MaybeArray } from '../types/index.js';
2
+ import type { DBRecord, DBRecordInstance, DBRecordsArrayInstance, RelationDetachOptions, RelationOptions, RelationTarget } from './record.js';
3
+ import type { Transaction } from './transaction.js';
4
+ import { RestApiProxy } from '../api/rest-api-proxy.js';
5
+ type RushDBInstance = {
6
+ registerModel(model: Model): void;
7
+ };
8
+ export declare class Model<S extends Schema = any> extends RestApiProxy {
9
+ readonly label: string;
10
+ readonly schema: S;
11
+ constructor(modelName: string, schema: S, RushDBInstance?: RushDBInstance);
12
+ /** @description
13
+ * Type helper for a draft version of the schema.
14
+ * Represents a flat object containing only the record's own properties
15
+ * (defined by the schema), excluding system fields such as `__id`, `__label`,
16
+ * and `__proptypes`. This type does not yet have a representation on the
17
+ * database side.
18
+ */
19
+ readonly draft: InferType<Model<S>>;
20
+ /** @description
21
+ * Type helper for a fully-defined record with database representation.
22
+ * Similar to the draft, but includes all fields that come with the record's
23
+ * database-side representation, such as `__id`, `__label`, and `__proptypes`.
24
+ */
25
+ readonly record: DBRecord<S>;
26
+ /** @description
27
+ * Type helper for a single record instance.
28
+ * Extends the record by providing additional methods to operate on this specific
29
+ * record, such as saving, updating, or deleting it.
30
+ */
31
+ readonly recordInstance: DBRecordInstance<S>;
32
+ /** @description
33
+ * Type helper for an array of record instances.
34
+ * Similar to a single record instance but supports batch or bulk operations,
35
+ * allowing efficient management of multiple records simultaneously.
36
+ */
37
+ readonly recordsArrayInstance: DBRecordsArrayInstance<S>;
38
+ getLabel(): string;
39
+ find(params?: SearchQuery<S> & {
40
+ labels?: never;
41
+ }, transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S>>;
42
+ findOne(params?: SearchQuery<S> & {
43
+ labels?: never;
44
+ limit?: never;
45
+ skip?: never;
46
+ }, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
47
+ findById(id: string, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
48
+ findUniq(params?: SearchQuery<S> & {
49
+ labels?: never;
50
+ limit?: never;
51
+ skip?: never;
52
+ }, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
53
+ create(record: InferSchemaTypesWrite<S>, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
54
+ attach(sourceId: string, target: RelationTarget, options?: RelationOptions, transaction?: Transaction | string): Promise<import("../api/types.js").ApiResponse<{
55
+ message: string;
56
+ }, Record<string, any>>>;
57
+ detach(sourceId: string, target: RelationTarget, options?: RelationDetachOptions, transaction?: Transaction | string): Promise<import("../api/types.js").ApiResponse<{
58
+ message: string;
59
+ }, Record<string, any>>>;
60
+ private handleSetOrUpdate;
61
+ set(id: string, record: InferSchemaTypesWrite<S>, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
62
+ update(id: string, record: Partial<InferSchemaTypesWrite<S>>, transaction?: Transaction | string): Promise<DBRecordInstance<S>>;
63
+ createMany(records: InferSchemaTypesWrite<S>[], transaction?: Transaction | string): Promise<DBRecordsArrayInstance<S>>;
64
+ delete(searchParams: Omit<SearchQuery<S>, 'labels'>, transaction?: Transaction | string): Promise<import("../api/types.js").ApiResponse<{
65
+ message: string;
66
+ }, Record<string, any>>>;
67
+ deleteById(idOrIds: MaybeArray<string>, transaction?: Transaction | string): Promise<import("../api/types.js").ApiResponse<{
68
+ message: string;
69
+ }, Record<string, any>>>;
70
+ }
71
+ export type InferType<M extends Model<any> = Model<any>> = FlattenTypes<InferSchemaTypesRead<M['schema']>>;
72
+ export {};
@@ -0,0 +1,109 @@
1
+ import type { AnyObject, PropertyType, PropertyValue, PropertyWithValue, SearchQuery, Schema, FlattenTypes, InferSchemaTypesRead, InferSchemaTypesWrite, MaybeArray, OptionalKeysRead, RequiredKeysRead } from '../types/index.js';
2
+ import type { Transaction } from './transaction.js';
3
+ import { RestApiProxy } from '../api/rest-api-proxy.js';
4
+ type DBRecordInternalProps<S extends Schema = Schema> = {
5
+ readonly __id: string;
6
+ readonly __label: string;
7
+ readonly __proptypes?: FlattenTypes<{
8
+ [Key in RequiredKeysRead<S>]: S[Key]['type'];
9
+ } & {
10
+ [Key in OptionalKeysRead<S>]?: S[Key]['type'];
11
+ }>;
12
+ };
13
+ export type RecordProps<S extends Schema = Schema> = S extends S ? InferSchemaTypesRead<S> : {
14
+ [K in keyof S]?: S[K];
15
+ };
16
+ export type DBRecord<S extends Schema = Schema> = FlattenTypes<DBRecordInternalProps<S> & FlattenTypes<RecordProps<S>>>;
17
+ export type DBRecordTarget = DBRecord<any> | DBRecordInstance<any> | string;
18
+ export type RelationTarget = DBRecordsArrayInstance<any> | MaybeArray<DBRecord<any>> | MaybeArray<DBRecordInstance<any>> | MaybeArray<string>;
19
+ export type Relation = {
20
+ sourceId: string;
21
+ sourceLabel: string;
22
+ targetId: string;
23
+ targetLabel: string;
24
+ type: string;
25
+ };
26
+ export type RelationDirection = 'in' | 'out';
27
+ export type RelationOptions = {
28
+ direction?: RelationDirection;
29
+ type?: string;
30
+ };
31
+ export type RelationDetachOptions = {
32
+ direction?: RelationDirection;
33
+ typeOrTypes?: string | string[];
34
+ };
35
+ export declare class DBRecordsBatchDraft {
36
+ label: string;
37
+ options?: {
38
+ returnResult?: boolean;
39
+ suggestTypes?: boolean;
40
+ };
41
+ payload: MaybeArray<AnyObject>;
42
+ constructor({ label, options, payload }: {
43
+ label: string;
44
+ options?: {
45
+ returnResult?: boolean;
46
+ suggestTypes?: boolean;
47
+ };
48
+ payload: AnyObject;
49
+ });
50
+ toJson(): {
51
+ label: string;
52
+ options: {
53
+ returnResult?: boolean;
54
+ suggestTypes?: boolean;
55
+ } | undefined;
56
+ payload: MaybeArray<AnyObject>;
57
+ };
58
+ }
59
+ export declare class DBRecordDraft {
60
+ label: string;
61
+ properties?: Array<{
62
+ metadata?: string;
63
+ name: string;
64
+ type: PropertyType;
65
+ value: PropertyValue;
66
+ valueSeparator?: string;
67
+ }>;
68
+ constructor({ label, properties }: {
69
+ label: string;
70
+ properties?: Array<PropertyWithValue & {
71
+ metadata?: string;
72
+ valueSeparator?: string;
73
+ }>;
74
+ relation?: RelationOptions;
75
+ });
76
+ toJson(): {
77
+ label: string;
78
+ properties: {
79
+ metadata?: string;
80
+ name: string;
81
+ type: PropertyType;
82
+ value: PropertyValue;
83
+ valueSeparator?: string;
84
+ }[] | undefined;
85
+ };
86
+ }
87
+ export declare class DBRecordInstance<S extends Schema = Schema> extends RestApiProxy {
88
+ data?: DBRecord<S>;
89
+ searchParams?: SearchQuery<S>;
90
+ constructor(data?: DBRecord<S>, searchParams?: SearchQuery<S>);
91
+ delete(transaction?: Transaction | string): Promise<import("../api/types.js").ApiResponse<{
92
+ message: string;
93
+ }, Record<string, any>> | undefined>;
94
+ update<S extends Schema = Schema>(partialData: DBRecordDraft | Partial<InferSchemaTypesWrite<S>>, transaction?: Transaction | string): Promise<DBRecordInstance<S> | undefined>;
95
+ set<S extends Schema = Schema>(data: DBRecordDraft | InferSchemaTypesWrite<S>, transaction?: Transaction | string): Promise<DBRecordInstance<S> | undefined>;
96
+ attach(target: RelationTarget, options?: RelationOptions, transaction?: Transaction | string): Promise<import("../api/types.js").ApiResponse<{
97
+ message: string;
98
+ }, Record<string, any>> | undefined>;
99
+ detach(target: RelationTarget, options?: RelationDetachOptions, transaction?: Transaction | string): Promise<import("../api/types.js").ApiResponse<{
100
+ message: string;
101
+ }, Record<string, any>> | undefined>;
102
+ }
103
+ export declare class DBRecordsArrayInstance<S extends Schema = Schema> extends RestApiProxy {
104
+ data?: DBRecord<S>[];
105
+ total: number | undefined;
106
+ searchParams?: SearchQuery<S>;
107
+ constructor(data?: DBRecord<S>[], total?: number, searchParams?: SearchQuery<S>);
108
+ }
109
+ export {};