chore: more misc changes

Signed-off-by: Rifa Achrinza <25147899+achrinza@users.noreply.github.com>
This commit is contained in:
Rifa Achrinza 2023-09-01 23:52:15 +08:00
parent 5a52edbbfa
commit 7d59e16d6c
No known key found for this signature in database
GPG Key ID: B85B83A366C129FA
25 changed files with 294 additions and 43 deletions

1
deleteme/__test__.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

91
deleteme/__test__.js Normal file
View File

@ -0,0 +1,91 @@
"use strict";
// Copyright IBM Corp. 2020. All Rights Reserved.
// Node module: loopback-datasource-juggler
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
Object.defineProperty(exports, "__esModule", { value: true });
// A test file to verify types described by our .d.ts files.
// The code in this file is only compiled, we don't run it via Mocha.
const __1 = require("..");
const db = new __1.DataSource('db', { connector: 'memory' });
//-------
// ModelBase should provide ObserverMixin APIs as static methods
//-------
//
(function () {
const Data = db.createModel('Data');
// An operation hook can be installed
Data.observe('before save', async (ctx) => { });
// Context is typed and provides `Model` property
Data.observe('before save', async (ctx) => {
console.log(ctx.Model.modelName);
});
// ModelBaseClass can be assigned to `typeof ModelBase`
// Please note that both `ModelBaseClass` and typeof ModelBase`
// are different ways how to describe a class constructor of a model.
// In this test we are verifying that the value returned by `createModel`
// can be assigned to both types.
const modelTypeof = Data;
const modelCls = modelTypeof;
});
//-------
// PersistedModel should provide ObserverMixin APIs as static methods
//-------
(function () {
const Product = db.createModel('Product', { name: String }, { strict: true });
// It accepts async function
Product.observe('before save', async (ctx) => { });
// It accepts callback-based function
Product.observe('before save', (ctx, next) => {
next(new Error('test error'));
});
// ctx.Model is a PersistedModel class constructor
Product.observe('before save', async (ctx) => {
await ctx.Model.findOne();
});
// PersistedModelClass can be assigned to `typeof PersistedModel`
// Please note that both `PersistedModelClass` and typeof PersistedModel`
// are different ways how to describe a class constructor of a model.
// In this test we are verifying that the value returned by `createModel`
// can be assigned to both types.
const modelTypeof = Product;
const modelCls = modelTypeof;
});
//-------
// KeyValueModel should provide ObserverMixin APIs as static methods
//-------
(function () {
const kvdb = new __1.DataSource({ connector: 'kv-memory' });
const CacheItem = kvdb.createModel('CacheItem');
// An operation hook can be installed
CacheItem.observe('before save', async (ctx) => { });
// ctx.Model is a KeyValueModel class constructor
CacheItem.observe('before save', async (ctx) => {
await ctx.Model.expire('key', 100);
});
});
//-------
// DataSource supports different `execute` styles
//-------
(async function () {
// SQL style
const tx = await db.beginTransaction();
await db.execute('SELECT * FROM Product WHERE count > ?', [10], {
transaction: tx,
});
await tx.commit();
// MongoDB style
await db.execute('MyCollection', 'aggregate', [
{ $lookup: { /* ... */} },
{ $unwind: '$data' },
{ $out: 'tempData' }
]);
// Neo4J style
await db.execute({
query: 'MATCH (u:User {email: {email}}) RETURN u',
params: {
email: 'alice@example.com',
},
});
});
//# sourceMappingURL=__test__.js.map

1
deleteme/__test__.js.map Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"__test__.js","sourceRoot":"","sources":["../types/__test__.ts"],"names":[],"mappings":"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"}

