@vsaas/loopback-datasource-juggler 10.0.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 (63) hide show
  1. package/LICENSE +25 -0
  2. package/NOTICE +23 -0
  3. package/README.md +74 -0
  4. package/dist/_virtual/_rolldown/runtime.js +4 -0
  5. package/dist/index.js +26 -0
  6. package/dist/lib/browser.depd.js +13 -0
  7. package/dist/lib/case-utils.js +21 -0
  8. package/dist/lib/connectors/kv-memory.js +158 -0
  9. package/dist/lib/connectors/memory.js +810 -0
  10. package/dist/lib/connectors/transient.js +126 -0
  11. package/dist/lib/dao.js +2445 -0
  12. package/dist/lib/datasource.js +2215 -0
  13. package/dist/lib/date-string.js +87 -0
  14. package/dist/lib/geo.js +244 -0
  15. package/dist/lib/globalize.js +33 -0
  16. package/dist/lib/hooks.js +79 -0
  17. package/dist/lib/id-utils.js +66 -0
  18. package/dist/lib/include.js +795 -0
  19. package/dist/lib/include_utils.js +104 -0
  20. package/dist/lib/introspection.js +37 -0
  21. package/dist/lib/jutil.js +65 -0
  22. package/dist/lib/kvao/delete-all.js +57 -0
  23. package/dist/lib/kvao/delete.js +43 -0
  24. package/dist/lib/kvao/expire.js +35 -0
  25. package/dist/lib/kvao/get.js +34 -0
  26. package/dist/lib/kvao/index.js +28 -0
  27. package/dist/lib/kvao/iterate-keys.js +38 -0
  28. package/dist/lib/kvao/keys.js +55 -0
  29. package/dist/lib/kvao/set.js +39 -0
  30. package/dist/lib/kvao/ttl.js +35 -0
  31. package/dist/lib/list.js +101 -0
  32. package/dist/lib/mixins.js +58 -0
  33. package/dist/lib/model-builder.js +608 -0
  34. package/dist/lib/model-definition.js +231 -0
  35. package/dist/lib/model-utils.js +368 -0
  36. package/dist/lib/model.js +586 -0
  37. package/dist/lib/observer.js +235 -0
  38. package/dist/lib/relation-definition.js +2604 -0
  39. package/dist/lib/relations.js +587 -0
  40. package/dist/lib/scope.js +392 -0
  41. package/dist/lib/transaction.js +183 -0
  42. package/dist/lib/types.js +58 -0
  43. package/dist/lib/utils.js +625 -0
  44. package/dist/lib/validations.js +742 -0
  45. package/dist/package.js +93 -0
  46. package/package.json +85 -0
  47. package/types/common.d.ts +28 -0
  48. package/types/connector.d.ts +52 -0
  49. package/types/datasource.d.ts +324 -0
  50. package/types/date-string.d.ts +21 -0
  51. package/types/inclusion-mixin.d.ts +44 -0
  52. package/types/index.d.ts +36 -0
  53. package/types/kv-model.d.ts +201 -0
  54. package/types/model.d.ts +368 -0
  55. package/types/observer-mixin.d.ts +174 -0
  56. package/types/persisted-model.d.ts +505 -0
  57. package/types/query.d.ts +108 -0
  58. package/types/relation-mixin.d.ts +577 -0
  59. package/types/relation.d.ts +301 -0
  60. package/types/scope.d.ts +92 -0
  61. package/types/transaction-mixin.d.ts +47 -0
  62. package/types/types.d.ts +65 -0
  63. package/types/validation-mixin.d.ts +287 -0
