@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.
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +119 -0
- package/cjs/api/api.js +328 -0
- package/cjs/api/constants.js +7 -0
- package/cjs/api/create-api.js +258 -0
- package/cjs/api/index.js +8 -0
- package/cjs/api/rest-api-proxy.js +22 -0
- package/cjs/api/types.js +2 -0
- package/cjs/api/utils.js +154 -0
- package/cjs/common/constants.js +10 -0
- package/cjs/common/utils.js +46 -0
- package/cjs/index.cjs.node.js +24 -0
- package/cjs/index.cjs.worker.js +24 -0
- package/cjs/network/FetchHttpClient.js +138 -0
- package/cjs/network/HttpClient.js +59 -0
- package/cjs/network/NodeHttpClient.js +103 -0
- package/cjs/network/index.js +28 -0
- package/cjs/network/types.js +2 -0
- package/cjs/package.json +4 -0
- package/cjs/sdk/constants.js +12 -0
- package/cjs/sdk/errors.js +27 -0
- package/cjs/sdk/index.js +23 -0
- package/cjs/sdk/model.js +147 -0
- package/cjs/sdk/record.js +77 -0
- package/cjs/sdk/sdk.js +46 -0
- package/cjs/sdk/transaction.js +17 -0
- package/cjs/sdk/types.js +2 -0
- package/cjs/sdk/utils.js +103 -0
- package/cjs/types/expressions.js +2 -0
- package/cjs/types/index.js +21 -0
- package/cjs/types/query.js +2 -0
- package/cjs/types/schema.js +2 -0
- package/cjs/types/utils.js +2 -0
- package/cjs/types/value.js +2 -0
- package/esm/api/api.js +324 -0
- package/esm/api/constants.js +4 -0
- package/esm/api/create-api.js +254 -0
- package/esm/api/index.js +2 -0
- package/esm/api/rest-api-proxy.js +18 -0
- package/esm/api/types.js +1 -0
- package/esm/api/utils.js +138 -0
- package/esm/common/constants.js +7 -0
- package/esm/common/utils.js +37 -0
- package/esm/index.esm.node.js +6 -0
- package/esm/index.esm.worker.js +6 -0
- package/esm/network/FetchHttpClient.js +133 -0
- package/esm/network/HttpClient.js +53 -0
- package/esm/network/NodeHttpClient.js +98 -0
- package/esm/network/index.js +24 -0
- package/esm/network/types.js +1 -0
- package/esm/package.json +4 -0
- package/esm/sdk/constants.js +9 -0
- package/esm/sdk/errors.js +21 -0
- package/esm/sdk/index.js +7 -0
- package/esm/sdk/model.js +143 -0
- package/esm/sdk/record.js +70 -0
- package/esm/sdk/sdk.js +42 -0
- package/esm/sdk/transaction.js +13 -0
- package/esm/sdk/types.js +1 -0
- package/esm/sdk/utils.js +93 -0
- package/esm/types/expressions.js +1 -0
- package/esm/types/index.js +5 -0
- package/esm/types/query.js +1 -0
- package/esm/types/schema.js +1 -0
- package/esm/types/utils.js +1 -0
- package/esm/types/value.js +1 -0
- package/package.json +59 -0
- package/types/api/api.d.ts +43 -0
- package/types/api/constants.d.ts +4 -0
- package/types/api/create-api.d.ts +67 -0
- package/types/api/index.d.ts +3 -0
- package/types/api/rest-api-proxy.d.ts +6 -0
- package/types/api/types.d.ts +65 -0
- package/types/api/utils.d.ts +43 -0
- package/types/common/constants.d.ts +7 -0
- package/types/common/utils.d.ts +7 -0
- package/types/index.d.ts +72 -0
- package/types/network/FetchHttpClient.d.ts +26 -0
- package/types/network/HttpClient.d.ts +48 -0
- package/types/network/NodeHttpClient.d.ts +16 -0
- package/types/network/index.d.ts +6 -0
- package/types/network/types.d.ts +4 -0
- package/types/sdk/constants.d.ts +1 -0
- package/types/sdk/errors.d.ts +9 -0
- package/types/sdk/index.d.ts +7 -0
- package/types/sdk/model.d.ts +72 -0
- package/types/sdk/record.d.ts +109 -0
- package/types/sdk/sdk.d.ts +136 -0
- package/types/sdk/transaction.d.ts +11 -0
- package/types/sdk/types.d.ts +19 -0
- package/types/sdk/utils.d.ts +9 -0
- package/types/types/expressions.d.ts +23 -0
- package/types/types/index.d.ts +5 -0
- package/types/types/query.d.ts +102 -0
- package/types/types/schema.d.ts +48 -0
- package/types/types/utils.d.ts +9 -0
- package/types/types/value.d.ts +35 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { HttpClient } from '../network/HttpClient.js';
|
|
2
|
+
import type { Models, Schema } from '../types/index.js';
|
|
3
|
+
import type { Model } from './model.js';
|
|
4
|
+
import type { State, UserProvidedConfig } from './types.js';
|
|
5
|
+
import { DBRecordInstance } from './record.js';
|
|
6
|
+
export declare const initSDK: (httpClient: HttpClient) => {
|
|
7
|
+
new (token?: string, config?: UserProvidedConfig): {
|
|
8
|
+
state: State;
|
|
9
|
+
models: Map<string, Model>;
|
|
10
|
+
registerModel<M extends Model = Model<any>>(model: Model): Model<any>;
|
|
11
|
+
getModels(): Map<string, Model>;
|
|
12
|
+
getModel<Label extends keyof Models | string = never>(label: Label): Label extends keyof Models ? Model<Models[Label]> : Model | undefined;
|
|
13
|
+
toInstance<S extends Schema = Schema>(record: import("../types/utils.js").FlattenTypes<{
|
|
14
|
+
readonly __id: string;
|
|
15
|
+
readonly __label: string;
|
|
16
|
+
readonly __proptypes?: import("../types/utils.js").FlattenTypes<{ [Key in import("../types/schema.js").RequiredKeysRead<S>]: S[Key]["type"]; } & { [Key_1 in import("../types/schema.js").OptionalKeysRead<S>]?: S[Key_1]["type"] | undefined; }> | undefined;
|
|
17
|
+
} & import("../types/utils.js").FlattenTypes<import("./record.js").RecordProps<S>>>): DBRecordInstance<S>;
|
|
18
|
+
api: ReturnType<typeof import("../api/create-api.js").createApi>;
|
|
19
|
+
fetcher: ReturnType<typeof import("../network/index.js").createFetcher>;
|
|
20
|
+
records: import("../api/types.js").RecordsApi;
|
|
21
|
+
relations: {
|
|
22
|
+
find: <S extends Schema = any>({ pagination, search, transaction }: {
|
|
23
|
+
pagination?: Pick<import("../types/query.js").SearchQuery, "limit" | "skip">;
|
|
24
|
+
search?: import("../types/query.js").SearchQuery<S> | undefined;
|
|
25
|
+
transaction?: import("./transaction.js").Transaction | string;
|
|
26
|
+
}) => Promise<import("../api/types.js").ApiResponse<import("./record.js").Relation[]>>;
|
|
27
|
+
};
|
|
28
|
+
properties: {
|
|
29
|
+
delete: (id: string, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<import("../types/value.js").Property>>;
|
|
30
|
+
find: <S extends Schema = any>(searchParams: import("../types/query.js").SearchQuery<S>, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<import("../types/value.js").Property[]>>;
|
|
31
|
+
findById: (id: string, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<import("../types/value.js").Property>>;
|
|
32
|
+
values: (id: string, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<import("../types/value.js").Property & import("../types/value.js").PropertyValuesData>>;
|
|
33
|
+
};
|
|
34
|
+
labels: {
|
|
35
|
+
find: <S extends Schema = any>(searchParams: import("../types/query.js").SearchQuery<S>, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<Record<string, number>>>;
|
|
36
|
+
};
|
|
37
|
+
tx: {
|
|
38
|
+
begin: (config?: Partial<{
|
|
39
|
+
ttl: number;
|
|
40
|
+
}>) => Promise<import("./transaction.js").Transaction>;
|
|
41
|
+
commit: (id: string) => Promise<import("../api/types.js").ApiResponse<{
|
|
42
|
+
message: string;
|
|
43
|
+
}>>;
|
|
44
|
+
get: (id: string) => Promise<import("./transaction.js").Transaction>;
|
|
45
|
+
rollback: (id: string) => Promise<import("../api/types.js").ApiResponse<{
|
|
46
|
+
message: string;
|
|
47
|
+
}>>;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
instance: {
|
|
51
|
+
state: State;
|
|
52
|
+
models: Map<string, Model>;
|
|
53
|
+
registerModel<M extends Model = Model<any>>(model: Model): Model<any>;
|
|
54
|
+
getModels(): Map<string, Model>;
|
|
55
|
+
getModel<Label extends keyof Models | string = never>(label: Label): Label extends keyof Models ? Model<Models[Label]> : Model | undefined;
|
|
56
|
+
toInstance<S extends Schema = Schema>(record: import("../types/utils.js").FlattenTypes<{
|
|
57
|
+
readonly __id: string;
|
|
58
|
+
readonly __label: string;
|
|
59
|
+
readonly __proptypes?: import("../types/utils.js").FlattenTypes<{ [Key in import("../types/schema.js").RequiredKeysRead<S>]: S[Key]["type"]; } & { [Key_1 in import("../types/schema.js").OptionalKeysRead<S>]?: S[Key_1]["type"] | undefined; }> | undefined;
|
|
60
|
+
} & import("../types/utils.js").FlattenTypes<import("./record.js").RecordProps<S>>>): DBRecordInstance<S>;
|
|
61
|
+
api: ReturnType<typeof import("../api/create-api.js").createApi>;
|
|
62
|
+
fetcher: ReturnType<typeof import("../network/index.js").createFetcher>;
|
|
63
|
+
records: import("../api/types.js").RecordsApi;
|
|
64
|
+
relations: {
|
|
65
|
+
find: <S extends Schema = any>({ pagination, search, transaction }: {
|
|
66
|
+
pagination?: Pick<import("../types/query.js").SearchQuery, "limit" | "skip">;
|
|
67
|
+
search?: import("../types/query.js").SearchQuery<S> | undefined;
|
|
68
|
+
transaction?: import("./transaction.js").Transaction | string;
|
|
69
|
+
}) => Promise<import("../api/types.js").ApiResponse<import("./record.js").Relation[]>>;
|
|
70
|
+
};
|
|
71
|
+
properties: {
|
|
72
|
+
delete: (id: string, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<import("../types/value.js").Property>>;
|
|
73
|
+
find: <S extends Schema = any>(searchParams: import("../types/query.js").SearchQuery<S>, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<import("../types/value.js").Property[]>>;
|
|
74
|
+
findById: (id: string, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<import("../types/value.js").Property>>;
|
|
75
|
+
values: (id: string, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<import("../types/value.js").Property & import("../types/value.js").PropertyValuesData>>;
|
|
76
|
+
};
|
|
77
|
+
labels: {
|
|
78
|
+
find: <S extends Schema = any>(searchParams: import("../types/query.js").SearchQuery<S>, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<Record<string, number>>>;
|
|
79
|
+
};
|
|
80
|
+
tx: {
|
|
81
|
+
begin: (config?: Partial<{
|
|
82
|
+
ttl: number;
|
|
83
|
+
}>) => Promise<import("./transaction.js").Transaction>;
|
|
84
|
+
commit: (id: string) => Promise<import("../api/types.js").ApiResponse<{
|
|
85
|
+
message: string;
|
|
86
|
+
}>>;
|
|
87
|
+
get: (id: string) => Promise<import("./transaction.js").Transaction>;
|
|
88
|
+
rollback: (id: string) => Promise<import("../api/types.js").ApiResponse<{
|
|
89
|
+
message: string;
|
|
90
|
+
}>>;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
getInstance(): {
|
|
94
|
+
state: State;
|
|
95
|
+
models: Map<string, Model>;
|
|
96
|
+
registerModel<M extends Model = Model<any>>(model: Model): Model<any>;
|
|
97
|
+
getModels(): Map<string, Model>;
|
|
98
|
+
getModel<Label extends keyof Models | string = never>(label: Label): Label extends keyof Models ? Model<Models[Label]> : Model | undefined;
|
|
99
|
+
toInstance<S extends Schema = Schema>(record: import("../types/utils.js").FlattenTypes<{
|
|
100
|
+
readonly __id: string;
|
|
101
|
+
readonly __label: string;
|
|
102
|
+
readonly __proptypes?: import("../types/utils.js").FlattenTypes<{ [Key in import("../types/schema.js").RequiredKeysRead<S>]: S[Key]["type"]; } & { [Key_1 in import("../types/schema.js").OptionalKeysRead<S>]?: S[Key_1]["type"] | undefined; }> | undefined;
|
|
103
|
+
} & import("../types/utils.js").FlattenTypes<import("./record.js").RecordProps<S>>>): DBRecordInstance<S>;
|
|
104
|
+
api: ReturnType<typeof import("../api/create-api.js").createApi>;
|
|
105
|
+
fetcher: ReturnType<typeof import("../network/index.js").createFetcher>;
|
|
106
|
+
records: import("../api/types.js").RecordsApi;
|
|
107
|
+
relations: {
|
|
108
|
+
find: <S extends Schema = any>({ pagination, search, transaction }: {
|
|
109
|
+
pagination?: Pick<import("../types/query.js").SearchQuery, "limit" | "skip">;
|
|
110
|
+
search?: import("../types/query.js").SearchQuery<S> | undefined;
|
|
111
|
+
transaction?: import("./transaction.js").Transaction | string;
|
|
112
|
+
}) => Promise<import("../api/types.js").ApiResponse<import("./record.js").Relation[]>>;
|
|
113
|
+
};
|
|
114
|
+
properties: {
|
|
115
|
+
delete: (id: string, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<import("../types/value.js").Property>>;
|
|
116
|
+
find: <S extends Schema = any>(searchParams: import("../types/query.js").SearchQuery<S>, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<import("../types/value.js").Property[]>>;
|
|
117
|
+
findById: (id: string, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<import("../types/value.js").Property>>;
|
|
118
|
+
values: (id: string, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<import("../types/value.js").Property & import("../types/value.js").PropertyValuesData>>;
|
|
119
|
+
};
|
|
120
|
+
labels: {
|
|
121
|
+
find: <S extends Schema = any>(searchParams: import("../types/query.js").SearchQuery<S>, transaction?: import("./transaction.js").Transaction | string) => Promise<import("../api/types.js").ApiResponse<Record<string, number>>>;
|
|
122
|
+
};
|
|
123
|
+
tx: {
|
|
124
|
+
begin: (config?: Partial<{
|
|
125
|
+
ttl: number;
|
|
126
|
+
}>) => Promise<import("./transaction.js").Transaction>;
|
|
127
|
+
commit: (id: string) => Promise<import("../api/types.js").ApiResponse<{
|
|
128
|
+
message: string;
|
|
129
|
+
}>>;
|
|
130
|
+
get: (id: string) => Promise<import("./transaction.js").Transaction>;
|
|
131
|
+
rollback: (id: string) => Promise<import("../api/types.js").ApiResponse<{
|
|
132
|
+
message: string;
|
|
133
|
+
}>>;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RestApiProxy } from '../api/rest-api-proxy.js';
|
|
2
|
+
export declare class Transaction extends RestApiProxy {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
constructor(id: string);
|
|
5
|
+
rollback(): Promise<import("../api/types.js").ApiResponse<{
|
|
6
|
+
message: string;
|
|
7
|
+
}>>;
|
|
8
|
+
commit(): Promise<import("../api/types.js").ApiResponse<{
|
|
9
|
+
message: string;
|
|
10
|
+
}>>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { HttpClientInterface } from '../network/HttpClient.js';
|
|
2
|
+
type ApiConnectionConfig = {
|
|
3
|
+
host: string;
|
|
4
|
+
port: number;
|
|
5
|
+
protocol: string;
|
|
6
|
+
} | {
|
|
7
|
+
url: string;
|
|
8
|
+
};
|
|
9
|
+
export type State = {
|
|
10
|
+
debug: boolean;
|
|
11
|
+
timeout: number;
|
|
12
|
+
token?: string;
|
|
13
|
+
} & Partial<ApiConnectionConfig>;
|
|
14
|
+
type CommonUserProvidedConfig = {
|
|
15
|
+
httpClient?: HttpClientInterface;
|
|
16
|
+
timeout?: number;
|
|
17
|
+
} & ApiConnectionConfig;
|
|
18
|
+
export type UserProvidedConfig = CommonUserProvidedConfig;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PropertyValue, Schema, InferSchemaTypesWrite } from '../types/index.js';
|
|
2
|
+
import type { UserProvidedConfig } from './types.js';
|
|
3
|
+
export declare const mergeDefaultsWithPayload: <S extends Schema = Schema>(schema: S, payload: Partial<InferSchemaTypesWrite<S>>) => Promise<InferSchemaTypesWrite<S>>;
|
|
4
|
+
export declare const pickUniqFieldsFromRecord: <S extends Schema = Schema>(schema: S, data: Partial<InferSchemaTypesWrite<S>>) => Record<string, PropertyValue>;
|
|
5
|
+
export declare const pickUniqFieldsFromRecords: <S extends Schema = Schema>(data: Partial<InferSchemaTypesWrite<S>>[], schema: S, label: string) => Record<string, PropertyValue[]>;
|
|
6
|
+
export declare const parseConfig: (config?: Record<string, unknown>) => UserProvidedConfig;
|
|
7
|
+
export declare function validateInteger(name: string, n: unknown, defaultVal?: number): number;
|
|
8
|
+
export declare function idToTimestamp(id: string): number;
|
|
9
|
+
export declare function idToDate(id: string): Date;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PROPERTY_TYPE_BOOLEAN, PROPERTY_TYPE_DATETIME, PROPERTY_TYPE_NULL, PROPERTY_TYPE_NUMBER, PROPERTY_TYPE_STRING } from '../common/constants.js';
|
|
2
|
+
import type { MaybeArray, RequireAtLeastOne } from './utils.js';
|
|
3
|
+
import type { BooleanValue, DatetimeObject, DatetimeValue, NullValue, NumberValue, StringValue } from './value.js';
|
|
4
|
+
export type DatetimeExpression = DatetimeValue | RequireAtLeastOne<Record<'$gt' | '$gte' | '$lt' | '$lte' | '$ne', DatetimeObject | DatetimeValue> & Record<'$in' | '$nin', Array<DatetimeObject | DatetimeValue>>>;
|
|
5
|
+
export type BooleanExpression = BooleanValue | Record<'$ne', BooleanValue>;
|
|
6
|
+
export type NullExpression = NullValue | Record<'$ne', NullValue>;
|
|
7
|
+
export type NumberExpression = NumberValue | RequireAtLeastOne<Record<'$gt' | '$gte' | '$lt' | '$lte' | '$ne', NumberValue> & Record<'$in' | '$nin', Array<NumberValue>>>;
|
|
8
|
+
export type StringExpression = StringValue | RequireAtLeastOne<Record<'$contains' | '$endsWith' | '$ne' | '$startsWith', StringValue> & Record<'$in' | '$nin', Array<StringValue>>>;
|
|
9
|
+
export type PropertyExpression = BooleanExpression | DatetimeExpression | NullExpression | NumberExpression | StringExpression;
|
|
10
|
+
export type PropertyExpressionByType = {
|
|
11
|
+
[PROPERTY_TYPE_BOOLEAN]: BooleanExpression;
|
|
12
|
+
[PROPERTY_TYPE_DATETIME]: DatetimeExpression;
|
|
13
|
+
[PROPERTY_TYPE_NULL]: NullExpression;
|
|
14
|
+
[PROPERTY_TYPE_NUMBER]: NumberExpression;
|
|
15
|
+
[PROPERTY_TYPE_STRING]: StringExpression;
|
|
16
|
+
};
|
|
17
|
+
export type LogicalGrouping<T> = Partial<{
|
|
18
|
+
$and: MaybeArray<T>;
|
|
19
|
+
$nor: MaybeArray<T>;
|
|
20
|
+
$not: MaybeArray<T>;
|
|
21
|
+
$or: MaybeArray<T>;
|
|
22
|
+
$xor: MaybeArray<T>;
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { RelationOptions } from '../sdk/index.js';
|
|
2
|
+
import type { BooleanExpression, PropertyExpression, PropertyExpressionByType, DatetimeExpression, LogicalGrouping, NullExpression, NumberExpression, StringExpression } from './expressions.js';
|
|
3
|
+
import type { Schema } from './schema.js';
|
|
4
|
+
import type { MaybeArray, RequireAtLeastOne } from './utils.js';
|
|
5
|
+
export type Relation = RelationOptions | string;
|
|
6
|
+
export type Related = {
|
|
7
|
+
[Key in keyof Models]?: {
|
|
8
|
+
$alias?: string;
|
|
9
|
+
$relation?: Relation;
|
|
10
|
+
} & Where<Models[Key]>;
|
|
11
|
+
};
|
|
12
|
+
export type LogicalExpressionValue<T = PropertyExpression & Related> = AndExpression<T> | NorExpression<T> | NotExpression<T> | OrExpression<T> | T | XorExpression<T>;
|
|
13
|
+
export type AndExpression<T = PropertyExpression & Related> = {
|
|
14
|
+
$and: MaybeArray<LogicalExpressionValue<T>>;
|
|
15
|
+
};
|
|
16
|
+
export type OrExpression<T = PropertyExpression & Related> = {
|
|
17
|
+
$or: MaybeArray<LogicalExpressionValue<T>>;
|
|
18
|
+
};
|
|
19
|
+
export type NotExpression<T = PropertyExpression & Related> = {
|
|
20
|
+
$not: MaybeArray<LogicalExpressionValue<T>>;
|
|
21
|
+
};
|
|
22
|
+
export type XorExpression<T = PropertyExpression & Related> = {
|
|
23
|
+
$xor: MaybeArray<LogicalExpressionValue<T>>;
|
|
24
|
+
};
|
|
25
|
+
export type NorExpression<T = PropertyExpression & Related> = {
|
|
26
|
+
$nor: MaybeArray<LogicalExpressionValue<T>>;
|
|
27
|
+
};
|
|
28
|
+
export type LogicalExpression<T = PropertyExpression & Related> = RequireAtLeastOne<AndExpression<T> & OrExpression<T> & NotExpression<T> & XorExpression<T> & NorExpression<T>>;
|
|
29
|
+
type MaybeLogicalExpression<T> = LogicalExpression<T> | T;
|
|
30
|
+
export type IdExpression = MaybeLogicalExpression<{
|
|
31
|
+
$id?: LogicalExpression<StringExpression> | StringExpression;
|
|
32
|
+
} & Related>;
|
|
33
|
+
export type Expression<S extends Schema = Schema> = IdExpression | (S extends Schema ? {
|
|
34
|
+
[Key in keyof S]?: MaybeLogicalExpression<PropertyExpressionByType[S[Key]['type']]>;
|
|
35
|
+
} : {
|
|
36
|
+
[Key in keyof S]?: S[Key] extends MaybeArray<number> ? MaybeLogicalExpression<NumberExpression> : S[Key] extends MaybeArray<boolean> ? MaybeLogicalExpression<BooleanExpression> : S[Key] extends MaybeArray<string> ? MaybeLogicalExpression<DatetimeExpression> | MaybeLogicalExpression<StringExpression> : S[Key] extends MaybeArray<null> ? MaybeLogicalExpression<NullExpression> : LogicalExpression | Partial<PropertyExpression>;
|
|
37
|
+
});
|
|
38
|
+
export type Where<S extends Schema = Schema> = ((Expression<S> & Related) & LogicalGrouping<Expression<S> & Related>) | LogicalGrouping<Expression<S> & Related>;
|
|
39
|
+
export type Order<S extends Schema = Schema> = 'asc' | 'desc' | Partial<Record<keyof S, 'asc' | 'desc'>>;
|
|
40
|
+
export type AggregateCollectFn = {
|
|
41
|
+
alias: string;
|
|
42
|
+
field?: string;
|
|
43
|
+
fn: 'collect';
|
|
44
|
+
limit?: number;
|
|
45
|
+
orderBy?: Order;
|
|
46
|
+
skip?: number;
|
|
47
|
+
uniq?: true;
|
|
48
|
+
};
|
|
49
|
+
export type AggregateCollectNestedFn = Omit<AggregateCollectFn, 'field'> & {
|
|
50
|
+
aggregate?: {
|
|
51
|
+
[field: string]: AggregateCollectNestedFn;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export type AggregateFn<S extends Schema = Schema> = {
|
|
55
|
+
alias: string;
|
|
56
|
+
field: string;
|
|
57
|
+
fn: 'avg';
|
|
58
|
+
precision?: number;
|
|
59
|
+
} | {
|
|
60
|
+
alias: string;
|
|
61
|
+
field: string;
|
|
62
|
+
fn: 'max';
|
|
63
|
+
} | {
|
|
64
|
+
alias: string;
|
|
65
|
+
field: string;
|
|
66
|
+
fn: 'min';
|
|
67
|
+
} | {
|
|
68
|
+
alias: string;
|
|
69
|
+
field: string;
|
|
70
|
+
fn: 'sum';
|
|
71
|
+
} | {
|
|
72
|
+
alias: string;
|
|
73
|
+
field?: string;
|
|
74
|
+
fn: 'count';
|
|
75
|
+
uniq?: true;
|
|
76
|
+
} | AggregateCollectFn;
|
|
77
|
+
export type Aggregate = {
|
|
78
|
+
[field: string]: AggregateCollectNestedFn;
|
|
79
|
+
} | {
|
|
80
|
+
[field: string]: AggregateFn | string;
|
|
81
|
+
};
|
|
82
|
+
export type WhereClause<S extends Schema = Schema> = {
|
|
83
|
+
where?: Where<S>;
|
|
84
|
+
};
|
|
85
|
+
export type PaginationClause = {
|
|
86
|
+
limit?: number;
|
|
87
|
+
skip?: number;
|
|
88
|
+
};
|
|
89
|
+
export type SearchQueryLabelsClause = {
|
|
90
|
+
labels?: string[];
|
|
91
|
+
};
|
|
92
|
+
export type OrderClause<S extends Schema = Schema> = {
|
|
93
|
+
orderBy?: Order<S>;
|
|
94
|
+
};
|
|
95
|
+
export type AggregateClause = {
|
|
96
|
+
aggregate?: Aggregate;
|
|
97
|
+
};
|
|
98
|
+
export type SearchQuery<S extends Schema = any> = SearchQueryLabelsClause & PaginationClause & OrderClause<S> & WhereClause<S> & AggregateClause;
|
|
99
|
+
/** Redeclare Models type in order to have suggestions over related records fields **/
|
|
100
|
+
export interface Models {
|
|
101
|
+
}
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { FlattenTypes, MaybePromise } from './utils.js';
|
|
2
|
+
import type { DatetimeObject, PropertyType, PropertyValue } from './value.js';
|
|
3
|
+
export type SchemaDefaultValue<T extends PropertyType = PropertyType> = MaybePromise<PropertyValue<T>>;
|
|
4
|
+
export type SchemaField<T extends PropertyType = PropertyType> = {
|
|
5
|
+
default?: SchemaDefaultValue<T>;
|
|
6
|
+
multiple?: boolean;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
type: T;
|
|
9
|
+
uniq?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type Schema = Record<string, SchemaField>;
|
|
12
|
+
type TypeMappingWrite = {
|
|
13
|
+
boolean: boolean;
|
|
14
|
+
datetime: DatetimeObject | string;
|
|
15
|
+
null: null;
|
|
16
|
+
number: number;
|
|
17
|
+
string: string;
|
|
18
|
+
};
|
|
19
|
+
export type OptionalKeysWrite<S extends Schema = Schema> = {
|
|
20
|
+
[Key in keyof S]: S[Key]['required'] extends false ? Key : S[Key]['default'] extends SchemaDefaultValue ? Key : never;
|
|
21
|
+
}[keyof S];
|
|
22
|
+
export type RequiredKeysWrite<S extends Schema = Schema> = {
|
|
23
|
+
[Key in keyof S]: S[Key]['required'] extends false ? never : S[Key]['default'] extends SchemaDefaultValue ? never : Key;
|
|
24
|
+
}[keyof S];
|
|
25
|
+
export type InferSchemaTypesWrite<S extends Schema = Schema> = FlattenTypes<{
|
|
26
|
+
[Key in RequiredKeysWrite<S>]: S[Key]['multiple'] extends true ? TypeMappingWrite[S[Key]['type']][] : TypeMappingWrite[S[Key]['type']];
|
|
27
|
+
} & {
|
|
28
|
+
[Key in OptionalKeysWrite<S>]?: S[Key]['multiple'] extends true ? TypeMappingWrite[S[Key]['type']][] : TypeMappingWrite[S[Key]['type']];
|
|
29
|
+
}>;
|
|
30
|
+
type TypeMappingRead = {
|
|
31
|
+
boolean: boolean;
|
|
32
|
+
datetime: string;
|
|
33
|
+
null: null;
|
|
34
|
+
number: number;
|
|
35
|
+
string: string;
|
|
36
|
+
};
|
|
37
|
+
export type OptionalKeysRead<S extends Schema = Schema> = {
|
|
38
|
+
[Key in keyof S]: S[Key]['required'] extends false ? Key : never;
|
|
39
|
+
}[keyof S];
|
|
40
|
+
export type RequiredKeysRead<S extends Schema = Schema> = {
|
|
41
|
+
[Key in keyof S]: S[Key]['required'] extends false ? never : Key;
|
|
42
|
+
}[keyof S];
|
|
43
|
+
export type InferSchemaTypesRead<S extends Schema = Schema> = FlattenTypes<{
|
|
44
|
+
[Key in RequiredKeysRead<S>]: S[Key]['multiple'] extends true ? TypeMappingRead[S[Key]['type']][] : TypeMappingRead[S[Key]['type']];
|
|
45
|
+
} & {
|
|
46
|
+
[Key in OptionalKeysRead<S>]?: S[Key]['multiple'] extends true ? TypeMappingRead[S[Key]['type']][] : TypeMappingRead[S[Key]['type']];
|
|
47
|
+
}>;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type MaybePromise<T = any> = () => Promise<T> | T;
|
|
2
|
+
export type RequireAtLeastOne<T> = {
|
|
3
|
+
[K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>;
|
|
4
|
+
}[keyof T];
|
|
5
|
+
export type MaybeArray<T> = Array<T> | T;
|
|
6
|
+
export type FlattenTypes<T> = T extends object ? {
|
|
7
|
+
[K in keyof T]: FlattenTypes<T[K]>;
|
|
8
|
+
} : T;
|
|
9
|
+
export type AnyObject = Record<string, any>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PROPERTY_TYPE_BOOLEAN, PROPERTY_TYPE_DATETIME, PROPERTY_TYPE_NULL, PROPERTY_TYPE_NUMBER, PROPERTY_TYPE_STRING } from '../common/constants.js';
|
|
2
|
+
import type { MaybeArray } from './utils.js';
|
|
3
|
+
export type DatetimeObject = {
|
|
4
|
+
$day?: number;
|
|
5
|
+
$hour?: number;
|
|
6
|
+
$microsecond?: number;
|
|
7
|
+
$millisecond?: number;
|
|
8
|
+
$minute?: number;
|
|
9
|
+
$month?: number;
|
|
10
|
+
$nanosecond?: number;
|
|
11
|
+
$second?: number;
|
|
12
|
+
$year: number;
|
|
13
|
+
};
|
|
14
|
+
export type DatetimeValue = DatetimeObject | string;
|
|
15
|
+
export type BooleanValue = boolean;
|
|
16
|
+
export type NullValue = null;
|
|
17
|
+
export type NumberValue = number;
|
|
18
|
+
export type StringValue = string;
|
|
19
|
+
export type PropertyType = typeof PROPERTY_TYPE_BOOLEAN | typeof PROPERTY_TYPE_DATETIME | typeof PROPERTY_TYPE_NULL | typeof PROPERTY_TYPE_NUMBER | typeof PROPERTY_TYPE_STRING;
|
|
20
|
+
export type Property = {
|
|
21
|
+
id: string;
|
|
22
|
+
metadata?: string;
|
|
23
|
+
name: string;
|
|
24
|
+
type: PropertyType;
|
|
25
|
+
};
|
|
26
|
+
export type PropertyWithValue = Property & {
|
|
27
|
+
value: PropertyValue;
|
|
28
|
+
};
|
|
29
|
+
export type PropertyValuesData = {
|
|
30
|
+
max?: number;
|
|
31
|
+
min?: number;
|
|
32
|
+
values: PropertyValue[];
|
|
33
|
+
};
|
|
34
|
+
export type PropertySingleValue<TType extends PropertyType = PropertyType> = TType extends typeof PROPERTY_TYPE_DATETIME ? DatetimeValue : TType extends typeof PROPERTY_TYPE_NUMBER ? NumberValue : TType extends typeof PROPERTY_TYPE_STRING ? StringValue : TType extends typeof PROPERTY_TYPE_NULL ? NullValue : TType extends typeof PROPERTY_TYPE_BOOLEAN ? BooleanValue : StringValue;
|
|
35
|
+
export type PropertyValue<TType extends PropertyType = PropertyType> = MaybeArray<PropertySingleValue<TType>>;
|