View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("util");
const date_string_1 = require("../date-string");
let stringTypeGuard;
const dateString = new date_string_1.DateString('2020-01-01');
date_string_1.DateString('2020-01-01');
date_string_1.DateString(dateString);
stringTypeGuard = dateString.toJSON().when;
stringTypeGuard = dateString.toString();
stringTypeGuard = dateString.inspect();
stringTypeGuard = dateString[util_1.inspect.custom]();
//# sourceMappingURL=date-string.spec.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"date-string.spec.js","sourceRoot":"","sources":["../../types/__tests__/date-string.spec.ts"],"names":[],"mappings":";;AAAA,+BAA+B;AAC/B,gDAA0C;AAE1C,IAAI,eAAuB,CAAC;AAE5B,MAAM,UAAU,GAAG,IAAI,wBAAU,CAAC,YAAY,CAAC,CAAC;AAChD,wBAAU,CAAC,YAAY,CAAC,CAAC;AACzB,wBAAU,CAAC,UAAU,CAAC,CAAC;AACvB,eAAe,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC;AAC3C,eAAe,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;AACxC,eAAe,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC;AACvC,eAAe,GAAG,UAAU,CAAC,cAAO,CAAC,MAAM,CAAC,EAAE,CAAC"}

1
deleteme/__tests__/geopoint.spec.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const geo_1 = require("../geo");
let numberTypeGuard;
new geo_1.GeoPoint(123, 456);
new geo_1.GeoPoint('123', 456);
new geo_1.GeoPoint(123, '456');
new geo_1.GeoPoint('123', '456');
new geo_1.GeoPoint([123, 456]);
new geo_1.GeoPoint(['123', '456']);
new geo_1.GeoPoint(['123', 456]);
new geo_1.GeoPoint([123, '456']);
new geo_1.GeoPoint({ lat: 123, lng: 456 });
new geo_1.GeoPoint({ lat: '123', lng: 456 });
new geo_1.GeoPoint({ lat: 123, lng: '456' });
new geo_1.GeoPoint({ lat: '123', lng: '456' });
numberTypeGuard = geo_1.GeoPoint.distanceBetwen([123, 456], [123, 456]);
numberTypeGuard = geo_1.GeoPoint.distanceBetwen([123, 456], [123, 456], { type: geo_1.GeoDistanceUnit.degrees });
const geoPoint = new geo_1.GeoPoint(123, 456);
numberTypeGuard = geoPoint.distanceTo([123, 456]);
numberTypeGuard = geoPoint.distanceTo([123, 456], { type: geo_1.GeoDistanceUnit.degrees });
//# sourceMappingURL=geopoint.spec.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"geopoint.spec.js","sourceRoot":"","sources":["../../types/__tests__/geopoint.spec.ts"],"names":[],"mappings":";;AAAA,gCAAqE;AAErE,IAAI,eAAuB,CAAC;AAE5B,IAAI,cAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACvB,IAAI,cAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACzB,IAAI,cAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AACzB,IAAI,cAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAE3B,IAAI,cAAQ,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACzB,IAAI,cAAQ,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAC7B,IAAI,cAAQ,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;AAC3B,IAAI,cAAQ,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;AAE3B,IAAI,cAAQ,CAAC,EAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAC,CAAC,CAAC;AACnC,IAAI,cAAQ,CAAC,EAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAC,CAAC,CAAA;AACpC,IAAI,cAAQ,CAAC,EAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAC,CAAC,CAAA;AACpC,IAAI,cAAQ,CAAC,EAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAC,CAAC,CAAC;AAEvC,eAAe,GAAG,cAAQ,CAAC,cAAc,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAClE,eAAe,GAAG,cAAQ,CAAC,cAAc,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAC,IAAI,EAAE,qBAAe,CAAC,OAAO,EAAC,CAAC,CAAC;AAEnG,MAAM,QAAQ,GAAG,IAAI,cAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACxC,eAAe,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;AACjD,eAAe,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAC,IAAI,EAAE,qBAAe,CAAC,OAAO,EAAC,CAAC,CAAC"}

