@ja-platform/db 0.0.0-dev-20261113193343 → 0.0.0-stage
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/README.md +3 -0
- package/package.json +3 -52
- package/LICENSE +0 -521
- package/dist/@types/Schema.d.ts +0 -1
- package/dist/@types/app.d.ts +0 -12
- package/dist/@types/browser.d.ts +0 -31
- package/dist/@types/credentials/ApiCredentials.d.ts +0 -18
- package/dist/@types/credentials/MobileCredentials.d.ts +0 -22
- package/dist/@types/credentials/index.d.ts +0 -2
- package/dist/@types/database/Batch.d.ts +0 -61
- package/dist/@types/database/Collection.d.ts +0 -85
- package/dist/@types/database/Database.d.ts +0 -22
- package/dist/@types/database/DatabaseObject.d.ts +0 -51
- package/dist/@types/database/GenericDatabase.d.ts +0 -4
- package/dist/@types/database/JourneyAPIAdapter.d.ts +0 -45
- package/dist/@types/database/ObjectDisplayScope.d.ts +0 -22
- package/dist/@types/database/OnlineDB.d.ts +0 -8
- package/dist/@types/database/adapters/BaseAdapter.d.ts +0 -26
- package/dist/@types/database/adapters/DatabaseAdapter.d.ts +0 -22
- package/dist/@types/database/adapters/WebSQLAdapter.d.ts +0 -50
- package/dist/@types/index.d.ts +0 -2
- package/dist/@types/query/InternalQuery.d.ts +0 -17
- package/dist/@types/query/Query.d.ts +0 -133
- package/dist/@types/query/getPreloadRelationships.d.ts +0 -9
- package/dist/@types/query/queryOperations.d.ts +0 -87
- package/dist/@types/types/Attachment.d.ts +0 -104
- package/dist/@types/types/Location.d.ts +0 -18
- package/dist/@types/types/ObjectData.d.ts +0 -12
- package/dist/@types/types/TypeOperations.d.ts +0 -42
- package/dist/@types/utils/FunctionQueue.d.ts +0 -32
- package/dist/@types/utils/JourneyPromise.d.ts +0 -2
- package/dist/@types/utils/base64.d.ts +0 -4
- package/dist/@types/utils/retryableFetch.d.ts +0 -3
- package/dist/Schema.js +0 -6
- package/dist/Schema.js.map +0 -1
- package/dist/app.js +0 -30
- package/dist/app.js.map +0 -1
- package/dist/browser.js +0 -77
- package/dist/browser.js.map +0 -1
- package/dist/credentials/ApiCredentials.js +0 -61
- package/dist/credentials/ApiCredentials.js.map +0 -1
- package/dist/credentials/MobileCredentials.js +0 -73
- package/dist/credentials/MobileCredentials.js.map +0 -1
- package/dist/credentials/index.js +0 -19
- package/dist/credentials/index.js.map +0 -1
- package/dist/database/Batch.js +0 -189
- package/dist/database/Batch.js.map +0 -1
- package/dist/database/Collection.js +0 -69
- package/dist/database/Collection.js.map +0 -1
- package/dist/database/Database.js +0 -47
- package/dist/database/Database.js.map +0 -1
- package/dist/database/DatabaseObject.js +0 -646
- package/dist/database/DatabaseObject.js.map +0 -1
- package/dist/database/GenericDatabase.js +0 -3
- package/dist/database/GenericDatabase.js.map +0 -1
- package/dist/database/JourneyAPIAdapter.js +0 -357
- package/dist/database/JourneyAPIAdapter.js.map +0 -1
- package/dist/database/ObjectDisplayScope.js +0 -117
- package/dist/database/ObjectDisplayScope.js.map +0 -1
- package/dist/database/OnlineDB.js +0 -16
- package/dist/database/OnlineDB.js.map +0 -1
- package/dist/database/adapters/BaseAdapter.js +0 -66
- package/dist/database/adapters/BaseAdapter.js.map +0 -1
- package/dist/database/adapters/DatabaseAdapter.js +0 -3
- package/dist/database/adapters/DatabaseAdapter.js.map +0 -1
- package/dist/database/adapters/WebSQLAdapter.js +0 -343
- package/dist/database/adapters/WebSQLAdapter.js.map +0 -1
- package/dist/index.js +0 -20
- package/dist/index.js.map +0 -1
- package/dist/query/InternalQuery.js +0 -3
- package/dist/query/InternalQuery.js.map +0 -1
- package/dist/query/Query.js +0 -414
- package/dist/query/Query.js.map +0 -1
- package/dist/query/getPreloadRelationships.js +0 -45
- package/dist/query/getPreloadRelationships.js.map +0 -1
- package/dist/query/queryOperations.js +0 -678
- package/dist/query/queryOperations.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types/Attachment.js +0 -198
- package/dist/types/Attachment.js.map +0 -1
- package/dist/types/Location.js +0 -38
- package/dist/types/Location.js.map +0 -1
- package/dist/types/ObjectData.js +0 -3
- package/dist/types/ObjectData.js.map +0 -1
- package/dist/types/TypeOperations.js +0 -267
- package/dist/types/TypeOperations.js.map +0 -1
- package/dist/utils/FunctionQueue.js +0 -91
- package/dist/utils/FunctionQueue.js.map +0 -1
- package/dist/utils/JourneyPromise.js +0 -3
- package/dist/utils/JourneyPromise.js.map +0 -1
- package/dist/utils/base64.js +0 -40
- package/dist/utils/base64.js.map +0 -1
- package/dist/utils/retryableFetch.js +0 -57
- package/dist/utils/retryableFetch.js.map +0 -1
- package/readme.md +0 -37
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { PersistedObjectData } from '../types/ObjectData';
|
|
2
|
-
import * as j from '../utils/JourneyPromise';
|
|
3
|
-
import { DatabaseAdapter } from './adapters/DatabaseAdapter';
|
|
4
|
-
import { Database } from './Database';
|
|
5
|
-
import { DatabaseObject } from './DatabaseObject';
|
|
6
|
-
export interface BatchError {
|
|
7
|
-
object: DatabaseObject;
|
|
8
|
-
operation: 'put' | 'patch' | 'delete' | 'ignore';
|
|
9
|
-
error: {
|
|
10
|
-
detail: string;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export interface ExecuteBatchOperation {
|
|
14
|
-
op: 'put' | 'patch' | 'delete' | 'ignore';
|
|
15
|
-
type: string;
|
|
16
|
-
id: string;
|
|
17
|
-
object: DatabaseObject;
|
|
18
|
-
data?: PersistedObjectData;
|
|
19
|
-
patch?: PersistedObjectData;
|
|
20
|
-
}
|
|
21
|
-
export interface ExecuteBatchResult {
|
|
22
|
-
error?: any;
|
|
23
|
-
}
|
|
24
|
-
export declare class Batch {
|
|
25
|
-
/**
|
|
26
|
-
* Construct a new batch.
|
|
27
|
-
*
|
|
28
|
-
* If the same object is added to the batch multiple times, only the last instance
|
|
29
|
-
* is kept.
|
|
30
|
-
*
|
|
31
|
-
* @param adapter the Database instance
|
|
32
|
-
*/
|
|
33
|
-
constructor(adapter: DatabaseAdapter | Database);
|
|
34
|
-
/**
|
|
35
|
-
* Add an object to save to the batch. The object is saved when batch.execute() is called.
|
|
36
|
-
*/
|
|
37
|
-
save(object: DatabaseObject): void;
|
|
38
|
-
/**
|
|
39
|
-
* Add an object to destroy to the batch. The object is destroyed when batch.execute() is called.
|
|
40
|
-
*/
|
|
41
|
-
destroy(object: DatabaseObject): void;
|
|
42
|
-
/**
|
|
43
|
-
* Execute the batch.
|
|
44
|
-
*
|
|
45
|
-
* There are two classes of errors:
|
|
46
|
-
* 1. Network or code error. The entire batch is rejected with an error.
|
|
47
|
-
* 2. Individual object errors. In this case, the batch is rejected with a CrudError, which contains the individual errors.
|
|
48
|
-
*/
|
|
49
|
-
execute(): j.Promise<void>;
|
|
50
|
-
private _getOps;
|
|
51
|
-
}
|
|
52
|
-
export declare class CrudError extends Error {
|
|
53
|
-
errors: BatchError[];
|
|
54
|
-
constructor(errors: BatchError[]);
|
|
55
|
-
/**
|
|
56
|
-
* Return the first error. Useful if this was used for a single operation.
|
|
57
|
-
*/
|
|
58
|
-
firstError(): {
|
|
59
|
-
detail: string;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { DatabaseObject } from './DatabaseObject';
|
|
2
|
-
import { SchemaModelType } from '@ja-platform/parser-schema';
|
|
3
|
-
import { DatabaseAdapter } from './adapters/DatabaseAdapter';
|
|
4
|
-
import { Query } from '../query/Query';
|
|
5
|
-
import * as j from '../utils/JourneyPromise';
|
|
6
|
-
export declare class Collection<T extends DatabaseObject = DatabaseObject> {
|
|
7
|
-
type: SchemaModelType;
|
|
8
|
-
adapter: DatabaseAdapter;
|
|
9
|
-
constructor(adapter: DatabaseAdapter, type: SchemaModelType);
|
|
10
|
-
/**
|
|
11
|
-
* Query for all objects in the collection. The query may be filtered further.
|
|
12
|
-
*
|
|
13
|
-
* Return the results as a Query. Call `.toArray()` to get the results.
|
|
14
|
-
*/
|
|
15
|
-
all(): Query<T>;
|
|
16
|
-
/**
|
|
17
|
-
* Create a new object.
|
|
18
|
-
*
|
|
19
|
-
* It is not saved until .save() is called.
|
|
20
|
-
*
|
|
21
|
-
* @param attributes - Enumerable object to initialize with.
|
|
22
|
-
*/
|
|
23
|
-
create(attributes?: any): T;
|
|
24
|
-
/**
|
|
25
|
-
* Filter by a query string and arguments.
|
|
26
|
-
*
|
|
27
|
-
* Return the results as a Query. Call `.toArray()` to get the results.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* Example:
|
|
31
|
-
*
|
|
32
|
-
* DB.user.where('email = ? and archived != ?', email, false)
|
|
33
|
-
*
|
|
34
|
-
* @param query the query string
|
|
35
|
-
* @param args the query args
|
|
36
|
-
*/
|
|
37
|
-
where(query: string, ...args: any[]): Query<T>;
|
|
38
|
-
/**
|
|
39
|
-
* Filter by an object of {attribute: value} pairs.
|
|
40
|
-
*
|
|
41
|
-
* Return the results as a Query. Call `.toArray()` to get the results.
|
|
42
|
-
*
|
|
43
|
-
* @param filters an object of {field: value}
|
|
44
|
-
*/
|
|
45
|
-
where(filters: {
|
|
46
|
-
[key: string]: any;
|
|
47
|
-
}): Query<T>;
|
|
48
|
-
/**
|
|
49
|
-
* Same as .all()
|
|
50
|
-
*/
|
|
51
|
-
where(): Query<T>;
|
|
52
|
-
private _first;
|
|
53
|
-
/**
|
|
54
|
-
* Get a single object by id.
|
|
55
|
-
*/
|
|
56
|
-
first(id: string): j.Promise<T>;
|
|
57
|
-
/**
|
|
58
|
-
* Get a single object by query.
|
|
59
|
-
*
|
|
60
|
-
* If the query has more than one matching result, only the first seen one is returned.
|
|
61
|
-
*
|
|
62
|
-
* Same as .where(...).first().
|
|
63
|
-
*
|
|
64
|
-
* @param query the query string
|
|
65
|
-
* @param args the query args
|
|
66
|
-
*/
|
|
67
|
-
first(query: string, ...args: any[]): j.Promise<T>;
|
|
68
|
-
/**
|
|
69
|
-
* Return a single object from the collection.
|
|
70
|
-
*/
|
|
71
|
-
first(): j.Promise<T>;
|
|
72
|
-
/**
|
|
73
|
-
* Get a single object by query.
|
|
74
|
-
*
|
|
75
|
-
* If the query has more than one matching result, only the first seen one is returned.
|
|
76
|
-
*
|
|
77
|
-
* Same as .where(...).first().
|
|
78
|
-
*
|
|
79
|
-
* @param filters an object of {field: value}
|
|
80
|
-
*/
|
|
81
|
-
first(filters: {
|
|
82
|
-
[key: string]: any;
|
|
83
|
-
}): j.Promise<T>;
|
|
84
|
-
}
|
|
85
|
-
export type TypedCollection<T> = Collection<DatabaseObject & T>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ApiCredentialOptions } from '../credentials';
|
|
2
|
-
import { DatabaseAdapter } from './adapters/DatabaseAdapter';
|
|
3
|
-
import { Collection, TypedCollection } from './Collection';
|
|
4
|
-
import { Batch } from './Batch';
|
|
5
|
-
import { DatabaseObject } from './DatabaseObject';
|
|
6
|
-
import { Query } from '../query/Query';
|
|
7
|
-
import { DBSchema as Schema } from '../Schema';
|
|
8
|
-
export declare class Database {
|
|
9
|
-
/**
|
|
10
|
-
* Convenience factory method for getting a Database Object
|
|
11
|
-
*/
|
|
12
|
-
static instance(options: ApiCredentialOptions): Promise<Database>;
|
|
13
|
-
Batch: new () => Batch;
|
|
14
|
-
schema: Schema;
|
|
15
|
-
static getTypedDatabase<T extends {
|
|
16
|
-
[key: string]: {};
|
|
17
|
-
}, U = {
|
|
18
|
-
[K in keyof T]?: TypedCollection<T[K]>;
|
|
19
|
-
}>(schema: Schema, adapter: DatabaseAdapter): Database & U;
|
|
20
|
-
constructor(schema: Schema, adapter: DatabaseAdapter);
|
|
21
|
-
}
|
|
22
|
-
export { Collection, DatabaseObject, Query };
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { SchemaModelType } from '@ja-platform/parser-schema';
|
|
2
|
-
import * as j from '../utils/JourneyPromise';
|
|
3
|
-
import { DatabaseAdapter } from './adapters/DatabaseAdapter';
|
|
4
|
-
export declare class DatabaseObject {
|
|
5
|
-
/**
|
|
6
|
-
* ID of the object, generated when the object is first created.
|
|
7
|
-
*/
|
|
8
|
-
readonly id: string;
|
|
9
|
-
readonly type: SchemaModelType;
|
|
10
|
-
/**
|
|
11
|
-
* true if this object has ben saved to the database.
|
|
12
|
-
*/
|
|
13
|
-
persisted: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Read a field or resolve a relationship.
|
|
16
|
-
*/
|
|
17
|
-
_get: (name: string) => Promise<any>;
|
|
18
|
-
/**
|
|
19
|
-
* Read a field or cached relationship, returning undefined while it loads.
|
|
20
|
-
*/
|
|
21
|
-
_cached: (name: string) => any;
|
|
22
|
-
/**
|
|
23
|
-
* Set a declared field or belongs-to relationship.
|
|
24
|
-
*/
|
|
25
|
-
_set: (name: string, value: any) => void;
|
|
26
|
-
/**
|
|
27
|
-
* Set all values provided in an enumerable object.
|
|
28
|
-
*
|
|
29
|
-
* @param values - the values to set
|
|
30
|
-
*/
|
|
31
|
-
setAll: (values?: any) => void;
|
|
32
|
-
private _reload;
|
|
33
|
-
private _save;
|
|
34
|
-
private _destroy;
|
|
35
|
-
constructor(adapter: DatabaseAdapter, type: SchemaModelType, id: string);
|
|
36
|
-
/**
|
|
37
|
-
* Reload this object from the database.
|
|
38
|
-
*/
|
|
39
|
-
reload(): j.Promise<void>;
|
|
40
|
-
/**
|
|
41
|
-
* Save this object to the database.
|
|
42
|
-
*/
|
|
43
|
-
save(): j.Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* Delete this object from the database.
|
|
46
|
-
*/
|
|
47
|
-
destroy(): j.Promise<void>;
|
|
48
|
-
}
|
|
49
|
-
export type CreateAccessor = (name: string, set: (name: string, value: any) => void, get: (name: string) => any) => void;
|
|
50
|
-
export declare var createAccessor: CreateAccessor;
|
|
51
|
-
export declare function setCreateAccessor(fn: CreateAccessor): void;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import 'isomorphic-fetch';
|
|
2
|
-
import type { RequestInit } from 'node-fetch';
|
|
3
|
-
import { BaseAdapter } from './adapters/BaseAdapter';
|
|
4
|
-
import { SchemaModelType } from '@ja-platform/parser-schema';
|
|
5
|
-
import { Query } from '../query/Query';
|
|
6
|
-
import { ExecuteBatchOperation } from './Batch';
|
|
7
|
-
import { ObjectData } from '../types/ObjectData';
|
|
8
|
-
import { ApiCredentials } from '../credentials';
|
|
9
|
-
import { DBSchema } from '../Schema';
|
|
10
|
-
export type { Response, RequestInit } from 'node-fetch';
|
|
11
|
-
export interface ApiObjectData extends ObjectData {
|
|
12
|
-
_updated_at?: string;
|
|
13
|
-
display?: string;
|
|
14
|
-
}
|
|
15
|
-
export interface ApiAdapterOptions {
|
|
16
|
-
fetch?: RequestInit;
|
|
17
|
-
}
|
|
18
|
-
export declare class JourneyAPIAdapter extends BaseAdapter {
|
|
19
|
-
static apiToInternalFormat(type: SchemaModelType, apiObj: any): ApiObjectData;
|
|
20
|
-
name: string;
|
|
21
|
-
serializeOptions: {
|
|
22
|
-
inlineAttachments: boolean;
|
|
23
|
-
};
|
|
24
|
-
schema: DBSchema;
|
|
25
|
-
options: ApiAdapterOptions;
|
|
26
|
-
credentials: ApiCredentials;
|
|
27
|
-
constructor(credentials: ApiCredentials, schema: DBSchema, options?: ApiAdapterOptions);
|
|
28
|
-
description(): string;
|
|
29
|
-
executeQuery(query: Query): Promise<ObjectData[]>;
|
|
30
|
-
get(type: string, id: string): Promise<ObjectData>;
|
|
31
|
-
getAll(type: string, ids: string[]): Promise<ObjectData[]>;
|
|
32
|
-
private getIdBatch;
|
|
33
|
-
applyBatch(crud: ExecuteBatchOperation[]): Promise<any[]>;
|
|
34
|
-
loadDataModel(): Promise<void>;
|
|
35
|
-
apiGet(url: string): Promise<any>;
|
|
36
|
-
private apiPost;
|
|
37
|
-
/**
|
|
38
|
-
* Post crud actions.
|
|
39
|
-
*
|
|
40
|
-
* @param {*} actions - array of actions
|
|
41
|
-
*/
|
|
42
|
-
private postCrud;
|
|
43
|
-
private doApiQuery;
|
|
44
|
-
private executeQueryGetMore;
|
|
45
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { ReferencePath } from '@ja-platform/parser-expressions';
|
|
2
|
-
import type { SchemaObjectDisplayExpression } from '@ja-platform/parser-schema';
|
|
3
|
-
import { Type } from '@ja-platform/parser-type-system';
|
|
4
|
-
import type { Formatter } from '@ja-platform/parser-type-system';
|
|
5
|
-
export declare class ObjectDisplayScope {
|
|
6
|
-
readonly object: unknown;
|
|
7
|
-
private readonly formatterFor?;
|
|
8
|
-
static getValue(object: unknown, expression: string | ReferencePath, depth?: number): any;
|
|
9
|
-
static getValuePromise(object: unknown, expression: string | ReferencePath, depth?: number): Promise<any>;
|
|
10
|
-
static retrieveValue(object: unknown, expression: string | readonly (string | number)[], depth: number, isPromise: boolean): any;
|
|
11
|
-
static promise(object: unknown, name: string): Promise<unknown>;
|
|
12
|
-
static cached(object: unknown, name: string): unknown;
|
|
13
|
-
constructor(object: unknown, formatterFor?: (type: Type) => Formatter);
|
|
14
|
-
/**
|
|
15
|
-
* Render available fields, returning null while a referenced value is loading.
|
|
16
|
-
*/
|
|
17
|
-
evaluate(expression: SchemaObjectDisplayExpression): string | null;
|
|
18
|
-
getExpressionFormatter(path: ReferencePath): Formatter | null;
|
|
19
|
-
getExpressionType(path: ReferencePath): Type | null;
|
|
20
|
-
getValue(expression: string | ReferencePath): any;
|
|
21
|
-
getValuePromise(expression: string | ReferencePath): Promise<any>;
|
|
22
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ApiAdapterOptions } from './JourneyAPIAdapter';
|
|
2
|
-
import { ApiCredentialOptions } from '../credentials/ApiCredentials';
|
|
3
|
-
import { Database } from './Database';
|
|
4
|
-
export interface OnlineDBCredentials extends ApiCredentialOptions {
|
|
5
|
-
adapter?: ApiAdapterOptions;
|
|
6
|
-
dataModelPath?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function OnlineDB(options: OnlineDBCredentials): Database;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Query } from '../../query/Query';
|
|
2
|
-
import { ObjectData } from '../../types/ObjectData';
|
|
3
|
-
import { ExecuteBatchOperation } from '../Batch';
|
|
4
|
-
import { DatabaseAdapter } from './DatabaseAdapter';
|
|
5
|
-
export declare abstract class BaseAdapter implements DatabaseAdapter {
|
|
6
|
-
static logQuery(...args: any[]): any;
|
|
7
|
-
batchLimit: number;
|
|
8
|
-
closed: boolean;
|
|
9
|
-
adapterName: string;
|
|
10
|
-
promise: Promise<void>;
|
|
11
|
-
name: string;
|
|
12
|
-
protected constructor();
|
|
13
|
-
description(): string;
|
|
14
|
-
open(): Promise<void>;
|
|
15
|
-
abstract get(type: string, id: string): Promise<ObjectData>;
|
|
16
|
-
/**
|
|
17
|
-
* Lookup a an array of IDs. Returns a promise that is resolved with an array of object data.
|
|
18
|
-
*/
|
|
19
|
-
getAll(type: string, ids: string[]): Promise<ObjectData[]>;
|
|
20
|
-
count(query: Query): Promise<number>;
|
|
21
|
-
close(): void;
|
|
22
|
-
ensureOpen(): void;
|
|
23
|
-
explain(query: Query): Promise<any>;
|
|
24
|
-
abstract applyBatch(ops: ExecuteBatchOperation[]): Promise<any[]>;
|
|
25
|
-
abstract executeQuery(query: Query): Promise<ObjectData[]>;
|
|
26
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Type } from '@ja-platform/parser-type-system';
|
|
2
|
-
import { TypeOperations, ValueSerializeOptions } from '../../types/TypeOperations';
|
|
3
|
-
import { Query } from '../../query/Query';
|
|
4
|
-
import { ObjectData } from '../../types/ObjectData';
|
|
5
|
-
import { ExecuteBatchOperation, ExecuteBatchResult } from '../Batch';
|
|
6
|
-
export interface DatabaseAdapter {
|
|
7
|
-
operationsFor?(type: Type): TypeOperations;
|
|
8
|
-
batchLimit: number;
|
|
9
|
-
name: string;
|
|
10
|
-
serializeOptions?: ValueSerializeOptions;
|
|
11
|
-
description(): string;
|
|
12
|
-
applyBatch(ops: ExecuteBatchOperation[]): Promise<ExecuteBatchResult[]>;
|
|
13
|
-
/**
|
|
14
|
-
* Lookup an object. Returns a promise that is resolved with the object data, or null if not found.
|
|
15
|
-
*/
|
|
16
|
-
get(type: string, id: string): Promise<ObjectData>;
|
|
17
|
-
close(): void;
|
|
18
|
-
executeQuery(query: Query): Promise<ObjectData[]>;
|
|
19
|
-
explain(query: Query): Promise<any>;
|
|
20
|
-
count(query: Query): Promise<number>;
|
|
21
|
-
getAll(type: string, ids: string[]): Promise<ObjectData[]>;
|
|
22
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { BaseAdapter } from './BaseAdapter';
|
|
2
|
-
import { Query } from '../../query/Query';
|
|
3
|
-
import { ObjectData } from '../../types/ObjectData';
|
|
4
|
-
import { DatabaseAdapter } from './DatabaseAdapter';
|
|
5
|
-
import { ExecuteBatchOperation } from '../Batch';
|
|
6
|
-
export interface ExplainedResult {
|
|
7
|
-
type: 'index' | 'full scan';
|
|
8
|
-
results: number;
|
|
9
|
-
scanned: number;
|
|
10
|
-
data: ObjectData[];
|
|
11
|
-
duration?: number;
|
|
12
|
-
}
|
|
13
|
-
export declare class WebSQLAdapter extends BaseAdapter implements DatabaseAdapter {
|
|
14
|
-
static adapterName: string;
|
|
15
|
-
static supportsDiagnostics: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Clear the database. Returns a promise that is resolved when the database is cleared.
|
|
18
|
-
*/
|
|
19
|
-
static clear(keepCrud?: boolean): Promise<[unknown, unknown]>;
|
|
20
|
-
private db;
|
|
21
|
-
batchLimit: number;
|
|
22
|
-
constructor(options: any);
|
|
23
|
-
description(): string;
|
|
24
|
-
applyCrud(crud: any[]): Promise<{
|
|
25
|
-
updatedIds: string[];
|
|
26
|
-
}>;
|
|
27
|
-
/**
|
|
28
|
-
* Apply a batch of operations in a single transaction.
|
|
29
|
-
*
|
|
30
|
-
* The entire batch is either successful or not - we don't return errors for
|
|
31
|
-
* individual objects.
|
|
32
|
-
*/
|
|
33
|
-
applyBatch(crud: ExecuteBatchOperation[]): Promise<any[]>;
|
|
34
|
-
/**
|
|
35
|
-
* Perform a query.
|
|
36
|
-
* Returns a promise that is resolved with the resultset.
|
|
37
|
-
*/
|
|
38
|
-
executeQuery(query: Query): Promise<ObjectData[]>;
|
|
39
|
-
explain(query: Query): Promise<ExplainedResult>;
|
|
40
|
-
executeTableScan(query: Query): Promise<ExplainedResult>;
|
|
41
|
-
get(type: string, id: string): Promise<ObjectData>;
|
|
42
|
-
getAll(type: string, ids: string[]): Promise<ObjectData[]>;
|
|
43
|
-
estimateBytesUsed(): Promise<number>;
|
|
44
|
-
openDatabase(name: string): any;
|
|
45
|
-
private promisedTransaction;
|
|
46
|
-
private simpleQuery;
|
|
47
|
-
private transactionSaveData;
|
|
48
|
-
private transactionDestroy;
|
|
49
|
-
private logError;
|
|
50
|
-
}
|
package/dist/@types/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { DatabaseAdapter } from '../database/adapters/DatabaseAdapter';
|
|
2
|
-
import { Query } from './Query';
|
|
3
|
-
import { Expression } from './queryOperations';
|
|
4
|
-
import { DatabaseObject } from '../database/DatabaseObject';
|
|
5
|
-
import { ObjectData } from '../types/ObjectData';
|
|
6
|
-
import { SchemaModelType } from '@ja-platform/parser-schema';
|
|
7
|
-
export interface InternalQuery<T extends DatabaseObject = DatabaseObject> extends Query<T> {
|
|
8
|
-
readonly adapter: DatabaseAdapter;
|
|
9
|
-
readonly type: SchemaModelType;
|
|
10
|
-
expression: Expression;
|
|
11
|
-
ordering: any[];
|
|
12
|
-
limitNumber: number;
|
|
13
|
-
skipNumber: number;
|
|
14
|
-
_fetch(): Promise<T[]>;
|
|
15
|
-
_filter(data: ObjectData[]): ObjectData[];
|
|
16
|
-
_sort(data: ObjectData[]): ObjectData[];
|
|
17
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { RelationshipHash } from './getPreloadRelationships';
|
|
2
|
-
import { DatabaseAdapter } from '../database/adapters/DatabaseAdapter';
|
|
3
|
-
import { Expression } from './queryOperations';
|
|
4
|
-
import { DatabaseObject } from '../database/DatabaseObject';
|
|
5
|
-
import { FormatStringExpression } from '@ja-platform/parser-expressions';
|
|
6
|
-
import * as j from '../utils/JourneyPromise';
|
|
7
|
-
import { SchemaModelType } from '@ja-platform/parser-schema';
|
|
8
|
-
export declare class Query<T extends DatabaseObject = DatabaseObject> {
|
|
9
|
-
readonly type: SchemaModelType;
|
|
10
|
-
static isQuery(value: any): boolean;
|
|
11
|
-
constructor(adapter: DatabaseAdapter, type: SchemaModelType, expression?: Expression, ordering?: any[]);
|
|
12
|
-
private _reload;
|
|
13
|
-
private _explain;
|
|
14
|
-
_fetchWithDisplay(columns?: FormatStringExpression[] | Record<string, FormatStringExpression>): Promise<T[]>;
|
|
15
|
-
/**
|
|
16
|
-
* Apply additional query filters, as a new query.
|
|
17
|
-
*
|
|
18
|
-
* @param query the query string
|
|
19
|
-
* @param args query arguments
|
|
20
|
-
*/
|
|
21
|
-
where(query: string, ...args: any[]): Query<T>;
|
|
22
|
-
/**
|
|
23
|
-
* Apply additional filters, as a new query.
|
|
24
|
-
*
|
|
25
|
-
* @param filters an object of {field: value}
|
|
26
|
-
*/
|
|
27
|
-
where(filters?: any): Query<T>;
|
|
28
|
-
/**
|
|
29
|
-
* Return a copy of this query.
|
|
30
|
-
*/
|
|
31
|
-
where(): Query<T>;
|
|
32
|
-
private order_by;
|
|
33
|
-
/**
|
|
34
|
-
* Limit the maximum number of results returned by the query.
|
|
35
|
-
*
|
|
36
|
-
* A new query is returned - the original one is not modified.
|
|
37
|
-
*
|
|
38
|
-
* @param n maximum number of results
|
|
39
|
-
*/
|
|
40
|
-
limit(n: number): Query<T>;
|
|
41
|
-
/**
|
|
42
|
-
* Skip the first n results in the query. Typically used together with limit() for pagination.
|
|
43
|
-
*
|
|
44
|
-
* A new query is returned - the original one is not modified.
|
|
45
|
-
*
|
|
46
|
-
* @param n number of results to skip.
|
|
47
|
-
*/
|
|
48
|
-
skip(n: number): Query<T>;
|
|
49
|
-
/**
|
|
50
|
-
* Pre-load belongs-to relationships when executing the query.
|
|
51
|
-
*
|
|
52
|
-
* This allows the implementation to batch the lookups, which is faster than loading each related
|
|
53
|
-
* object individually.
|
|
54
|
-
*
|
|
55
|
-
* Nested belongs-to relationships are supported by using dots, e.g. `.include('owner.region')`.
|
|
56
|
-
*
|
|
57
|
-
* A new query is returned - the original one is not modified.
|
|
58
|
-
*
|
|
59
|
-
* @param relationships belongs-to names
|
|
60
|
-
*/
|
|
61
|
-
include(...relationships: string[]): Query<T>;
|
|
62
|
-
private _destroy_all;
|
|
63
|
-
private _count;
|
|
64
|
-
/**
|
|
65
|
-
* Execute the query and return the results.
|
|
66
|
-
*/
|
|
67
|
-
toArray(): j.Promise<T[]>;
|
|
68
|
-
/**
|
|
69
|
-
* Apply additional filters, then return the first result.
|
|
70
|
-
*
|
|
71
|
-
* @param filters an object of {attribute: value}
|
|
72
|
-
*/
|
|
73
|
-
first(filters?: {
|
|
74
|
-
[key: string]: any;
|
|
75
|
-
}): j.Promise<T | null>;
|
|
76
|
-
/**
|
|
77
|
-
* Apply additional query filters, then return the first result.
|
|
78
|
-
*
|
|
79
|
-
* Same as .where(...).first().
|
|
80
|
-
*
|
|
81
|
-
* @param query the query string
|
|
82
|
-
* @param args query arguments
|
|
83
|
-
*/
|
|
84
|
-
first(query: string, ...args: any[]): j.Promise<T | null>;
|
|
85
|
-
/**
|
|
86
|
-
* Return the first result matched by this query.
|
|
87
|
-
*/
|
|
88
|
-
first(): j.Promise<T | null>;
|
|
89
|
-
/**
|
|
90
|
-
* Return the number of results matched by the query.
|
|
91
|
-
*
|
|
92
|
-
* If .limit() was used, it would be respected for the count.
|
|
93
|
-
*/
|
|
94
|
-
count(): j.Promise<number>;
|
|
95
|
-
/**
|
|
96
|
-
* Return executions stats for the query.
|
|
97
|
-
*
|
|
98
|
-
* The format of the results is not fixed, and may change across versions.
|
|
99
|
-
* For debugging use only.
|
|
100
|
-
*/
|
|
101
|
-
explain(): j.Promise<any>;
|
|
102
|
-
/**
|
|
103
|
-
* Destroy all objects matched by this query.
|
|
104
|
-
*
|
|
105
|
-
* skip() and limit() is respected for this.
|
|
106
|
-
*/
|
|
107
|
-
destroyAll(): j.Promise<void>;
|
|
108
|
-
private _toArray;
|
|
109
|
-
private _first;
|
|
110
|
-
private _destroyAll;
|
|
111
|
-
/**
|
|
112
|
-
* Order by one or more attributes.
|
|
113
|
-
*
|
|
114
|
-
* A new query is returned - the original one is not modified.
|
|
115
|
-
*
|
|
116
|
-
* @param fields an array of field names to order by. Prefix with - for descending, e.g. `-updated_at`.
|
|
117
|
-
*/
|
|
118
|
-
orderBy(...fields: string[]): Query<T>;
|
|
119
|
-
/**
|
|
120
|
-
* For debugging purposes only.
|
|
121
|
-
*
|
|
122
|
-
* The format of the result is not defined.
|
|
123
|
-
*/
|
|
124
|
-
toJSON(): {
|
|
125
|
-
type: string;
|
|
126
|
-
expression: Expression;
|
|
127
|
-
ordering: any[];
|
|
128
|
-
limit: number;
|
|
129
|
-
skip: number;
|
|
130
|
-
include: RelationshipHash;
|
|
131
|
-
};
|
|
132
|
-
private _includeInternal;
|
|
133
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AbstractFormatExpression } from '@ja-platform/parser-expressions';
|
|
2
|
-
import { SchemaModelType } from '@ja-platform/parser-schema';
|
|
3
|
-
export interface RelationshipHash {
|
|
4
|
-
[key: string]: RelationshipHash;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Collect relationships needed by query displays, including related models' displays.
|
|
8
|
-
*/
|
|
9
|
-
export declare function getPreloadRelationships(type: SchemaModelType, columns?: AbstractFormatExpression<any>[] | Record<string, AbstractFormatExpression<any>>): RelationshipHash;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { SchemaModelType, Field } from '@ja-platform/parser-schema';
|
|
2
|
-
import { ObjectData } from '../types/ObjectData';
|
|
3
|
-
export declare function expressionFromHash(scopeType: SchemaModelType, hash: any): Expression;
|
|
4
|
-
export interface Expression {
|
|
5
|
-
normalize(): NormalizedExpression;
|
|
6
|
-
evaluate(object: Partial<ObjectData>): boolean;
|
|
7
|
-
toOriginalExpression(): any[];
|
|
8
|
-
}
|
|
9
|
-
export declare class Operation implements Expression {
|
|
10
|
-
attribute: Field;
|
|
11
|
-
operator: string;
|
|
12
|
-
value: any;
|
|
13
|
-
constructor(attribute: Field, operator: string, value: any);
|
|
14
|
-
normalize(): NormalizedExpression;
|
|
15
|
-
attributes(): Field<import("@ja-platform/parser-type-system").Type<any>>[];
|
|
16
|
-
evaluate(object: Partial<ObjectData>): boolean;
|
|
17
|
-
toString(): string;
|
|
18
|
-
toOriginalExpression(): any[];
|
|
19
|
-
}
|
|
20
|
-
export declare class RelationMatch implements Expression {
|
|
21
|
-
name: string;
|
|
22
|
-
id: string;
|
|
23
|
-
constructor(name: string, id: string);
|
|
24
|
-
normalize(): OrExpression<AndExpression>;
|
|
25
|
-
evaluate(object: Partial<ObjectData>): boolean;
|
|
26
|
-
toString(): string;
|
|
27
|
-
toOriginalExpression(): string[];
|
|
28
|
-
}
|
|
29
|
-
export declare class AndExpression implements Expression {
|
|
30
|
-
operands: Expression[];
|
|
31
|
-
constructor(operands: Expression[]);
|
|
32
|
-
join(otherAnd: AndExpression): AndExpression;
|
|
33
|
-
normalize(): any;
|
|
34
|
-
evaluate(object: Partial<ObjectData>): boolean;
|
|
35
|
-
toString(): string;
|
|
36
|
-
toOriginalExpression(): any[];
|
|
37
|
-
}
|
|
38
|
-
export declare class OrExpression<T extends Expression = Expression> implements Expression {
|
|
39
|
-
operands: T[];
|
|
40
|
-
constructor(operands: T[]);
|
|
41
|
-
normalize(): OrExpression<AndExpression>;
|
|
42
|
-
evaluate(object: Partial<ObjectData>): boolean;
|
|
43
|
-
toString(): string;
|
|
44
|
-
toOriginalExpression(): any[];
|
|
45
|
-
}
|
|
46
|
-
export type NormalizedExpression = OrExpression<AndExpression>;
|
|
47
|
-
export declare class TrueExpression implements Expression {
|
|
48
|
-
constructor();
|
|
49
|
-
normalize(): OrExpression<AndExpression>;
|
|
50
|
-
evaluate(object: ObjectData): boolean;
|
|
51
|
-
toString(): string;
|
|
52
|
-
toOriginalExpression(): string[];
|
|
53
|
-
}
|
|
54
|
-
export declare class Tokenizer {
|
|
55
|
-
expression: string;
|
|
56
|
-
i: number;
|
|
57
|
-
previousPosition: number;
|
|
58
|
-
private interpolatorCount;
|
|
59
|
-
constructor(expression: string);
|
|
60
|
-
exception(message: string, start?: number, end?: number): Error;
|
|
61
|
-
isWordSeparator(p: number): boolean;
|
|
62
|
-
isWord(): boolean;
|
|
63
|
-
hasMore(): boolean;
|
|
64
|
-
readOperator(): string;
|
|
65
|
-
readBooleanLogic(): string;
|
|
66
|
-
isOr(): boolean;
|
|
67
|
-
isAnd(): boolean;
|
|
68
|
-
isParenthesis(): boolean;
|
|
69
|
-
readParenthesis(): string;
|
|
70
|
-
readInterpolator(): number;
|
|
71
|
-
readWord(): string;
|
|
72
|
-
private advance;
|
|
73
|
-
private checkBuffer;
|
|
74
|
-
private readToken;
|
|
75
|
-
private isToken;
|
|
76
|
-
}
|
|
77
|
-
export declare class Parser {
|
|
78
|
-
private scopeType;
|
|
79
|
-
private tokenizer;
|
|
80
|
-
private args;
|
|
81
|
-
constructor(scopeType: SchemaModelType, tokenizer: Tokenizer, args: any[]);
|
|
82
|
-
parse(): Expression;
|
|
83
|
-
private parseOrExpression;
|
|
84
|
-
private parseAndExpression;
|
|
85
|
-
private parseTerm;
|
|
86
|
-
}
|
|
87
|
-
export declare function parse(scopeType: SchemaModelType, expression: string, args: any[]): Expression;
|