@@ -0,0 +1,93 @@
1
+ //#region package.json
2
+ var require_package = /* @__PURE__ */ require("./_virtual/_rolldown/runtime.js").__commonJSMin(((exports, module) => {
3
+ module.exports = {
4
+ "name": "@vsaas/loopback-datasource-juggler",
5
+ "version": "10.0.0",
6
+ "description": "Fork of loopback-datasource-juggler for LoopBack 3 style applications",
7
+ "keywords": [
8
+ "Connector",
9
+ "DataSource",
10
+ "Database",
11
+ "Juggler",
12
+ "LoopBack",
13
+ "ORM",
14
+ "StrongLoop"
15
+ ],
16
+ "license": "MIT",
17
+ "author": "Xompass",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/xompass/loopback-datasource-juggler"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "connectors/*.js",
25
+ "types/**/*.d.ts",
26
+ "README.md",
27
+ "LICENSE",
28
+ "NOTICE"
29
+ ],
30
+ "main": "dist/index.js",
31
+ "browser": { "depd": "./dist/lib/browser.depd.js" },
32
+ "types": "types/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./types/index.d.ts",
36
+ "require": "./dist/index.js",
37
+ "default": "./dist/index.js"
38
+ },
39
+ "./browser.depd": {
40
+ "require": "./dist/lib/browser.depd.js",
41
+ "default": "./dist/lib/browser.depd.js"
42
+ },
43
+ "./*": {
44
+ "require": "./dist/lib/*.js",
45
+ "default": "./dist/lib/*.js"
46
+ },
47
+ "./package.json": "./package.json"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public",
51
+ "registry": "https://registry.npmjs.org/"
52
+ },
53
+ "scripts": {
54
+ "build": "tsdown",
55
+ "fmt": "oxfmt -c ../.oxfmtrc.json .",
56
+ "lint": "oxlint -c ../.oxlintrc.json src",
57
+ "lint:fix": "oxlint -c ../.oxlintrc.json src --fix",
58
+ "prepack": "pnpm run build",
59
+ "prepublishOnly": "pnpm run typecheck && pnpm run lint && pnpm test",
60
+ "test:run": "vitest run",
61
+ "test": "pnpm run build && vitest run",
62
+ "typecheck": "tsc --noEmit -p tsconfig.json"
63
+ },
64
+ "dependencies": {
65
+ "@vsaas/loopback-connector": "workspace:^",
66
+ "debug": "^4.4.3",
67
+ "depd": "^2.0.0",
68
+ "inflection": "^3.0.2",
69
+ "minimatch": "10.2.4",
70
+ "neotraverse": "^0.6.18",
71
+ "qs": "^6.15.0"
72
+ },
73
+ "devDependencies": {
74
+ "@types/node": "catalog:",
75
+ "bson": "^4.7.2",
76
+ "loopback-connector-throwing": "workspace:*",
77
+ "oxfmt": "catalog:",
78
+ "oxlint": "catalog:",
79
+ "should": "^13.2.3",
80
+ "tsdown": "catalog:",
81
+ "typescript": "catalog:",
82
+ "vitest": "catalog:"
83
+ },
84
+ "engines": { "node": ">=20" }
85
+ };
86
+ }));
87
+ //#endregion
88
+ Object.defineProperty(exports, "default", {
89
+ enumerable: true,
90
+ get: function() {
91
+ return require_package();
92
+ }
93
+ });
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "@vsaas/loopback-datasource-juggler",
3
+ "version": "10.0.0",
4
+ "description": "Fork of loopback-datasource-juggler for LoopBack 3 style applications",
5
+ "keywords": [
6
+ "Connector",
7
+ "DataSource",
8
+ "Database",
9
+ "Juggler",
10
+ "LoopBack",
11
+ "ORM",
12
+ "StrongLoop"
13
+ ],
14
+ "license": "MIT",
15
+ "author": "Xompass",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/xompass/loopback-datasource-juggler"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "connectors/*.js",
23
+ "types/**/*.d.ts",
24
+ "README.md",
25
+ "LICENSE",
26
+ "NOTICE"
27
+ ],
28
+ "main": "dist/index.js",
29
+ "browser": {
30
+ "depd": "./dist/lib/browser.depd.js"
31
+ },
32
+ "types": "types/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./types/index.d.ts",
36
+ "require": "./dist/index.js",
37
+ "default": "./dist/index.js"
38
+ },
39
+ "./browser.depd": {
40
+ "require": "./dist/lib/browser.depd.js",
41
+ "default": "./dist/lib/browser.depd.js"
42
+ },
43
+ "./*": {
44
+ "require": "./dist/lib/*.js",
45
+ "default": "./dist/lib/*.js"
46
+ },
47
+ "./package.json": "./package.json"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public",
51
+ "registry": "https://registry.npmjs.org/"
52
+ },
53
+ "dependencies": {
54
+ "debug": "^4.4.3",
55
+ "depd": "^2.0.0",
56
+ "inflection": "^3.0.2",
57
+ "minimatch": "10.2.4",
58
+ "neotraverse": "^0.6.18",
59
+ "qs": "^6.15.0",
60
+ "@vsaas/loopback-connector": "^10.0.0"
61
+ },
62
+ "devDependencies": {
63
+ "@types/node": "25.5.0",
64
+ "bson": "^4.7.2",
65
+ "oxfmt": "0.42.0",
66
+ "oxlint": "1.57.0",
67
+ "should": "^13.2.3",
68
+ "tsdown": "0.21.5",
69
+ "typescript": "6.0.2",
70
+ "vitest": "4.1.1",
71
+ "loopback-connector-throwing": "1.0.0"
72
+ },
73
+ "engines": {
74
+ "node": ">=20"
75
+ },
76
+ "scripts": {
77
+ "build": "tsdown",
78
+ "fmt": "oxfmt -c ../.oxfmtrc.json .",
79
+ "lint": "oxlint -c ../.oxlintrc.json src",
80
+ "lint:fix": "oxlint -c ../.oxlintrc.json src --fix",
81
+ "test:run": "vitest run",
82
+ "test": "pnpm run build && vitest run",
83
+ "typecheck": "tsc --noEmit -p tsconfig.json"
84
+ }
85
+ }
@@ -0,0 +1,28 @@
1
+ // Copyright IBM Corp. 2018,2019. All Rights Reserved.
2
+ // Node module: loopback-datasource-juggler
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ /**
7
+ * Objects with open properties
8
+ */
9
+ export interface AnyObject<T = any> {
10
+ [property: string]: T;
11
+ }
12
+
13
+ /**
14
+ * Type alias for options object
15
+ */
16
+ export type Options = AnyObject<any>;
17
+
18
+ /**
19
+ * Type alias for Node.js callback functions
20
+ */
21
+ export type Callback<T = any> = (err?: any | null, result?: T) => void;
22
+
23
+ /**
24
+ * Return export type for promisified Node.js async methods.
25
+ *
26
+ * Note that starting with version 4.0, juggler uses native Promises.
27
+ */
28
+ export type PromiseOrVoid<T = any> = Promise<T> | void;
@@ -0,0 +1,52 @@
1
+ // Copyright IBM Corp. 2018,2019. All Rights Reserved.
2
+ // Node module: loopback-datasource-juggler
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import { Callback, DataSource, Options, PromiseOrVoid } from '..';
7
+
8
+ // Copyright IBM Corp. 2018. All Rights Reserved.
9
+ // Node module: loopback-datasource-juggler
10
+ // This file is licensed under the MIT License.
11
+ // License text available at https://opensource.org/licenses/MIT
12
+
13
+ /**
14
+ * Connector from `loopback-connector` module
15
+ */
16
+ export interface Connector {
17
+ name: string; // Name/type of the connector
18
+ dataSource?: DataSource;
19
+ connect(callback?: Callback): PromiseOrVoid; // Connect to the underlying system
20
+ disconnect(callback?: Callback): PromiseOrVoid; // Disconnect from the underlying system
21
+ ping(callback?: Callback): PromiseOrVoid; // Ping the underlying system
22
+ execute?(...args: any[]): Promise<any>;
23
+ [property: string]: any; // Other properties that vary by connectors
24
+ }
25
+
26
+ /**
27
+ * Base connector class
28
+ */
29
+ export declare class ConnectorBase implements Connector {
30
+ name: string; // Name/type of the connector;
31
+ dataSource?: DataSource;
32
+ connect(callback?: Callback): PromiseOrVoid; // Connect to the underlying system
33
+ disconnect(callback?: Callback): PromiseOrVoid; // Disconnect from the underlying system
34
+ ping(callback?: Callback): PromiseOrVoid; // Ping the underlying system
35
+ execute?(...args: any[]): Promise<any>;
36
+
37
+ /**
38
+ * Initialize the connector against the given data source
39
+ *
40
+ * @param {DataSource} dataSource The dataSource
41
+ * @param {Function} [callback] The callback function
42
+ */
43
+ static initialize(dataSource: DataSource, callback?: Callback): void;
44
+
45
+ constructor(settings?: Options);
46
+ }
47
+
48
+ export declare class Memory extends ConnectorBase {}
49
+
50
+ export declare class KeyValueMemoryConnector extends ConnectorBase {}
51
+
52
+ export declare class Transient extends ConnectorBase {}
@@ -0,0 +1,324 @@
1
+ // Copyright IBM Corp. 2018,2019. All Rights Reserved.
2
+ // Node module: loopback-datasource-juggler
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import { AnyObject, Callback, Options } from './common';
7
+ import { Connector } from './connector';
8
+ import { ModelBaseClass, ModelBuilder, ModelDefinition, PropertyDefinition } from './model';
9
+ import { EventEmitter } from 'events';
10
+ import { IsolationLevel, Transaction } from './transaction-mixin';
11
+
12
+ /**
13
+ * LoopBack models can manipulate data via the DataSource object.
14
+ * Attaching a `DataSource` to a `Model` adds instance methods and static methods to the `Model`.
15
+ *
16
+ * Define a data source to persist model data.
17
+ * To create a DataSource programmatically, call `createDataSource()` on the LoopBack object; for example:
18
+ * ```js
19
+ * var oracle = loopback.createDataSource({
20
+ * connector: 'oracle',
21
+ * host: '111.22.333.44',
22
+ * database: 'MYDB',
23
+ * username: 'username',
24
+ * password: 'password'
25
+ * });
26
+ * ```
27
+ *
28
+ * All classes in single dataSource share same the connector type and
29
+ * one database connection.
30
+ *
31
+ * For example, the following creates a DataSource, and waits for a connection callback.
32
+ *
33
+ * ```
34
+ * var dataSource = new DataSource('mysql', { database: 'myapp_test' });
35
+ * dataSource.define(...);
36
+ * dataSource.on('connected', function () {
37
+ * // work with database
38
+ * });
39
+ * ```
40
+ * @class DataSource
41
+ * @param {String} [name] Optional name for datasource.
42
+ * @options {Object} settings Database-specific settings to establish connection (settings depend on specific connector).
43
+ * The table below lists a typical set for a relational database.
44
+ * @property {String} connector Database connector to use. For any supported connector, can be any of:
45
+ *
46
+ * - The connector module from `require(connectorName)`.
47
+ * - The full name of the connector module, such as 'loopback-connector-oracle'.
48
+ * - The short name of the connector module, such as 'oracle'.
49
+ * - A local module under `./connectors/` folder.
50
+ * @property {String} host Database server host name.
51
+ * @property {String} port Database server port number.
52
+ * @property {String} username Database user name.
53
+ * @property {String} password Database password.
54
+ * @property {String} database Name of the database to use.
55
+ * @property {Boolean} debug Display debugging information. Default is false.
56
+ *
57
+ * The constructor allows the following styles:
58
+ *
59
+ * 1. new DataSource(dataSourceName, settings). For example:
60
+ * - new DataSource('myDataSource', {connector: 'memory'});
61
+ * - new DataSource('myDataSource', {name: 'myDataSource', connector: 'memory'});
62
+ * - new DataSource('myDataSource', {name: 'anotherDataSource', connector: 'memory'});
63
+ *
64
+ * 2. new DataSource(settings). For example:
65
+ * - new DataSource({name: 'myDataSource', connector: 'memory'});
66
+ * - new DataSource({connector: 'memory'});
67
+ *
68
+ * 3. new DataSource(connectorModule, settings). For example:
69
+ * - new DataSource(connectorModule, {name: 'myDataSource})
70
+ * - new DataSource(connectorModule)
71
+ */
72
+ export declare class DataSource extends EventEmitter {
73
+ name: string;
74
+ settings: Options;
75
+
76
+ initialized?: boolean;
77
+ connected?: boolean;
78
+ connecting?: boolean;
79
+
80
+ connector?: Connector;
81
+
82
+ definitions: { [modelName: string]: ModelDefinition };
83
+
84
+ DataAccessObject: AnyObject & { prototype: AnyObject };
85
+
86
+ constructor(name: string, settings?: Options, modelBuilder?: ModelBuilder);
87
+
88
+ constructor(settings?: Options, modelBuilder?: ModelBuilder);
89
+
90
+ constructor(connectorModule: Connector, settings?: Options, modelBuilder?: ModelBuilder);
91
+
92
+ /**
93
+ * Create a model class
94
+ * @param name Name of the model
95
+ * @param properties An object of property definitions
96
+ * @param options Options for model settings
97
+ */
98
+ createModel<T extends ModelBaseClass>(name: string, properties?: AnyObject, options?: Options): T;
99
+
100
+ /**
101
+ * Look up a model class by name
102
+ * @param modelName Model name
103
+ * @param forceCreate A flag to force creation of a model if not found
104
+ */
105
+ getModel(modelName: string, forceCreate?: boolean): ModelBaseClass | undefined;
106
+
107
+ /**
108
+ * Remove a model from the registry.
109
+ *
110
+ * @param modelName
111
+ */
112
+ deleteModelByName(modelName: string): void;
113
+
114
+ /**
115
+ * Remove all models from the registry, but keep the connector instance
116
+ * (including the pool of database connections).
117
+ */
118
+ deleteAllModels(): void;
119
+
120
+ /**
121
+ * Attach an existing model to a data source.
122
+ * This will mixin all of the data access object functions (DAO) into your
123
+ * modelClass definition.
124
+ * @param {ModelBaseClass} modelClass The model constructor that will be enhanced
125
+ * by DataAccessObject mixins.
126
+ */
127
+ attach(modelClass: ModelBaseClass): ModelBaseClass;
128
+
129
+ automigrate(models?: string | string[]): Promise<void>;
130
+ // legacy callback style
131
+ automigrate(models: string | string[] | undefined, callback: Callback): void;
132
+
133
+ autoupdate(models?: string | string[]): Promise<void>;
134
+ // legacy callback style
135
+ autoupdate(models: string | string[] | undefined, callback: Callback): void;
136
+
137
+ discoverModelDefinitions(options?: Options): Promise<ModelDefinition[]>;
138
+ // legacy callback style (no options)
139
+ discoverModelDefinitions(callback: Callback<ModelDefinition[]>): void;
140
+ // legacy callback style (with options)
141
+ discoverModelDefinitions(options: Options, callback: Callback<ModelDefinition[]>): void;
142
+
143
+ discoverModelProperties(modelName: string, options?: Options): Promise<PropertyDefinition[]>;
144
+ // legacy callback style (no options)
145
+ discoverModelProperties(modelName: string, callback: Callback<PropertyDefinition[]>): void;
146
+ // legacy callback style (with options)
147
+ discoverModelProperties(
148
+ modelName: string,
149
+ options: Options,
150
+ callback: Callback<PropertyDefinition[]>,
151
+ ): void;
152
+
153
+ discoverPrimaryKeys(modelName: string, options?: Options): Promise<PropertyDefinition[]>;
154
+ // legacy callback style (no options)
155
+ discoverPrimaryKeys(modelName: string, callback: Callback<PropertyDefinition[]>): void;
156
+ // legacy callback style (with options)
157
+ discoverPrimaryKeys(
158
+ modelName: string,
159
+ options: Options,
160
+ callback: Callback<PropertyDefinition[]>,
161
+ ): void;
162
+
163
+ discoverForeignKeys(modelName: string, options?: Options): Promise<PropertyDefinition[]>;
164
+ // legacy callback style (no options)
165
+ discoverForeignKeys(modelName: string, callback: Callback<PropertyDefinition[]>): void;
166
+ // legacy callback style (with options)
167
+ discoverForeignKeys(
168
+ modelName: string,
169
+ options: Options,
170
+ callback: Callback<PropertyDefinition[]>,
171
+ ): void;
172
+
173
+ discoverExportedForeignKeys(modelName: string, options?: Options): Promise<PropertyDefinition[]>;
174
+ // legacy callback style (no options)
175
+ discoverExportedForeignKeys(modelName: string, callback: Callback<PropertyDefinition[]>): void;
176
+ // legacy callback style (with options)
177
+ discoverExportedForeignKeys(
178
+ modelName: string,
179
+ options: Options,
180
+ callback: Callback<PropertyDefinition[]>,
181
+ ): void;
182
+
183
+ discoverAndBuildModels(
184
+ modelName: string,
185
+ options?: Options,
186
+ ): Promise<{ [name: string]: ModelBaseClass }>;
187
+ // legacy callback style (no options)
188
+ discoverAndBuildModels(
189
+ modelName: string,
190
+ callback: Callback<{ [name: string]: ModelBaseClass }>,
191
+ ): void;
192
+ // legacy callback style (with options)
193
+ discoverAndBuildModels(
194
+ modelName: string,
195
+ options: Options,
196
+ callback: Callback<{ [name: string]: ModelBaseClass }>,
197
+ ): void;
198
+
199
+ discoverSchema(tableName: string, options?: Options): Promise<AnyObject>;
200
+ // legacy callback style (no options)
201
+ discoverSchema(tableName: string, callback: Callback<AnyObject>): void;
202
+ // legacy callback style (with options)
203
+ discoverSchema(tableName: string, options: Options, callback: Callback<AnyObject>): void;
204
+
205
+ discoverSchemas(tableName: string, options?: Options): Promise<AnyObject[]>;
206
+ // legacy callback style (no options)
207
+ discoverSchemas(tableName: string, callback: Callback<AnyObject[]>): void;
208
+ // legacy callback style (with options)
209
+ discoverSchemas(tableName: string, options: Options, callback: Callback<AnyObject[]>): void;
210
+
211
+ buildModelFromInstance(
212
+ modelName: string,
213
+ jsonObject: AnyObject,
214
+ options?: Options,
215
+ ): ModelBaseClass;
216
+
217
+ connect(): Promise<void>;
218
+ // legacy callback style
219
+ connect(callback: Callback): void;
220
+
221
+ disconnect(): Promise<void>;
222
+ // legacy callback style
223
+ disconnect(callback: Callback): void;
224
+
225
+ // Only promise variant, callback is intentionally not described.
226
+ // Note we must use `void | PromiseLike<void>` to avoid breaking
227
+ // existing LoopBack 4 applications.
228
+ // TODO(semver-major): change the return type to `Promise<void>`
229
+ stop(): void | PromiseLike<void>;
230
+
231
+ ping(): Promise<void>;
232
+ // legacy callback style
233
+ ping(callback: Callback): void;
234
+
235
+ // Only promise variant, callback is intentionally not supported.
236
+
237
+ /**
238
+ * Execute a SQL command.
239
+ *
240
+ * **WARNING:** In general, it is always better to perform database actions
241
+ * through repository methods. Directly executing SQL may lead to unexpected
242
+ * results, corrupted data, security vulnerabilities and other issues.
243
+ *
244
+ * @example
245
+ *
246
+ * ```ts
247
+ * // MySQL
248
+ * const result = await db.execute(
249
+ * 'SELECT * FROM Products WHERE size > ?',
250
+ * [42]
251
+ * );
252
+ *
253
+ * // PostgreSQL
254
+ * const result = await db.execute(
255
+ * 'SELECT * FROM Products WHERE size > $1',
256
+ * [42]
257
+ * );
258
+ * ```
259
+ *
260
+ * @param command A parameterized SQL command or query.
261
+ * Check your database documentation for information on which characters to
262
+ * use as parameter placeholders.
263
+ * @param parameters List of parameter values to use.
264
+ * @param options Additional options, for example `transaction`.
265
+ * @returns A promise which resolves to the command output as returned by the
266
+ * database driver. The output type (data structure) is database specific and
267
+ * often depends on the command executed.
268
+ */
269
+ execute(command: string | object, parameters?: any[] | object, options?: Options): Promise<any>;
270
+
271
+ /**
272
+ * Execute a MongoDB command.
273
+ *
274
+ * **WARNING:** In general, it is always better to perform database actions
275
+ * through repository methods. Directly executing MongoDB commands may lead
276
+ * to unexpected results and other issues.
277
+ *
278
+ * @example
279
+ *
280
+ * ```ts
281
+ * const result = await db.execute('MyCollection', 'aggregate', [
282
+ * {$lookup: {
283
+ * // ...
284
+ * }},
285
+ * {$unwind: '$data'},
286
+ * {$out: 'tempData'}
287
+ * ]);
288
+ * ```
289
+ *
290
+ * @param collectionName The name of the collection to execute the command on.
291
+ * @param command The command name. See
292
+ * [Collection API docs](http://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html)
293
+ * for the list of commands supported by the MongoDB client.
294
+ * @param parameters Command parameters (arguments), as described in MongoDB API
295
+ * docs for individual collection methods.
296
+ * @returns A promise which resolves to the command output as returned by the
297
+ * database driver.
298
+ */
299
+ execute(collectionName: string, command: string, ...parameters: any[]): Promise<any>;
300
+
301
+ /**
302
+ * Execute a raw database command using a connector that's not described
303
+ * by LoopBack's `execute` API yet.
304
+ *
305
+ * **WARNING:** In general, it is always better to perform database actions
306
+ * through repository methods. Directly executing database commands may lead
307
+ * to unexpected results and other issues.
308
+ *
309
+ * @param args Command and parameters, please consult your connector's
310
+ * documentation to learn about supported commands and their parameters.
311
+ * @returns A promise which resolves to the command output as returned by the
312
+ * database driver.
313
+ */
314
+ execute(...args: any[]): Promise<any>;
315
+
316
+ /**
317
+ * Begin a new transaction.
318
+ *
319
+ *
320
+ * @param [options] Options {isolationLevel: '...', timeout: 1000}
321
+ * @returns Promise A promise which resolves to a Transaction object
322
+ */
323
+ beginTransaction(options?: IsolationLevel | Options): Promise<Transaction>;
324
+ }
@@ -0,0 +1,21 @@
1
+ import { inspect } from 'util';
2
+
3
+ // @achrinza: One of the limitations of these definitions is that the class instance
4
+ // isn't callable; Hence, changing the `value` class member must be done
5
+ // directly. This is a TypeScript limitation as class constructors cannot
6
+ // have a custom return value.
7
+ export function DateString(value: DateString | string): DateString;
8
+ export class DateString {
9
+ private _when: string;
10
+ private _date: Date;
11
+
12
+ get when(): string;
13
+ set when(val: string);
14
+
15
+ constructor(value: string);
16
+
17
+ toString(): DateString['when'];
18
+ toJSON(): { when: DateString['when'] };
19
+ inspect(): string;
20
+ [inspect.custom]: DateString['inspect'];
21
+ }
@@ -0,0 +1,44 @@
1
+ // Copyright IBM Corp. 2018. All Rights Reserved.
2
+ // Node module: loopback-datasource-juggler
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import { PersistedData, PersistedModel } from '..';
7
+ import { Callback, Options, PromiseOrVoid } from './common';
8
+ import { Inclusion } from './query';
9
+
10
+ /**
11
+ * Inclusion mixin
12
+ */
13
+ export interface InclusionMixin {
14
+ /**
15
+ * Enables you to load relations of several objects and optimize numbers of requests.
16
+ *
17
+ * Examples:
18
+ *
19
+ * Load all users' posts with only one additional request:
20
+ * `User.include(users, 'posts', function() {});`
21
+ * Or
22
+ * `User.include(users, ['posts'], function() {});`
23
+ *
24
+ * Load all users posts and passports with two additional requests:
25
+ * `User.include(users, ['posts', 'passports'], function() {});`
26
+ *
27
+ * Load all passports owner (users), and all posts of each owner loaded:
28
+ *```Passport.include(passports, {owner: 'posts'}, function() {});
29
+ *``` Passport.include(passports, {owner: ['posts', 'passports']});
30
+ *``` Passport.include(passports, {owner: [{posts: 'images'}, 'passports']});
31
+ *
32
+ * @param {Array} objects Array of instances
33
+ * @param {String|Object|Array} include Which relations to load.
34
+ * @param {Object} [options] Options for CRUD
35
+ * @param {Function} cb Callback called when relations are loaded
36
+ *
37
+ */
38
+ include<T extends PersistedModel>(
39
+ objects: PersistedData<T>[],
40
+ include: Inclusion,
41
+ options?: Options,
42
+ callback?: Callback<PersistedData<T>[]>,
43
+ ): PromiseOrVoid<PersistedData<T>[]>;
44
+ }
@@ -0,0 +1,36 @@
1
+ // Copyright IBM Corp. 2018. All Rights Reserved.
2
+ // Node module: loopback-datasource-juggler
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ // Type definitions for loopback-datasource-juggler 3.x
7
+ // Project: https://github.com/strongloop/loopback-datasource-juggler
8
+ // Definitions by: Raymond Feng <https://github.com/raymondfeng>
9
+ // TypeScript Version: 2.8
10
+
11
+ /**
12
+ * Experimental TypeScript definitions to capture types of the key artifacts
13
+ * from `loopback-datasource-juggler` module. One of the main purposes is to
14
+ * leverage such types in `LoopBack 4`'s bridge to juggler.
15
+ *
16
+ * Please note some of the classes, properties, methods, and functions are
17
+ * intentionally not included in the definitions because of one of the following
18
+ * factors:
19
+ *
20
+ * - They are internal
21
+ * - They are to be deprecated
22
+ */
23
+ export * from './common';
24
+ export * from './model';
25
+ export * from './relation';
26
+ export * from './query';
27
+ export * from './datasource';
28
+ export * from './kv-model';
29
+ export * from './persisted-model';
30
+ export * from './scope';
31
+ export * from './transaction-mixin';
32
+ export * from './relation-mixin';
33
+ export * from './observer-mixin';
34
+ export * from './validation-mixin';
35
+ export * from './inclusion-mixin';
36
+ export * from './connector';