View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const model_builder_1 = require("../model-builder");
let modelBuilderTypeGuard = model_builder_1.ModelBuilder;
let typesTypeGuard;
// Test: Ensure that ModelBuilder is compliant with Types interface as
// ...ModelBuilder inherits from Types. This is to workaround TypeScript's
// ...inability to represent unorthodox "extending" from multiple classes.
typesTypeGuard = modelBuilderTypeGuard;
//# sourceMappingURL=model-builder.spec.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"model-builder.spec.js","sourceRoot":"","sources":["../../types/__tests__/model-builder.spec.ts"],"names":[],"mappings":";;AAAA,oDAAgD;AAGhD,IAAI,qBAAqB,GAAwB,4BAAY,CAAC;AAC9D,IAAI,cAA+B,CAAC;AAEpC,sEAAsE;AACtE,gFAAgF;AAChF,gFAAgF;AAChF,cAAc,GAAG,qBAAqB,CAAC"}

1
deleteme/__tests__/types.spec.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,18 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = __importDefault(require("../types"));
let stringTypeGuard;
let voidTypeGuard;
let jsonTypeGuard;
stringTypeGuard = types_1.Types.JSON('arbitrary value');
voidTypeGuard = types_1.Types.JSON(new types_1.Types.JSON('test'));
jsonTypeGuard = new types_1.Types.JSON('test');
const modelTypes = {};
types_1.default(modelTypes);
voidTypeGuard = modelTypes.registerType({});
voidTypeGuard = modelTypes.registerType({}, ['custom name 1']);
modelTypes.schemaTypes;
//# sourceMappingURL=types.spec.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"types.spec.js","sourceRoot":"","sources":["../../types/__tests__/types.spec.ts"],"names":[],"mappings":";;;;;AAAA,qDAAqE;AAErE,IAAI,eAAuB,CAAC;AAC5B,IAAI,aAAmB,CAAC;AACxB,IAAI,aAAyB,CAAC;AAE9B,eAAe,GAAG,aAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;AAChD,aAAa,GAAG,aAAK,CAAC,IAAI,CAAC,IAAI,aAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,aAAa,GAAG,IAAI,aAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACvC,MAAM,UAAU,GAAe,EAAgB,CAAC;AAChD,eAAkB,CAAC,UAAU,CAAC,CAAC;AAC/B,aAAa,GAAG,UAAU,CAAC,YAAY,CAAC,EAAU,CAAC,CAAC;AACpD,aAAa,GAAG,UAAU,CAAC,YAAY,CAAC,EAAU,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;AACvE,UAAU,CAAC,WAAW,CAAC"}

11
graph.txt Normal file
View File

@ -0,0 +1,11 @@
Connector------> DataAccessObject
^ /
| /____>_____________________>_____________
v / / \
DataSource -> ModelBuilder -> ModelClass -> ModelDefinition -> ModelSettings
\_____________>_____________/ | \
| \__> ModelProperties
V
ModelBaseClass

33
package-lock.json generated
View File

@ -36,7 +36,8 @@
"mocha": "^8.4.0",
"nyc": "^15.1.0",
"should": "^13.2.3",
"typescript": "^4.0.3"
"typescript": "^5.1.6",
"typescript28": "npm:typescript@2.8"
},
"engines": {
"node": ">=10"
@ -4869,8 +4870,23 @@
}
},
"node_modules/typescript": {
"version": "4.4.2",
"integrity": "sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==",
"version": "5.1.6",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz",
"integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=14.17"
}
},
"node_modules/typescript28": {
"name": "typescript",
"version": "2.8.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.8.4.tgz",
"integrity": "sha512-IIU5cN1mR5J3z9jjdESJbnxikTrEz3lzAw/D0Tf45jHpBp55nY31UkUvmVHoffCfKHTqJs3fCLPDxknQTTFegQ==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
@ -8864,8 +8880,15 @@
}
},
"typescript": {
"version": "4.4.2",
"integrity": "sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ==",
"version": "5.1.6",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz",
"integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==",
"dev": true
},
"typescript28": {
"version": "npm:typescript@2.8.4",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.8.4.tgz",
"integrity": "sha512-IIU5cN1mR5J3z9jjdESJbnxikTrEz3lzAw/D0Tf45jHpBp55nY31UkUvmVHoffCfKHTqJs3fCLPDxknQTTFegQ==",
"dev": true
},
"universalify": {

View File

@ -47,7 +47,8 @@
"mocha": "^8.4.0",
"nyc": "^15.1.0",
"should": "^13.2.3",
"typescript": "^4.0.3"
"typescript": "^5.1.6",
"typescript28": "npm:typescript@2.8"
},
"dependencies": {
"async": "^3.1.0",

5
test.js Normal file
View File

@ -0,0 +1,5 @@
'use strict';
const juggler = require('.');
const ds = new juggler.DataSource('memory');
ds.createModel('MyModel', {'MyProp': String});

9
tsconfig.compat.json Normal file
View File

@ -0,0 +1,9 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "tsconfig.json",
"compilerOptions": {
skip
},
"include": ["types/", "index.d.ts"],
"exclude": ["node_modules/**"]
}

