@decaf-ts/core 0.0.4
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/LICENSE.md +21 -0
- package/README.md +297 -0
- package/dist/core.bundle.min.js +2 -0
- package/dist/core.bundle.min.js.LICENSE.txt +14 -0
- package/dist/esm/core.bundle.min.esm.js +2 -0
- package/dist/esm/core.bundle.min.esm.js.LICENSE.txt +14 -0
- package/lib/esm/identity/decorators.d.ts +29 -0
- package/lib/esm/identity/decorators.js +1 -0
- package/lib/esm/identity/index.d.ts +1 -0
- package/lib/esm/identity/index.js +1 -0
- package/lib/esm/index.d.ts +23 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/interfaces/Builder.d.ts +16 -0
- package/lib/esm/interfaces/Builder.js +0 -0
- package/lib/esm/interfaces/Executor.d.ts +17 -0
- package/lib/esm/interfaces/Executor.js +0 -0
- package/lib/esm/interfaces/IAdapter.d.ts +5 -0
- package/lib/esm/interfaces/IAdapter.js +0 -0
- package/lib/esm/interfaces/Observable.d.ts +31 -0
- package/lib/esm/interfaces/Observable.js +0 -0
- package/lib/esm/interfaces/Observer.d.ts +16 -0
- package/lib/esm/interfaces/Observer.js +0 -0
- package/lib/esm/interfaces/RawExecutor.d.ts +19 -0
- package/lib/esm/interfaces/RawExecutor.js +0 -0
- package/lib/esm/interfaces/Sequence.d.ts +16 -0
- package/lib/esm/interfaces/Sequence.js +0 -0
- package/lib/esm/interfaces/SequenceOptions.d.ts +10 -0
- package/lib/esm/interfaces/SequenceOptions.js +0 -0
- package/lib/esm/interfaces/index.d.ts +8 -0
- package/lib/esm/interfaces/index.js +1 -0
- package/lib/esm/model/BaseModel.d.ts +7 -0
- package/lib/esm/model/BaseModel.js +1 -0
- package/lib/esm/model/index.d.ts +1 -0
- package/lib/esm/model/index.js +1 -0
- package/lib/esm/persistence/Adapter.d.ts +39 -0
- package/lib/esm/persistence/Adapter.js +1 -0
- package/lib/esm/persistence/constants.d.ts +1 -0
- package/lib/esm/persistence/constants.js +1 -0
- package/lib/esm/persistence/decorators.d.ts +3 -0
- package/lib/esm/persistence/decorators.js +1 -0
- package/lib/esm/persistence/index.d.ts +4 -0
- package/lib/esm/persistence/index.js +1 -0
- package/lib/esm/persistence/utils.d.ts +1 -0
- package/lib/esm/persistence/utils.js +1 -0
- package/lib/esm/repository/Repository.d.ts +33 -0
- package/lib/esm/repository/Repository.js +1 -0
- package/lib/esm/repository/errors.d.ts +12 -0
- package/lib/esm/repository/errors.js +1 -0
- package/lib/esm/repository/index.d.ts +2 -0
- package/lib/esm/repository/index.js +1 -0
- package/lib/identity/decorators.cjs +1 -0
- package/lib/identity/decorators.d.ts +29 -0
- package/lib/identity/index.cjs +1 -0
- package/lib/identity/index.d.ts +1 -0
- package/lib/index.cjs +1 -0
- package/lib/index.d.ts +23 -0
- package/lib/interfaces/Builder.cjs +1 -0
- package/lib/interfaces/Builder.d.ts +16 -0
- package/lib/interfaces/Executor.cjs +1 -0
- package/lib/interfaces/Executor.d.ts +17 -0
- package/lib/interfaces/IAdapter.cjs +1 -0
- package/lib/interfaces/IAdapter.d.ts +5 -0
- package/lib/interfaces/Observable.cjs +1 -0
- package/lib/interfaces/Observable.d.ts +31 -0
- package/lib/interfaces/Observer.cjs +1 -0
- package/lib/interfaces/Observer.d.ts +16 -0
- package/lib/interfaces/RawExecutor.cjs +1 -0
- package/lib/interfaces/RawExecutor.d.ts +19 -0
- package/lib/interfaces/Sequence.cjs +1 -0
- package/lib/interfaces/Sequence.d.ts +16 -0
- package/lib/interfaces/SequenceOptions.cjs +1 -0
- package/lib/interfaces/SequenceOptions.d.ts +10 -0
- package/lib/interfaces/index.cjs +1 -0
- package/lib/interfaces/index.d.ts +8 -0
- package/lib/model/BaseModel.cjs +1 -0
- package/lib/model/BaseModel.d.ts +7 -0
- package/lib/model/index.cjs +1 -0
- package/lib/model/index.d.ts +1 -0
- package/lib/persistence/Adapter.cjs +1 -0
- package/lib/persistence/Adapter.d.ts +39 -0
- package/lib/persistence/constants.cjs +1 -0
- package/lib/persistence/constants.d.ts +1 -0
- package/lib/persistence/decorators.cjs +1 -0
- package/lib/persistence/decorators.d.ts +3 -0
- package/lib/persistence/index.cjs +1 -0
- package/lib/persistence/index.d.ts +4 -0
- package/lib/persistence/utils.cjs +1 -0
- package/lib/persistence/utils.d.ts +1 -0
- package/lib/repository/Repository.cjs +1 -0
- package/lib/repository/Repository.d.ts +33 -0
- package/lib/repository/errors.cjs +1 -0
- package/lib/repository/errors.d.ts +12 -0
- package/lib/repository/index.cjs +1 -0
- package/lib/repository/index.d.ts +2 -0
- package/package.json +106 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { DBModel, Repository as Rep } from "@decaf-ts/db-decorators";
|
|
2
|
+
import { Observable } from "../interfaces/Observable";
|
|
3
|
+
import { Observer } from "../interfaces/Observer";
|
|
4
|
+
import { Adapter } from "../persistence/Adapter";
|
|
5
|
+
export declare abstract class Repository<T extends DBModel> extends Rep<T> implements Observable {
|
|
6
|
+
private observers;
|
|
7
|
+
private readonly _adapter;
|
|
8
|
+
get adapter(): Adapter<string>;
|
|
9
|
+
protected constructor();
|
|
10
|
+
create(model: T, ...args: any[]): Promise<T>;
|
|
11
|
+
read(key: string, ...args: any[]): Promise<T>;
|
|
12
|
+
update(model: T, ...args: any[]): Promise<T>;
|
|
13
|
+
delete(key: string, ...args: any[]): Promise<T>;
|
|
14
|
+
/**
|
|
15
|
+
* @summary Registers an {@link Observer}
|
|
16
|
+
* @param {Observer} observer
|
|
17
|
+
*
|
|
18
|
+
* @see {Observable#observe}
|
|
19
|
+
*/
|
|
20
|
+
observe(observer: Observer): void;
|
|
21
|
+
/**
|
|
22
|
+
* @summary Unregisters an {@link Observer}
|
|
23
|
+
* @param {Observer} observer
|
|
24
|
+
*
|
|
25
|
+
* @see {Observable#unObserve}
|
|
26
|
+
*/
|
|
27
|
+
unObserve(observer: Observer): void;
|
|
28
|
+
/**
|
|
29
|
+
* @summary calls all registered {@link Observer}s to update themselves
|
|
30
|
+
* @param {any[]} [args] optional arguments to be passed to the {@link Observer#refresh} method
|
|
31
|
+
*/
|
|
32
|
+
updateObservers(...args: any[]): Promise<void>;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{InternalError,Repository as Rep}from"@decaf-ts/db-decorators";import{ObserverError}from"./errors";class Repository extends Rep{get adapter(){if(this._adapter)return this._adapter;throw new InternalError("No adapter found for this repository. did you use the @uses decorator or pass it in the constructor?")}constructor(){super(),this.observers=[]}async create(r,...e){return this.adapter.create(r,...e)}async read(r,...e){return this.adapter.read(r,...e)}async update(r,...e){return this.adapter.update(r,...e)}async delete(r,...e){return this.adapter.delete(r,...e)}observe(r){if(-1!==this.observers.indexOf(r))throw new InternalError("Observer already registered");this.observers.push(r)}unObserve(r){r=this.observers.indexOf(r);if(-1===r)throw new InternalError("Failed to find Observer");this.observers.splice(r,1)}async updateObservers(...t){return new Promise((r,e)=>{Promise.all(this.observers.map(r=>r.refresh(...t))).then(()=>{r()}).catch(r=>e(new ObserverError(r)))})}}export{Repository};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseError } from "@decaf-ts/db-decorators";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Represents a failure in observer communication
|
|
4
|
+
*
|
|
5
|
+
* @param {string} msg the error message
|
|
6
|
+
*
|
|
7
|
+
* @class ObserverError
|
|
8
|
+
* @extends BaseError
|
|
9
|
+
*/
|
|
10
|
+
export declare class ObserverError extends BaseError {
|
|
11
|
+
constructor(msg: string | Error);
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{BaseError}from"@decaf-ts/db-decorators";class ObserverError extends BaseError{constructor(r){super(ObserverError.name,r)}}export{ObserverError};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./errors";export*from"./Repository";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.pkOnCreate=pkOnCreate,exports.pk=pk;let decorator_validation_1=require("@decaf-ts/decorator-validation"),db_decorators_1=require("@decaf-ts/db-decorators"),reflection_1=require("@decaf-ts/reflection");async function pkOnCreate(r,t,a){if(r.sequence){let e;try{e=await this.adapter.getSequence(a,r.sequence,r.options)}catch(e){throw new db_decorators_1.InternalError(`Failed to instantiate Sequence ${r.sequence.name}: `+e)}r=await e.next();Object.defineProperty(a,t,{enumerable:!0,writable:!1,configurable:!0,value:r})}}function pk(e,r){e={sequence:e,options:r};return(0,reflection_1.apply)((0,db_decorators_1.index)(),(0,decorator_validation_1.required)(),(0,db_decorators_1.readonly)(),(0,reflection_1.metadata)((0,db_decorators_1.getDBKey)(db_decorators_1.DBKeys.ID),{}),(0,db_decorators_1.onCreate)(pkOnCreate,e))}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Constructor } from "@decaf-ts/decorator-validation";
|
|
2
|
+
import { SequenceOptions } from "../interfaces/SequenceOptions";
|
|
3
|
+
import { Sequence } from "../interfaces/Sequence";
|
|
4
|
+
import { DBModel } from "@decaf-ts/db-decorators";
|
|
5
|
+
import { Repository } from "../repository/Repository";
|
|
6
|
+
export type IdOnCreateData = {
|
|
7
|
+
sequence?: Constructor<Sequence>;
|
|
8
|
+
options?: SequenceOptions;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @summary Primary Key Decorator
|
|
12
|
+
* @description Marks the property as the {@link DBModel}s primary key.
|
|
13
|
+
* Also marks the property as {@link unique} as {@required} and ensures the index is created properly according to the provided {@link Sequence}
|
|
14
|
+
*
|
|
15
|
+
*
|
|
16
|
+
*
|
|
17
|
+
* @function pk
|
|
18
|
+
*
|
|
19
|
+
* @memberOf module:wallet-db.Decorators
|
|
20
|
+
*
|
|
21
|
+
* @see unique
|
|
22
|
+
* @see required
|
|
23
|
+
* @see on
|
|
24
|
+
* @param data
|
|
25
|
+
* @param key
|
|
26
|
+
* @param model
|
|
27
|
+
*/
|
|
28
|
+
export declare function pkOnCreate<T extends DBModel, V extends Repository<T>>(this: V, data: IdOnCreateData, key: string, model: T): Promise<void>;
|
|
29
|
+
export declare function pk(sequence?: Constructor<Sequence>, opts?: SequenceOptions): <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&("get"in o?t.__esModule:!o.writable&&!o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,o)}:function(e,t,r,i){e[i=void 0===i?r:i]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./decorators.cjs"),exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./decorators";
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&("get"in i?r.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,i)}:function(e,r,t,o){e[o=void 0===o?t:o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.VERSION=void 0,__exportStar(require("./identity/index.cjs"),exports),__exportStar(require("./interfaces/index.cjs"),exports),__exportStar(require("./model/index.cjs"),exports),__exportStar(require("./persistence/index.cjs"),exports),__exportStar(require("./repository/index.cjs"),exports),exports.VERSION="0.0.3";
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary Module summary
|
|
3
|
+
* @description Module description
|
|
4
|
+
* @module ts-workspace
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @summary Namespace summary
|
|
8
|
+
* @description Namespace description
|
|
9
|
+
* @namespace Namespace
|
|
10
|
+
* @memberOf module:ts-workspace
|
|
11
|
+
*/
|
|
12
|
+
export * from "./identity";
|
|
13
|
+
export * from "./interfaces";
|
|
14
|
+
export * from "./model";
|
|
15
|
+
export * from "./persistence";
|
|
16
|
+
export * from "./repository";
|
|
17
|
+
/**
|
|
18
|
+
* @summary stores the current package version
|
|
19
|
+
* @description this is how you should document a constant
|
|
20
|
+
* @const VERSION
|
|
21
|
+
* @memberOf module:ts-workspace
|
|
22
|
+
*/
|
|
23
|
+
export declare const VERSION = "0.0.3";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary Standard Builder APi for the Builder design pattern
|
|
3
|
+
* @description Expose the build method
|
|
4
|
+
*
|
|
5
|
+
* @interface Builder
|
|
6
|
+
*
|
|
7
|
+
* @category Construction
|
|
8
|
+
*/
|
|
9
|
+
export interface Builder<T> {
|
|
10
|
+
/**
|
|
11
|
+
* @summary Build the Object
|
|
12
|
+
*
|
|
13
|
+
* @method
|
|
14
|
+
*/
|
|
15
|
+
build(...args: any[]): T;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary processes query objects
|
|
3
|
+
*
|
|
4
|
+
* @interface Executor
|
|
5
|
+
*
|
|
6
|
+
* @category Query
|
|
7
|
+
*/
|
|
8
|
+
export interface Executor {
|
|
9
|
+
/**
|
|
10
|
+
* @summary Processes itself
|
|
11
|
+
*
|
|
12
|
+
* @param {any[]} args
|
|
13
|
+
*
|
|
14
|
+
* @method
|
|
15
|
+
*/
|
|
16
|
+
execute<V>(...args: any): Promise<V[]>;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Observer } from "./Observer";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Observable Api
|
|
4
|
+
* @description manage and update {@link Observer}s
|
|
5
|
+
*
|
|
6
|
+
* @interface Observable
|
|
7
|
+
*
|
|
8
|
+
* @category Observables
|
|
9
|
+
*/
|
|
10
|
+
export interface Observable {
|
|
11
|
+
/**
|
|
12
|
+
* @summary Register new {@link Observer}s
|
|
13
|
+
* @param {Observer} observer
|
|
14
|
+
*
|
|
15
|
+
* @method
|
|
16
|
+
*/
|
|
17
|
+
observe(observer: Observer): void;
|
|
18
|
+
/**
|
|
19
|
+
* @summary Unregister new {@link Observer}s
|
|
20
|
+
* @param {Observer} observer
|
|
21
|
+
*
|
|
22
|
+
* @method
|
|
23
|
+
*/
|
|
24
|
+
unObserve(observer: Observer): void;
|
|
25
|
+
/**
|
|
26
|
+
* @summary have registered {@link Observer}s update themselves
|
|
27
|
+
* @param {any[]} args
|
|
28
|
+
* @method
|
|
29
|
+
*/
|
|
30
|
+
updateObservers(...args: any[]): Promise<void>;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary Observer Api
|
|
3
|
+
* @description will be called by the {@link Observable}
|
|
4
|
+
*
|
|
5
|
+
* @interface Observer
|
|
6
|
+
*
|
|
7
|
+
* @category Observables
|
|
8
|
+
*/
|
|
9
|
+
export interface Observer {
|
|
10
|
+
/**
|
|
11
|
+
* @summary Refreshes the Observer
|
|
12
|
+
* @param {any[]} args
|
|
13
|
+
* @method
|
|
14
|
+
*/
|
|
15
|
+
refresh(...args: any[]): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary Executes a raw instruction in the Database
|
|
3
|
+
* @typeDef T The input type
|
|
4
|
+
*
|
|
5
|
+
* @interface RawExecutor
|
|
6
|
+
* @category Query
|
|
7
|
+
*/
|
|
8
|
+
export interface RawExecutor<T> {
|
|
9
|
+
/**
|
|
10
|
+
* @summary Executes a raw instruction in the Database
|
|
11
|
+
*
|
|
12
|
+
* @typeDef V the expected outcome of the instruction
|
|
13
|
+
* @param rawInput
|
|
14
|
+
* @param args
|
|
15
|
+
*
|
|
16
|
+
* @method
|
|
17
|
+
*/
|
|
18
|
+
raw<V>(rawInput: T, ...args: any[]): Promise<V>;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary Sequence
|
|
3
|
+
*
|
|
4
|
+
* @interface Sequence
|
|
5
|
+
*
|
|
6
|
+
* @category Sequences
|
|
7
|
+
*/
|
|
8
|
+
export interface Sequence {
|
|
9
|
+
/**
|
|
10
|
+
* @summary generates the next value in the sequence
|
|
11
|
+
*
|
|
12
|
+
* @method
|
|
13
|
+
*/
|
|
14
|
+
next(): Promise<string | number>;
|
|
15
|
+
current(): Promise<string | number>;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&("get"in i?r.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,i)}:function(e,r,t,o){e[o=void 0===o?t:o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./Builder.cjs"),exports),__exportStar(require("./Executor.cjs"),exports),__exportStar(require("./IAdapter.cjs"),exports),__exportStar(require("./Observable.cjs"),exports),__exportStar(require("./Observer.cjs"),exports),__exportStar(require("./RawExecutor.cjs"),exports),__exportStar(require("./Sequence.cjs"),exports),__exportStar(require("./SequenceOptions.cjs"),exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,o,a){var d,r=arguments.length,s=r<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,o):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,a);else for(var c=e.length-1;0<=c;c--)(d=e[c])&&(s=(r<3?d(s):3<r?d(t,o,s):d(t,o))||s);return 3<r&&s&&Object.defineProperty(t,o,s),s},__metadata=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseModel=void 0;let db_decorators_1=require("@decaf-ts/db-decorators");class BaseModel extends db_decorators_1.DBModel{constructor(e){super(e),this.createdOn=void 0,this.updatedOn=void 0}}exports.BaseModel=BaseModel,__decorate([(0,db_decorators_1.timestamp)(db_decorators_1.DBOperations.CREATE),__metadata("design:type",Date)],BaseModel.prototype,"createdOn",void 0),__decorate([(0,db_decorators_1.timestamp)(),__metadata("design:type",Date)],BaseModel.prototype,"updatedOn",void 0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&("get"in n?t.__esModule:!n.writable&&!n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,n)}:function(e,t,r,i){e[i=void 0===i?r:i]=t[r]}),__exportStar=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||__createBinding(t,e,r)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./BaseModel.cjs"),exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./BaseModel";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.Adapter=void 0;let db_decorators_1=require("@decaf-ts/db-decorators"),injectable_decorators_1=require("@decaf-ts/injectable-decorators"),utils_1=require("./utils.cjs"),errors_1=require("../repository/errors.cjs");class Adapter{constructor(){this.observers=[]}observe(r){if(-1!==this.observers.indexOf(r))throw new db_decorators_1.InternalError("Observer already registered");this.observers.push(r)}unObserve(r){r=this.observers.indexOf(r);if(-1===r)throw new db_decorators_1.InternalError("Failed to find Observer");this.observers.splice(r,1)}async updateObservers(...t){return new Promise((r,e)=>{Promise.all(this.observers.map(r=>r.refresh(...t))).then(()=>{r()}).catch(r=>e(new errors_1.ObserverError(r)))})}static get current(){return this._current}static get(r){var e=injectable_decorators_1.Injectables.get((0,utils_1.genAdapterInjectableKey)(r));if(e)return e;throw new db_decorators_1.InternalError(`No Adapter registered under ${r}. Did you use the @adapter decorator?`)}static setCurrent(r){var e=this.get(r);if(!e)throw new db_decorators_1.NotFoundError(`No persistence flavour ${r} registered`);this._current=e}}exports.Adapter=Adapter;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DBModel } from "@decaf-ts/db-decorators";
|
|
2
|
+
import { Observer } from "../interfaces/Observer";
|
|
3
|
+
import { IAdapter } from "../interfaces/IAdapter";
|
|
4
|
+
import { Sequence } from "../interfaces/Sequence";
|
|
5
|
+
import { Constructor } from "@decaf-ts/decorator-validation";
|
|
6
|
+
import { SequenceOptions } from "../interfaces/SequenceOptions";
|
|
7
|
+
export declare abstract class Adapter<T = string> implements IAdapter<T> {
|
|
8
|
+
private static _current;
|
|
9
|
+
private observers;
|
|
10
|
+
abstract createIndex(...args: any[]): Promise<any>;
|
|
11
|
+
abstract getSequence<V extends DBModel>(model: V, sequence: Constructor<Sequence>, options?: SequenceOptions): Promise<Sequence>;
|
|
12
|
+
abstract create<V>(model: V, ...args: any[]): Promise<V>;
|
|
13
|
+
abstract read<V>(key: string | number, ...args: any[]): Promise<V>;
|
|
14
|
+
abstract update<V>(model: V, ...args: any[]): Promise<V>;
|
|
15
|
+
abstract delete<V>(key: string | number, ...args: any[]): Promise<V>;
|
|
16
|
+
abstract raw<V>(rawInput: T, ...args: any[]): Promise<V>;
|
|
17
|
+
/**
|
|
18
|
+
* @summary Registers an {@link Observer}
|
|
19
|
+
* @param {Observer} observer
|
|
20
|
+
*
|
|
21
|
+
* @see {Observable#observe}
|
|
22
|
+
*/
|
|
23
|
+
observe(observer: Observer): void;
|
|
24
|
+
/**
|
|
25
|
+
* @summary Unregisters an {@link Observer}
|
|
26
|
+
* @param {Observer} observer
|
|
27
|
+
*
|
|
28
|
+
* @see {Observable#unObserve}
|
|
29
|
+
*/
|
|
30
|
+
unObserve(observer: Observer): void;
|
|
31
|
+
/**
|
|
32
|
+
* @summary calls all registered {@link Observer}s to update themselves
|
|
33
|
+
* @param {any[]} [args] optional arguments to be passed to the {@link Observer#refresh} method
|
|
34
|
+
*/
|
|
35
|
+
updateObservers(...args: any[]): Promise<void>;
|
|
36
|
+
static get current(): Adapter<any>;
|
|
37
|
+
static get(flavour: any): Adapter<any> | undefined;
|
|
38
|
+
static setCurrent(flavour: string): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.PersistenceKeys=void 0,exports.PersistenceKeys={REFLECT:"model.persistence.",ADAPTER:"adapter",INJECTABLE:"decaf-adapter-{0}"};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PersistenceKeys: Record<string, string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.getPersistenceKey=getPersistenceKey,exports.adapter=adapter,exports.uses=uses;let injectable_decorators_1=require("@decaf-ts/injectable-decorators"),reflection_1=require("@decaf-ts/reflection"),constants_1=require("./constants.cjs"),utils_1=require("./utils.cjs");function getPersistenceKey(e){return constants_1.PersistenceKeys.REFLECT+e}function adapter(e){return(0,injectable_decorators_1.injectable)((0,utils_1.genAdapterInjectableKey)(e),!0)}function uses(e){return(0,reflection_1.metadata)(getPersistenceKey(constants_1.PersistenceKeys.ADAPTER),(0,utils_1.genAdapterInjectableKey)(e))}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&("get"in i?r.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,i)}:function(e,r,t,o){e[o=void 0===o?t:o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./Adapter.cjs"),exports),__exportStar(require("./constants.cjs"),exports),__exportStar(require("./decorators.cjs"),exports),__exportStar(require("./utils.cjs"),exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.genAdapterInjectableKey=genAdapterInjectableKey;let decorator_validation_1=require("@decaf-ts/decorator-validation"),constants_1=require("./constants.cjs");function genAdapterInjectableKey(e){return(0,decorator_validation_1.sf)(constants_1.PersistenceKeys.INJECTABLE,e)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function genAdapterInjectableKey(flavour: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.Repository=void 0;let db_decorators_1=require("@decaf-ts/db-decorators"),errors_1=require("./errors.cjs");class Repository extends db_decorators_1.Repository{get adapter(){if(this._adapter)return this._adapter;throw new db_decorators_1.InternalError("No adapter found for this repository. did you use the @uses decorator or pass it in the constructor?")}constructor(){super(),this.observers=[]}async create(r,...e){return this.adapter.create(r,...e)}async read(r,...e){return this.adapter.read(r,...e)}async update(r,...e){return this.adapter.update(r,...e)}async delete(r,...e){return this.adapter.delete(r,...e)}observe(r){if(-1!==this.observers.indexOf(r))throw new db_decorators_1.InternalError("Observer already registered");this.observers.push(r)}unObserve(r){r=this.observers.indexOf(r);if(-1===r)throw new db_decorators_1.InternalError("Failed to find Observer");this.observers.splice(r,1)}async updateObservers(...s){return new Promise((r,e)=>{Promise.all(this.observers.map(r=>r.refresh(...s))).then(()=>{r()}).catch(r=>e(new errors_1.ObserverError(r)))})}}exports.Repository=Repository;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { DBModel, Repository as Rep } from "@decaf-ts/db-decorators";
|
|
2
|
+
import { Observable } from "../interfaces/Observable";
|
|
3
|
+
import { Observer } from "../interfaces/Observer";
|
|
4
|
+
import { Adapter } from "../persistence/Adapter";
|
|
5
|
+
export declare abstract class Repository<T extends DBModel> extends Rep<T> implements Observable {
|
|
6
|
+
private observers;
|
|
7
|
+
private readonly _adapter;
|
|
8
|
+
get adapter(): Adapter<string>;
|
|
9
|
+
protected constructor();
|
|
10
|
+
create(model: T, ...args: any[]): Promise<T>;
|
|
11
|
+
read(key: string, ...args: any[]): Promise<T>;
|
|
12
|
+
update(model: T, ...args: any[]): Promise<T>;
|
|
13
|
+
delete(key: string, ...args: any[]): Promise<T>;
|
|
14
|
+
/**
|
|
15
|
+
* @summary Registers an {@link Observer}
|
|
16
|
+
* @param {Observer} observer
|
|
17
|
+
*
|
|
18
|
+
* @see {Observable#observe}
|
|
19
|
+
*/
|
|
20
|
+
observe(observer: Observer): void;
|
|
21
|
+
/**
|
|
22
|
+
* @summary Unregisters an {@link Observer}
|
|
23
|
+
* @param {Observer} observer
|
|
24
|
+
*
|
|
25
|
+
* @see {Observable#unObserve}
|
|
26
|
+
*/
|
|
27
|
+
unObserve(observer: Observer): void;
|
|
28
|
+
/**
|
|
29
|
+
* @summary calls all registered {@link Observer}s to update themselves
|
|
30
|
+
* @param {any[]} [args] optional arguments to be passed to the {@link Observer#refresh} method
|
|
31
|
+
*/
|
|
32
|
+
updateObservers(...args: any[]): Promise<void>;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.ObserverError=void 0;let db_decorators_1=require("@decaf-ts/db-decorators");class ObserverError extends db_decorators_1.BaseError{constructor(r){super(ObserverError.name,r)}}exports.ObserverError=ObserverError;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseError } from "@decaf-ts/db-decorators";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Represents a failure in observer communication
|
|
4
|
+
*
|
|
5
|
+
* @param {string} msg the error message
|
|
6
|
+
*
|
|
7
|
+
* @class ObserverError
|
|
8
|
+
* @extends BaseError
|
|
9
|
+
*/
|
|
10
|
+
export declare class ObserverError extends BaseError {
|
|
11
|
+
constructor(msg: string | Error);
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&("get"in i?r.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,i)}:function(e,r,t,o){e[o=void 0===o?t:o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./errors.cjs"),exports),__exportStar(require("./Repository.cjs"),exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@decaf-ts/core",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "template for ts projects",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"require": "./lib/index.cjs",
|
|
8
|
+
"import": "./lib/esm/index.js"
|
|
9
|
+
},
|
|
10
|
+
"types": "lib/index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"do-install": "TOKEN=$(cat .token) npm install",
|
|
13
|
+
"update-dependencies": "rimraf node_modules/@decaf-ts package-lock.json && npm run do-install",
|
|
14
|
+
"flash-forward": "npx npm-check-updates -u && npm run do-install",
|
|
15
|
+
"reset": "rm -rf * && git checkout . && git pull && npm run do-install",
|
|
16
|
+
"build": "rimraf ./lib && rimraf ./dist && gulp dev",
|
|
17
|
+
"build:prod": "rimraf ./lib && rimraf ./dist && gulp prod",
|
|
18
|
+
"test": "jest --coverage --testPathPattern=\"/tests/unit\" --passWithNoTests --detectOpenHandles",
|
|
19
|
+
"test:integration": "jest --coverage --testPathPattern=\"/tests/(integration)\" --passWithNoTests --detectOpenHandles",
|
|
20
|
+
"test:all": "jest --coverage --testPathPattern=\"/tests/(unit|integration)\" --passWithNoTests --detectOpenHandles",
|
|
21
|
+
"lint": "eslint .",
|
|
22
|
+
"lint-fix": "eslint --fix ./src/*",
|
|
23
|
+
"test:circular": "dpdm -T --no-warning --no-tree ./src/index.ts",
|
|
24
|
+
"prepare-release": "npm run lint-fix && npm run build:prod && npm run test && npm run docs",
|
|
25
|
+
"release": "./bin/tag-release.sh",
|
|
26
|
+
"clean-publish": "npx clean-publish",
|
|
27
|
+
"coverage": "npm run test:all && jest-coverage-badges --input \"./workdocs/coverage/coverage-summary.json\" --output \"./workdocs/badges\"",
|
|
28
|
+
"docs": "npx rimraf ./docs && mkdir docs && npm run do-install -- better-docs taffydb && gulp docs; npm remove better-docs taffydb"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/decaf-ts/ts-workspace.git"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=20.0.0",
|
|
36
|
+
"npm": ">=10.0.0"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"lib",
|
|
40
|
+
"dist"
|
|
41
|
+
],
|
|
42
|
+
"keywords": [
|
|
43
|
+
"plantuml",
|
|
44
|
+
"mermaid",
|
|
45
|
+
"uml",
|
|
46
|
+
"drawio",
|
|
47
|
+
"mddocs",
|
|
48
|
+
"md",
|
|
49
|
+
"jsdoc",
|
|
50
|
+
"doc",
|
|
51
|
+
"docs",
|
|
52
|
+
"documentation",
|
|
53
|
+
"ci/cd",
|
|
54
|
+
"ci",
|
|
55
|
+
"cd",
|
|
56
|
+
"template",
|
|
57
|
+
"typescript",
|
|
58
|
+
"ts"
|
|
59
|
+
],
|
|
60
|
+
"author": "Tiago Venceslau",
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/decaf-ts/ts-workspace/issues"
|
|
64
|
+
},
|
|
65
|
+
"homepage": "https://github.com/decaf-ts/ts-workspace#readme",
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@types/jest": "^29.5.12",
|
|
68
|
+
"@typescript-eslint/eslint-plugin": "^7.1.1",
|
|
69
|
+
"clean-publish": "^4.3.0",
|
|
70
|
+
"eslint": "^8.57.0",
|
|
71
|
+
"eslint-config-prettier": "^9.1.0",
|
|
72
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
73
|
+
"gulp": "^4.0.2",
|
|
74
|
+
"gulp-if": "^3.0.0",
|
|
75
|
+
"gulp-rename": "^2.0.0",
|
|
76
|
+
"gulp-replace": "^1.1.4",
|
|
77
|
+
"gulp-run-command": "^0.0.10",
|
|
78
|
+
"gulp-sourcemaps": "^3.0.0",
|
|
79
|
+
"gulp-typescript": "^6.0.0-alpha.1",
|
|
80
|
+
"gulp-uglify": "^3.0.2",
|
|
81
|
+
"jest": "^29.7.0",
|
|
82
|
+
"jest-coverage-badges": "^1.1.2",
|
|
83
|
+
"jest-junit": "^16.0.0",
|
|
84
|
+
"jsdoc": "^4.0.2",
|
|
85
|
+
"jsdoc-mermaid": "^1.0.0",
|
|
86
|
+
"markdown-include": "^0.4.3",
|
|
87
|
+
"merge-stream": "^2.0.0",
|
|
88
|
+
"nodemon": "^3.1.0",
|
|
89
|
+
"npm-check-updates": "^16.14.15",
|
|
90
|
+
"prettier": "^3.2.5",
|
|
91
|
+
"rimraf": "^5.0.5",
|
|
92
|
+
"ts-jest": "^29.1.2",
|
|
93
|
+
"ts-loader": "^9.5.1",
|
|
94
|
+
"ts-node": "^10.9.2",
|
|
95
|
+
"typescript": "^5.4.2",
|
|
96
|
+
"vinyl-named": "^1.1.0",
|
|
97
|
+
"webpack-stream": "^7.0.0"
|
|
98
|
+
},
|
|
99
|
+
"peerDependencies": {
|
|
100
|
+
"@decaf-ts/db-decorators": "latest",
|
|
101
|
+
"@decaf-ts/decorator-validation": "latest",
|
|
102
|
+
"@decaf-ts/injectable-decorators": "latest",
|
|
103
|
+
"@decaf-ts/reflection": "latest",
|
|
104
|
+
"reflect-metadata": "^0.2.1"
|
|
105
|
+
}
|
|
106
|
+
}
|