View File

@ -1,5 +1,4 @@
import * as buildModelTypes from '../types';
import {ModelTypes, Type, Types} from '../types';
import registerModelTypes, {ModelTypes, Type, Types} from '../types';
let stringTypeGuard: string;
let voidTypeGuard: void;
@ -8,8 +7,8 @@ let jsonTypeGuard: Types.JSON;
stringTypeGuard = Types.JSON('arbitrary value');
voidTypeGuard = Types.JSON(new Types.JSON('test'));
jsonTypeGuard = new Types.JSON('test');
const modelTypes: ModelTypes = {}
buildModelTypes(modelTypes);
const modelTypes: ModelTypes = {} as ModelTypes;
registerModelTypes(modelTypes);
voidTypeGuard = modelTypes.registerType({} as Type);
voidTypeGuard = modelTypes.registerType({} as Type, ['custom name 1']);
modelTypes.schemaTypes;

View File

@ -1,8 +1,9 @@
import { Callback } from '../common';
import {ConnectorInitialize, Connector, SchemaDiscoveryOptions, ConnectorSettings} from '../connector'
import {ConnectorInitialize, SchemaDiscoveryOptions, ConnectorSettings} from '../connector'
import { DataAccessObject } from '../dao';
import { DataSource } from '../datasource';
import { ModelBase, Schema } from '../model';
import {Connector} from 'loopback-connector';
export let initialize: ConnectorInitialize;
@ -13,12 +14,12 @@ export interface TransientConnectorSettings extends ConnectorSettings {
export type TransientConnectorGenerateId = (model: string, data?: unknown, idName?: string) => string;
// export declare class Transient implements Connector {
// isTransaction: boolean;
// constructor(m: Transient | null, settings?: ConnectorSettings);
// onTransactionExec?: Callback<void>;
// generateId: TransientConnectorGenerateId;
// flush<T extends any>(action: unknown, result?: T, callback?: Callback<T>): void;
// exec(callback: Callback<void>): void;
// transaction(): Transient;
// }
export declare class Transient extends Connector {
isTransaction: boolean;
constructor(m: Transient | null, settings?: TransientConnectorSettings);
onTransactionExec?: Callback<void>;
generateId: TransientConnectorGenerateId;
flush<T extends any>(action: unknown, result?: T, callback?: Callback<T>): void;
exec(callback: Callback<void>): void;
transaction(): Transient;
}

21
types/datasource.d.ts vendored
View File

@ -9,6 +9,7 @@ import {
ModelBaseClass,
ModelDefinition,
PropertyDefinition,
PropertyType,
} from './model';
import { ModelBuilder } from "./model-builder";
import {EventEmitter} from 'events';
@ -116,6 +117,7 @@ export function DataSource<CT extends Connector>(
*/
export declare class DataSource<
CT extends Connector = Connector,
MBT extends ModelBuilder = ModelBuilder,
> extends EventEmitter {
name: string;
settings: ConnectorSettings;
@ -129,18 +131,18 @@ export declare class DataSource<
*
* @deprecated Use {@link DataSource.connector} instead.
*/
adapter?: BuiltConnector & CT;
adapter?: DataSource['connector'];
/**
* Connector instance.
*/
connector?: BuiltConnector & CT;
modelBuilder: ModelBuilder;
modelBuilder: MBT;
models: Record<string, ModelBaseClass>;
models: MBT['models'];
definitions: {[modelName: string]: ModelDefinition};
definitions: MBT['definitions'];
DataAccessObject: AnyObject & {prototype: AnyObject};
@ -200,18 +202,18 @@ export declare class DataSource<
*/
static relationTypes: Record<string, string>;
constructor(settings: ConnectorSettings, modelBuilder?: MBT);
constructor(
name: string,
settings?: ConnectorSettings,
modelBuilder?: ModelBuilder,
modelBuilder?: MBT,
);
constructor(settings: ConnectorSettings, modelBuilder?: ModelBuilder);
constructor(
connectorModule: Connector,
settings?: Omit<ConnectorSettings, 'adapter' | 'connector'>,
modelBuilder?: ModelBuilder,
modelBuilder?: MBT,
);
private setup(dsName: string, settings: ConnectorSettings): void;
@ -397,7 +399,8 @@ export declare class DataSource<
*/
createModel<T extends ModelBaseClass>(
name: string,
properties?: PropertyDefinition[],
// properties?: PropertyDefinition[],
properties?: Record<string, PropertyType>,
options?: ModelSettings,
): T;

49
types/jutil.d.ts vendored
View File

@ -1,13 +1,46 @@
export type InheritsOptions = {
staticProperties?: boolean,
override?: boolean,
export interface InheritsOptions {
staticProperties?: boolean;
override?: boolean;
}
export type MixinOptions = InheritsOptions & {
instanceProperties?: boolean,
proxyFunctions?: boolean,
export interface MixIntoOptions {
override?: boolean
}
export function inherits<T extends object>(newClass: T, baseClass: object, options: InheritsOptions): T;
export interface MixinOptions extends InheritsOptions, MixIntoOptions {
instanceProperties?: boolean;
proxyFunctions?: boolean;
}
export function mixin<T extends object>(newClass: T, mixinClass: object, options: MixinOptions): T;
export function inherits<T extends object>(
newClass: T,
baseClass: object,
options: InheritsOptions,
): T;
export function mixin<
NT extends object & {prototype?: object},
MT extends object & {prototype?: object},
OT extends MixinOptions>(
newClass: NT,
mixinClass: MT,
options: OT,
): (OT['staticProperties'] extends undefined | false ? {} :
ReturnType<typeof mixInto>) &
(OT['instanceProperties'] extends undefined | false ? {} :
NT['prototype'] extends undefined ? {} :
ReturnType<typeof mixInto<MT['prototype'], NT['prototype'], OT>>);
declare function mixInto<
ST extends object | undefined,
TT extends object | undefined,
OT extends MixIntoOptions,
>(
sourceScope: ST,
targetScope: TT,
options: OT,
): OT['override'] extends true
? ST & Exclude<TT, keyof ST>
: TT & Exclude<ST, keyof TT>;
declare function mergeMixins(source: object[], target: object[]): object[];

14
types/model.d.ts vendored
View File

@ -132,7 +132,9 @@ export interface ColumnMetadata extends AnyObject {
}
/**
* Definition of model properties, for example
* Definition of model properties.
*
* @remarks
* ```ts
* {
* name: {type: String, required: true},
@ -233,12 +235,12 @@ export interface ModelSettings
*/
forceId?: boolean | 'auto';
properties?: ModelProperties;
// properties?: ModelProperties;
/**
* @deprecated Use {@link ModelSettings.properties} instead.
*/
attributes?: ModelProperties;
// /**
// * @deprecated Use {@link ModelSettings.properties} instead.
// */
// attributes?: ModelProperties;
/**
* @remarks