@antelopejs/interface-database-decorators 0.0.2
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 +190 -0
- package/README.md +42 -0
- package/dist/antelope.test.d.ts +2 -0
- package/dist/antelope.test.js +52 -0
- package/dist/antelope.test.js.map +1 -0
- package/dist/common.d.ts +22 -0
- package/dist/common.js +36 -0
- package/dist/common.js.map +1 -0
- package/dist/database.d.ts +2 -0
- package/dist/database.js +71 -0
- package/dist/database.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/model.d.ts +101 -0
- package/dist/model.js +161 -0
- package/dist/model.js.map +1 -0
- package/dist/modifiers/common.d.ts +87 -0
- package/dist/modifiers/common.js +370 -0
- package/dist/modifiers/common.js.map +1 -0
- package/dist/modifiers/encryption.d.ts +37 -0
- package/dist/modifiers/encryption.js +79 -0
- package/dist/modifiers/encryption.js.map +1 -0
- package/dist/modifiers/hash.d.ts +41 -0
- package/dist/modifiers/hash.js +54 -0
- package/dist/modifiers/hash.js.map +1 -0
- package/dist/modifiers/index.d.ts +4 -0
- package/dist/modifiers/index.js +21 -0
- package/dist/modifiers/index.js.map +1 -0
- package/dist/modifiers/localization.d.ts +43 -0
- package/dist/modifiers/localization.js +57 -0
- package/dist/modifiers/localization.js.map +1 -0
- package/dist/schema.d.ts +4 -0
- package/dist/schema.js +21 -0
- package/dist/schema.js.map +1 -0
- package/dist/table.d.ts +53 -0
- package/dist/table.js +63 -0
- package/dist/table.js.map +1 -0
- package/dist/tests/common.test.d.ts +1 -0
- package/dist/tests/common.test.js +52 -0
- package/dist/tests/common.test.js.map +1 -0
- package/dist/tests/database.test.d.ts +1 -0
- package/dist/tests/database.test.js +184 -0
- package/dist/tests/database.test.js.map +1 -0
- package/dist/tests/integration.test.d.ts +1 -0
- package/dist/tests/integration.test.js +399 -0
- package/dist/tests/integration.test.js.map +1 -0
- package/dist/tests/model.test.d.ts +1 -0
- package/dist/tests/model.test.js +186 -0
- package/dist/tests/model.test.js.map +1 -0
- package/dist/tests/modifiers/common.test.d.ts +1 -0
- package/dist/tests/modifiers/common.test.js +165 -0
- package/dist/tests/modifiers/common.test.js.map +1 -0
- package/dist/tests/modifiers/encryption.test.d.ts +1 -0
- package/dist/tests/modifiers/encryption.test.js +161 -0
- package/dist/tests/modifiers/encryption.test.js.map +1 -0
- package/dist/tests/modifiers/hash.test.d.ts +1 -0
- package/dist/tests/modifiers/hash.test.js +126 -0
- package/dist/tests/modifiers/hash.test.js.map +1 -0
- package/dist/tests/modifiers/localization.test.d.ts +1 -0
- package/dist/tests/modifiers/localization.test.js +175 -0
- package/dist/tests/modifiers/localization.test.js.map +1 -0
- package/dist/tests/schema.test.d.ts +1 -0
- package/dist/tests/schema.test.js +102 -0
- package/dist/tests/schema.test.js.map +1 -0
- package/dist/tests/table.test.d.ts +1 -0
- package/dist/tests/table.test.js +112 -0
- package/dist/tests/table.test.js.map +1 -0
- package/package.json +101 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type * as DatabaseDev from "@antelopejs/interface-database";
|
|
2
|
+
import { MixinSymbol, TwoWayModifier } from "./common";
|
|
3
|
+
type Options = {
|
|
4
|
+
/** Encryption algorithm (for supported algorithms refer to {@link createCipheriv}) */
|
|
5
|
+
algorithm?: string;
|
|
6
|
+
/** Encryption key. */
|
|
7
|
+
secretKey: string;
|
|
8
|
+
/** Initialization Vector size. */
|
|
9
|
+
ivSize?: number;
|
|
10
|
+
};
|
|
11
|
+
type Meta = Record<string, never>;
|
|
12
|
+
type LockedType = [ciphertext: string, iv: string, authTag?: string];
|
|
13
|
+
/**
|
|
14
|
+
* Encryption modifier. enables the use of {@link Encrypted} on table fields.
|
|
15
|
+
*
|
|
16
|
+
* These fields are stored encrypted in the database.
|
|
17
|
+
*/
|
|
18
|
+
export declare class EncryptionModifier extends TwoWayModifier<LockedType, [
|
|
19
|
+
], Meta, Options> {
|
|
20
|
+
readonly autolock = true;
|
|
21
|
+
lock(_locked_value: LockedType | undefined, value: unknown): LockedType;
|
|
22
|
+
readonly autounlock = true;
|
|
23
|
+
unlock([locked_value, iv_str, authTag]: LockedType): unknown;
|
|
24
|
+
unlockrequest(data: DatabaseDev.ValueProxy<LockedType>): DatabaseDev.ValueProxy<unknown>;
|
|
25
|
+
[MixinSymbol]: {
|
|
26
|
+
new (): {};
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Mark a Database Table class field as being encrypted.
|
|
31
|
+
*
|
|
32
|
+
* @note The Table class MUST incorporate the {@link EncryptionModifier} mixin.
|
|
33
|
+
*
|
|
34
|
+
* @param options Encryption options.
|
|
35
|
+
*/
|
|
36
|
+
export declare const Encrypted: (options: Options) => import("@antelopejs/interface-core/decorators").PropertyDecorator;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Encrypted = exports.EncryptionModifier = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const decorators_1 = require("@antelopejs/interface-core/decorators");
|
|
6
|
+
const common_1 = require("./common");
|
|
7
|
+
function date_encoder(key) {
|
|
8
|
+
return this[key] instanceof Date
|
|
9
|
+
? {
|
|
10
|
+
value: this[key].toUTCString(),
|
|
11
|
+
type: "Date",
|
|
12
|
+
}
|
|
13
|
+
: this[key];
|
|
14
|
+
}
|
|
15
|
+
function date_decoder(_key, value) {
|
|
16
|
+
return value !== null &&
|
|
17
|
+
typeof value === "object" &&
|
|
18
|
+
Object.keys(value).length === 2 &&
|
|
19
|
+
Object.keys(value).includes("type") &&
|
|
20
|
+
Object.keys(value).includes("value") &&
|
|
21
|
+
value.type === "Date"
|
|
22
|
+
? new Date(value.value)
|
|
23
|
+
: value;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Encryption modifier. enables the use of {@link Encrypted} on table fields.
|
|
27
|
+
*
|
|
28
|
+
* These fields are stored encrypted in the database.
|
|
29
|
+
*/
|
|
30
|
+
class EncryptionModifier extends common_1.TwoWayModifier {
|
|
31
|
+
autolock = true;
|
|
32
|
+
lock(_locked_value, value) {
|
|
33
|
+
const iv = (0, node_crypto_1.randomBytes)(this.options.ivSize || 16);
|
|
34
|
+
const cipher = (0, node_crypto_1.createCipheriv)(this.options.algorithm || "aes-256-gcm", this.options.secretKey, iv);
|
|
35
|
+
const encrypted = Buffer.concat([
|
|
36
|
+
cipher.update(JSON.stringify(value, date_encoder)),
|
|
37
|
+
cipher.final(),
|
|
38
|
+
]).toString("base64");
|
|
39
|
+
let authTag;
|
|
40
|
+
try {
|
|
41
|
+
authTag =
|
|
42
|
+
"getAuthTag" in cipher
|
|
43
|
+
? cipher.getAuthTag().toString("base64")
|
|
44
|
+
: undefined;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Ignore error if getAuthTag is not available
|
|
48
|
+
}
|
|
49
|
+
return [encrypted, iv.toString("base64"), authTag];
|
|
50
|
+
}
|
|
51
|
+
autounlock = true;
|
|
52
|
+
unlock([locked_value, iv_str, authTag]) {
|
|
53
|
+
const decipher = (0, node_crypto_1.createDecipheriv)(this.options.algorithm || "aes-256-gcm", this.options.secretKey, Buffer.from(iv_str, "base64"));
|
|
54
|
+
if ("setAuthTag" in decipher && authTag) {
|
|
55
|
+
decipher.setAuthTag(Buffer.from(authTag, "base64"));
|
|
56
|
+
}
|
|
57
|
+
return JSON.parse(Buffer.concat([
|
|
58
|
+
decipher.update(Buffer.from(locked_value, "base64")),
|
|
59
|
+
decipher.final(),
|
|
60
|
+
]).toString("utf8"), date_decoder);
|
|
61
|
+
}
|
|
62
|
+
unlockrequest(data) {
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
[common_1.MixinSymbol] = class {
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.EncryptionModifier = EncryptionModifier;
|
|
69
|
+
/**
|
|
70
|
+
* Mark a Database Table class field as being encrypted.
|
|
71
|
+
*
|
|
72
|
+
* @note The Table class MUST incorporate the {@link EncryptionModifier} mixin.
|
|
73
|
+
*
|
|
74
|
+
* @param options Encryption options.
|
|
75
|
+
*/
|
|
76
|
+
exports.Encrypted = (0, decorators_1.MakePropertyDecorator)((target, propertyKey, options) => {
|
|
77
|
+
(0, common_1.attachModifier)(target.constructor, EncryptionModifier, propertyKey, options);
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=encryption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.js","sourceRoot":"","sources":["../../src/modifiers/encryption.ts"],"names":[],"mappings":";;;AAAA,6CAMqB;AACrB,sEAA8E;AAE9E,qCAAuE;AAavE,SAAS,YAAY,CAAY,GAAW;IAC1C,OAAO,IAAI,CAAC,GAAG,CAAC,YAAY,IAAI;QAC9B,CAAC,CAAC;YACE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE;YAC9B,IAAI,EAAE,MAAM;SACb;QACH,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAChB,CAAC;AAED,SAAS,YAAY,CAAC,IAAY,EAAE,KAAU;IAC5C,OAAO,KAAK,KAAK,IAAI;QACnB,OAAO,KAAK,KAAK,QAAQ;QACzB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC;QAC/B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;QACnC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;QACpC,KAAK,CAAC,IAAI,KAAK,MAAM;QACrB,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;QACvB,CAAC,CAAC,KAAK,CAAC;AACZ,CAAC;AAED;;;;GAIG;AACH,MAAa,k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C1B,QAAS,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;QACrE,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,CACf,MAAM,CAAC,MAAM,CAAC;YACZ,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;YACpD,QAAQ,CAAC,KAAK,EAAE;SACjB,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EACnB,YAAY,CACF,CAAC;IACf,CAAC;IAEe,aAAa,CAC3B,IAAwC;QAExC,OAAO,IAAuC,CAAC;IACjD,CAAC;IAED,CAAC,oBAAW,CAAC,GAAG;KAAQ,CAAC;CAC1B;AAjED,gDAiEC;AAED;;;;;;GAMG;AACU,QAAA,SAAS,GAAG,IAAA,kCAAqB,EAC5C,CAAC,MAAM,EAAE,WAAW,EAAE,OAAgB,EAAE,EAAE;IACxC,IAAA,uBAAc,EACZ,MAAM,CAAC,WAAW,EAClB,kBAAkB,EAClB,WAAW,EACX,OAAO,CACR,CAAC;AACJ,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MixinSymbol, OneWayModifier } from "./common";
|
|
2
|
+
type Options = {
|
|
3
|
+
/** Hashing algorithm (for supported algorithms refer to {@link createHash}) */
|
|
4
|
+
algorithm?: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Hash modifier. enables the use of {@link Hashed} on table fields.
|
|
8
|
+
*
|
|
9
|
+
* Hashed fields only contain a hash of the inserted value.
|
|
10
|
+
* Because of this, you lose the ability to query the information directly.
|
|
11
|
+
* You can test equality using {@link testHash}
|
|
12
|
+
*/
|
|
13
|
+
export declare class HashModifier extends OneWayModifier<string | undefined, [
|
|
14
|
+
], {
|
|
15
|
+
salt?: string;
|
|
16
|
+
}, Options> {
|
|
17
|
+
readonly autolock = true;
|
|
18
|
+
lock(_locked_value: string | undefined, value: unknown): string | undefined;
|
|
19
|
+
[MixinSymbol]: {
|
|
20
|
+
new (): {
|
|
21
|
+
/**
|
|
22
|
+
* Test a value against the stored hash.
|
|
23
|
+
*
|
|
24
|
+
* @param field - Name of the field to test against.
|
|
25
|
+
* @param value - Value to hash and test.
|
|
26
|
+
*
|
|
27
|
+
* @returns Whether the new value is identical to the original or not.
|
|
28
|
+
*/
|
|
29
|
+
testHash<This extends {}, F extends keyof This>(this: This, field: F, value: This[F]): unknown;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Mark a Database Table class field as being hashed.
|
|
35
|
+
*
|
|
36
|
+
* @note The Table class MUST incorporate the {@link HashModifier} mixin.
|
|
37
|
+
*
|
|
38
|
+
* @param options Hash options.
|
|
39
|
+
*/
|
|
40
|
+
export declare const Hashed: (options?: Options | undefined) => import("@antelopejs/interface-core/decorators").PropertyDecorator;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Hashed = exports.HashModifier = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const decorators_1 = require("@antelopejs/interface-core/decorators");
|
|
6
|
+
const randomstring_1 = require("randomstring");
|
|
7
|
+
const common_1 = require("./common");
|
|
8
|
+
/**
|
|
9
|
+
* Hash modifier. enables the use of {@link Hashed} on table fields.
|
|
10
|
+
*
|
|
11
|
+
* Hashed fields only contain a hash of the inserted value.
|
|
12
|
+
* Because of this, you lose the ability to query the information directly.
|
|
13
|
+
* You can test equality using {@link testHash}
|
|
14
|
+
*/
|
|
15
|
+
class HashModifier extends common_1.OneWayModifier {
|
|
16
|
+
autolock = true;
|
|
17
|
+
lock(_locked_value, value) {
|
|
18
|
+
if (value === undefined) {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
if (!this.meta.salt) {
|
|
22
|
+
this.meta.salt = (0, randomstring_1.generate)();
|
|
23
|
+
}
|
|
24
|
+
return (0, node_crypto_1.createHash)(this.options.algorithm || "sha256")
|
|
25
|
+
.update(this.meta.salt)
|
|
26
|
+
.update(JSON.stringify(value))
|
|
27
|
+
.digest("base64");
|
|
28
|
+
}
|
|
29
|
+
[common_1.MixinSymbol] = class {
|
|
30
|
+
/**
|
|
31
|
+
* Test a value against the stored hash.
|
|
32
|
+
*
|
|
33
|
+
* @param field - Name of the field to test against.
|
|
34
|
+
* @param value - Value to hash and test.
|
|
35
|
+
*
|
|
36
|
+
* @returns Whether the new value is identical to the original or not.
|
|
37
|
+
*/
|
|
38
|
+
testHash(field, value) {
|
|
39
|
+
return (0, common_1.testValue)(this, field, value);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.HashModifier = HashModifier;
|
|
44
|
+
/**
|
|
45
|
+
* Mark a Database Table class field as being hashed.
|
|
46
|
+
*
|
|
47
|
+
* @note The Table class MUST incorporate the {@link HashModifier} mixin.
|
|
48
|
+
*
|
|
49
|
+
* @param options Hash options.
|
|
50
|
+
*/
|
|
51
|
+
exports.Hashed = (0, decorators_1.MakePropertyDecorator)((target, propertyKey, options) => {
|
|
52
|
+
(0, common_1.attachModifier)(target.constructor, HashModifier, propertyKey, options || {});
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/modifiers/hash.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AACzC,sEAA8E;AAC9E,+CAAwC;AACxC,qCAKkB;AAOlB;;;;;;GAMG;AACH,MAAa,YAAa,SAAQ,uBAKjC;IACiB,QAAQ,GAAG,IAAI,CAAC;IAEhB,IAAI,CAAC,aAAiC,EAAE,KAAc;QACpE,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACpB,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAA,uBAAQ,GAAE,CAAC;QAC9B,CAAC;QACD,OAAO,IAAA,wBAAU,EAAC,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,QAAQ,CAAC;aAClD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;aACtB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;aAC7B,MAAM,CAAC,QAAQ,CAAC,CAAC;IACtB,CAAC;IAED,CAAC,oBAAW,CAAC,GAAG;QACd;;;;;;;WAOG;QACH,QAAQ,CAEN,KAAQ,EACR,KAAc;YAEd,OAAO,IAAA,kBAAS,EAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QACvC,CAAC;KACF,CAAC;CACH;AAtCD,oCAsCC;AAED;;;;;;GAMG;AACU,QAAA,MAAM,GAAG,IAAA,kCAAqB,EACzC,CAAC,MAAM,EAAE,WAAW,EAAE,OAAiB,EAAE,EAAE;IACzC,IAAA,uBAAc,EACZ,MAAM,CAAC,WAAW,EAClB,YAAY,EACZ,WAAW,EACX,OAAO,IAAI,EAAE,CACd,CAAC;AACJ,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./encryption"), exports);
|
|
19
|
+
__exportStar(require("./hash"), exports);
|
|
20
|
+
__exportStar(require("./localization"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/modifiers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,+CAA6B;AAC7B,yCAAuB;AACvB,iDAA+B"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type * as DatabaseDev from "@antelopejs/interface-database";
|
|
2
|
+
import { ContainerModifier, MixinSymbol } from "./common";
|
|
3
|
+
type Options = {
|
|
4
|
+
/** Fallback locale to use when no value exists for the selected locale. */
|
|
5
|
+
fallbackLocale?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Localization modifier. enables the use of {@link Localized} on table fields.
|
|
9
|
+
*
|
|
10
|
+
* Localized fields contain multiple values (one for each language).
|
|
11
|
+
* Accessing a particular value is done by first calling {@link localize} on the Table class instance.
|
|
12
|
+
* This method is added through the mixin class.
|
|
13
|
+
*
|
|
14
|
+
* See {@link ContainerModifier} for the generic modifier.
|
|
15
|
+
*/
|
|
16
|
+
export declare class LocalizationModifier extends ContainerModifier<Record<string, never>, Options> {
|
|
17
|
+
unlock(locked_value: Record<string, unknown>, key: string): unknown;
|
|
18
|
+
unlockrequest(data: DatabaseDev.ValueProxy<Record<string, unknown>>, _meta: DatabaseDev.ValueProxy<Record<string, never>>, key: DatabaseDev.ValueProxyOrValue<string>): DatabaseDev.ValueProxy<unknown>;
|
|
19
|
+
[MixinSymbol]: {
|
|
20
|
+
new (): {
|
|
21
|
+
/**
|
|
22
|
+
* Specify which locale to use for accessing some or all localized fields.
|
|
23
|
+
*
|
|
24
|
+
* @param locale - Locale to use to unlock the field(s).
|
|
25
|
+
* @param fields - Field names to unlock. Picks from the fields of the object this function is mixed into.
|
|
26
|
+
*
|
|
27
|
+
* @returns `this`
|
|
28
|
+
*/
|
|
29
|
+
localize<This extends {
|
|
30
|
+
constructor: any;
|
|
31
|
+
}>(this: This, locale: string, fields?: Array<keyof This>): This;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Mark a Database Table class field as being localized.
|
|
37
|
+
*
|
|
38
|
+
* @note The Table class MUST incorporate the {@link LocalizationModifier} mixin.
|
|
39
|
+
*
|
|
40
|
+
* @param options Localization options.
|
|
41
|
+
*/
|
|
42
|
+
export declare const Localized: (options?: Options | undefined) => import("@antelopejs/interface-core/decorators").PropertyDecorator;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Localized = exports.LocalizationModifier = void 0;
|
|
4
|
+
const decorators_1 = require("@antelopejs/interface-core/decorators");
|
|
5
|
+
const common_1 = require("./common");
|
|
6
|
+
/**
|
|
7
|
+
* Localization modifier. enables the use of {@link Localized} on table fields.
|
|
8
|
+
*
|
|
9
|
+
* Localized fields contain multiple values (one for each language).
|
|
10
|
+
* Accessing a particular value is done by first calling {@link localize} on the Table class instance.
|
|
11
|
+
* This method is added through the mixin class.
|
|
12
|
+
*
|
|
13
|
+
* See {@link ContainerModifier} for the generic modifier.
|
|
14
|
+
*/
|
|
15
|
+
class LocalizationModifier extends common_1.ContainerModifier {
|
|
16
|
+
unlock(locked_value, key) {
|
|
17
|
+
const unlocked = super.unlock(locked_value, key);
|
|
18
|
+
if (unlocked !== undefined) {
|
|
19
|
+
return unlocked;
|
|
20
|
+
}
|
|
21
|
+
if (this.options.fallbackLocale) {
|
|
22
|
+
return super.unlock(locked_value, this.options.fallbackLocale);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
unlockrequest(data, _meta, key) {
|
|
26
|
+
if (this.options.fallbackLocale) {
|
|
27
|
+
return data.key(key).default(data.key(this.options.fallbackLocale));
|
|
28
|
+
}
|
|
29
|
+
return data.key(key);
|
|
30
|
+
}
|
|
31
|
+
[common_1.MixinSymbol] = class {
|
|
32
|
+
/**
|
|
33
|
+
* Specify which locale to use for accessing some or all localized fields.
|
|
34
|
+
*
|
|
35
|
+
* @param locale - Locale to use to unlock the field(s).
|
|
36
|
+
* @param fields - Field names to unlock. Picks from the fields of the object this function is mixed into.
|
|
37
|
+
*
|
|
38
|
+
* @returns `this`
|
|
39
|
+
*/
|
|
40
|
+
localize(locale, fields) {
|
|
41
|
+
(0, common_1.unlock)(this, LocalizationModifier, fields, locale);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.LocalizationModifier = LocalizationModifier;
|
|
47
|
+
/**
|
|
48
|
+
* Mark a Database Table class field as being localized.
|
|
49
|
+
*
|
|
50
|
+
* @note The Table class MUST incorporate the {@link LocalizationModifier} mixin.
|
|
51
|
+
*
|
|
52
|
+
* @param options Localization options.
|
|
53
|
+
*/
|
|
54
|
+
exports.Localized = (0, decorators_1.MakePropertyDecorator)((target, propertyKey, options) => {
|
|
55
|
+
(0, common_1.attachModifier)(target.constructor, LocalizationModifier, propertyKey, options || {});
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=localization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localization.js","sourceRoot":"","sources":["../../src/modifiers/localization.ts"],"names":[],"mappings":";;;AAAA,sEAA8E;AAE9E,qCAKkB;AAOlB;;;;;;;;GAQG;AACH,MAAa,oBAA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1
|
+
import { type Class, type ClassDecorator } from "@antelopejs/interface-core/decorators";
|
|
2
|
+
import type { Table } from "./table";
|
|
3
|
+
export declare const RegisterTable: (tableName: string, schemaName: string) => ClassDecorator<typeof Table>;
|
|
4
|
+
export declare function getTablesForSchema(schemaName: string): Record<string, Class<Table>> | undefined;
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegisterTable = void 0;
|
|
4
|
+
exports.getTablesForSchema = getTablesForSchema;
|
|
5
|
+
const decorators_1 = require("@antelopejs/interface-core/decorators");
|
|
6
|
+
const common_1 = require("./common");
|
|
7
|
+
const schemaTableRegistry = {};
|
|
8
|
+
exports.RegisterTable = (0, decorators_1.MakeClassDecorator)((target, tableName, schemaName) => {
|
|
9
|
+
const metadata = (0, common_1.getMetadata)(target, common_1.DatumStaticMetadata);
|
|
10
|
+
metadata.tableName = tableName;
|
|
11
|
+
metadata.schemaName = schemaName;
|
|
12
|
+
if (!(schemaName in schemaTableRegistry)) {
|
|
13
|
+
schemaTableRegistry[schemaName] = {};
|
|
14
|
+
}
|
|
15
|
+
schemaTableRegistry[schemaName][tableName] =
|
|
16
|
+
target;
|
|
17
|
+
});
|
|
18
|
+
function getTablesForSchema(schemaName) {
|
|
19
|
+
return schemaTableRegistry[schemaName];
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":";;;AA2BA,gDAIC;AA/BD,sEAI+C;AAC/C,qCAA4D;AAG5D,MAAM,mBAAmB,GAAiD,EAAE,CAAC;AAEhE,QAAA,aAAa,GAGU,IAAA,+BAAkB,EACpD,CAAC,MAAM,EAAE,SAAiB,EAAE,UAAkB,EAAE,EAAE;IAChD,MAAM,QAAQ,GAAG,IAAA,oBAAW,EAAC,MAAM,EAAE,4BAAmB,CAAC,CAAC;IAC1D,QAAQ,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;IAEjC,IAAI,CAAC,CAAC,UAAU,IAAI,mBAAmB,CAAC,EAAE,CAAC;QACzC,mBAAmB,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;IACvC,CAAC;IACD,mBAAmB,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC;QACxC,MAAiC,CAAC;AACtC,CAAC,CACF,CAAC;AAEF,SAAgB,kBAAkB,CAChC,UAAkB;IAElB,OAAO,mBAAmB,CAAC,UAAU,CAAC,CAAC;AACzC,CAAC"}
|
package/dist/table.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type ClassDecorator } from "@antelopejs/interface-core/decorators";
|
|
2
|
+
import { type Constructible } from "./common";
|
|
3
|
+
import { MixinSymbol, type MixinType } from "./modifiers/common";
|
|
4
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
5
|
+
export declare const TableMetaSymbol: unique symbol;
|
|
6
|
+
export declare const TableRefSymbol: unique symbol;
|
|
7
|
+
export type ExtractTableMeta<T> = T extends {
|
|
8
|
+
[TableMetaSymbol]: infer Meta;
|
|
9
|
+
} ? Meta extends object ? Meta : never : object;
|
|
10
|
+
export interface TableClass<Base = object, Args extends any[] = [], Meta extends object | undefined = undefined> {
|
|
11
|
+
new (...args: Args): {
|
|
12
|
+
_id: string;
|
|
13
|
+
} & Base & (Meta extends object ? {
|
|
14
|
+
[TableMetaSymbol]: Meta;
|
|
15
|
+
} : object);
|
|
16
|
+
with<This extends TableClass, T extends Constructible<{
|
|
17
|
+
[MixinSymbol]: Constructible;
|
|
18
|
+
}>[] = []>(this: This, ...other: T): TableClass<InstanceType<This> & UnionToIntersection<InstanceType<MixinType<InstanceType<T[number]>>>>, ConstructorParameters<This>, ExtractTableMeta<InstanceType<This>> | ExtractTableMeta<InstanceType<T[number]>>>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Database Table superclass
|
|
22
|
+
*/
|
|
23
|
+
export declare class Table {
|
|
24
|
+
_id: string;
|
|
25
|
+
/**
|
|
26
|
+
* Supplement the superclass with Modifier mixins.
|
|
27
|
+
*
|
|
28
|
+
* @param others List of Modifier mixin classes
|
|
29
|
+
* @returns New superclass
|
|
30
|
+
*/
|
|
31
|
+
static with<This extends typeof Table, T extends Constructible<{
|
|
32
|
+
[MixinSymbol]: Constructible;
|
|
33
|
+
}>[] = []>(this: This, ...others: T): TableClass<InstanceType<This> & UnionToIntersection<InstanceType<MixinType<InstanceType<T[number]>>>>, ConstructorParameters<This>, ExtractTableMeta<InstanceType<This>> | ExtractTableMeta<InstanceType<T[number]>>>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Database Table Index decorator.
|
|
37
|
+
*
|
|
38
|
+
* Available options:
|
|
39
|
+
* - `group`: Index name for multi-field indexes.
|
|
40
|
+
*
|
|
41
|
+
* @param options Options
|
|
42
|
+
*/
|
|
43
|
+
export declare const Index: (options?: {
|
|
44
|
+
group?: string;
|
|
45
|
+
} | undefined) => import("@antelopejs/interface-core/decorators").PropertyDecorator;
|
|
46
|
+
type AwaitableArray<T> = Promise<T | T[]> | T | T[];
|
|
47
|
+
/**
|
|
48
|
+
* Database Table class decorator to create default data on table creation.
|
|
49
|
+
*
|
|
50
|
+
* @param generator Data generator
|
|
51
|
+
*/
|
|
52
|
+
export declare const Fixture: <T extends typeof Table>(generator: (p: T) => AwaitableArray<Partial<InstanceType<T>>>) => ClassDecorator<T>;
|
|
53
|
+
export {};
|
package/dist/table.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Fixture = exports.Index = exports.Table = exports.TableRefSymbol = exports.TableMetaSymbol = void 0;
|
|
4
|
+
const decorators_1 = require("@antelopejs/interface-core/decorators");
|
|
5
|
+
const common_1 = require("./common");
|
|
6
|
+
const common_2 = require("./modifiers/common");
|
|
7
|
+
exports.TableMetaSymbol = Symbol();
|
|
8
|
+
exports.TableRefSymbol = Symbol();
|
|
9
|
+
/**
|
|
10
|
+
* Database Table superclass
|
|
11
|
+
*/
|
|
12
|
+
class Table {
|
|
13
|
+
/**
|
|
14
|
+
* Supplement the superclass with Modifier mixins.
|
|
15
|
+
*
|
|
16
|
+
* @param others List of Modifier mixin classes
|
|
17
|
+
* @returns New superclass
|
|
18
|
+
*/
|
|
19
|
+
static with(...others) {
|
|
20
|
+
// biome-ignore lint/complexity/noThisInStatic: intentional mixin pattern — this refers to the calling class
|
|
21
|
+
const c = class _internal_table extends this {
|
|
22
|
+
};
|
|
23
|
+
for (const mixin of others
|
|
24
|
+
.map((otherClass) => otherClass.prototype && new otherClass())
|
|
25
|
+
.map((other) => other?.[common_2.MixinSymbol])
|
|
26
|
+
.filter((mixin) => mixin?.prototype)) {
|
|
27
|
+
for (const key of Object.getOwnPropertyNames(mixin.prototype)) {
|
|
28
|
+
if (key !== "constructor" && !(key in c.prototype)) {
|
|
29
|
+
c.prototype[key] = mixin.prototype[key];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
for (const key of Object.getOwnPropertySymbols(mixin.prototype)) {
|
|
33
|
+
if (!(key in c.prototype)) {
|
|
34
|
+
c.prototype[key] = mixin.prototype[key];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return c;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.Table = Table;
|
|
42
|
+
/**
|
|
43
|
+
* Database Table Index decorator.
|
|
44
|
+
*
|
|
45
|
+
* Available options:
|
|
46
|
+
* - `group`: Index name for multi-field indexes.
|
|
47
|
+
*
|
|
48
|
+
* @param options Options
|
|
49
|
+
*/
|
|
50
|
+
exports.Index = (0, decorators_1.MakePropertyDecorator)((target, propertyKey, options) => {
|
|
51
|
+
const metadata = (0, common_1.getMetadata)(target.constructor, common_1.DatumStaticMetadata);
|
|
52
|
+
metadata.addIndex(propertyKey, options?.group || propertyKey);
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Database Table class decorator to create default data on table creation.
|
|
56
|
+
*
|
|
57
|
+
* @param generator Data generator
|
|
58
|
+
*/
|
|
59
|
+
exports.Fixture = (0, decorators_1.MakeClassDecorator)((target, generator) => {
|
|
60
|
+
const metadata = (0, common_1.getMetadata)(target, common_1.DatumStaticMetadata);
|
|
61
|
+
metadata.generator = generator;
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.js","sourceRoot":"","sources":["../src/table.ts"],"names":[],"mappings":";;;AAAA,sEAI+C;AAC/C,qCAAgF;AAChF,+CAAiE;AAQpD,QAAA,eAAe,GAAG,MAAM,EAAE,CAAC;AAC3B,QAAA,cAAc,GAAG,MAAM,EAAE,CAAC;AAgCvC;;GAEG;AACH,MAAa,KAAK;IAGhB;;;;;OAKG;IACI,MAAM,CAAC,IAAI,CAKhB,GAAG,MAAS;QAQZ,4GAA4G;QAC5G,MAAM,CAAC,GAAG,MAAM,eAAgB,SAAS,IAAY;SAAG,CAAC;QACzD,KAAK,MAAM,KAAK,IAAI,MAAM;aACvB,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,IAAI,IAAI,UAAU,EAAE,CAAC;aAC7D,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,oBAAW,CAAC,CAAC;aACpC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC;YACvC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC9D,IAAI,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3
|
+
const common_1 = require("@antelopejs/interface-database-decorators/common");
|
|
4
|
+
const chai_1 = require("chai");
|
|
5
|
+
describe("Common - metadata", () => {
|
|
6
|
+
it("creates metadata with default values", async () => CreateMetadataWithDefaultValuesTest());
|
|
7
|
+
it("adds index to metadata", async () => AddIndexToMetadataTest());
|
|
8
|
+
it("creates new metadata when not exists", async () => CreateNewMetadataWhenNotExistsTest());
|
|
9
|
+
it("retrieves existing metadata", async () => RetrieveExistingMetadataTest());
|
|
10
|
+
it("handles deep partial types correctly", async () => HandleDeepPartialTypesCorrectlyTest());
|
|
11
|
+
it("has schemaName undefined by default", async () => SchemaNameUndefinedByDefaultTest());
|
|
12
|
+
});
|
|
13
|
+
async function CreateMetadataWithDefaultValuesTest() {
|
|
14
|
+
const metadata = new common_1.DatumStaticMetadata();
|
|
15
|
+
(0, chai_1.expect)(metadata.primary).to.equal("_id");
|
|
16
|
+
(0, chai_1.expect)(metadata.indexes).to.deep.equal({});
|
|
17
|
+
(0, chai_1.expect)(metadata.generator).to.equal(undefined);
|
|
18
|
+
}
|
|
19
|
+
async function AddIndexToMetadataTest() {
|
|
20
|
+
const metadata = new common_1.DatumStaticMetadata();
|
|
21
|
+
metadata.addIndex("email", "user_search");
|
|
22
|
+
metadata.addIndex("name", "user_search");
|
|
23
|
+
(0, chai_1.expect)(metadata.indexes.user_search).to.deep.equal(["email", "name"]);
|
|
24
|
+
}
|
|
25
|
+
async function CreateNewMetadataWhenNotExistsTest() {
|
|
26
|
+
class TestClass {
|
|
27
|
+
}
|
|
28
|
+
const metadata = (0, common_1.getMetadata)(TestClass, common_1.DatumStaticMetadata);
|
|
29
|
+
(0, chai_1.expect)(metadata).to.be.instanceOf(common_1.DatumStaticMetadata);
|
|
30
|
+
(0, chai_1.expect)(metadata.primary).to.equal("_id");
|
|
31
|
+
}
|
|
32
|
+
async function RetrieveExistingMetadataTest() {
|
|
33
|
+
class TestClass {
|
|
34
|
+
}
|
|
35
|
+
const metadata1 = (0, common_1.getMetadata)(TestClass, common_1.DatumStaticMetadata);
|
|
36
|
+
const metadata2 = (0, common_1.getMetadata)(TestClass, common_1.DatumStaticMetadata);
|
|
37
|
+
(0, chai_1.expect)(metadata1).to.equal(metadata2);
|
|
38
|
+
}
|
|
39
|
+
async function HandleDeepPartialTypesCorrectlyTest() {
|
|
40
|
+
const _partial = {
|
|
41
|
+
name: "John",
|
|
42
|
+
address: {
|
|
43
|
+
street: "Main St",
|
|
44
|
+
},
|
|
45
|
+
hobbies: ["reading"],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async function SchemaNameUndefinedByDefaultTest() {
|
|
49
|
+
const metadata = new common_1.DatumStaticMetadata();
|
|
50
|
+
(0, chai_1.expect)(metadata.schemaName).to.equal(undefined);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=common.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.test.js","sourceRoot":"","sources":["../../src/tests/common.test.ts"],"names":[],"mappings":";;AAAA,6EAI0D;AAC1D,+BAA8B;AAE9B,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE,CACpD,mCAAmC,EAAE,CAAC,CAAC;IACzC,EAAE,CAAC,wBAAwB,EAAE,KAAK,IAAI,EAAE,CAAC,sBAAsB,EAAE,CAAC,CAAC;IACnE,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE,CACpD,kCAAkC,EAAE,CAAC,CAAC;IACxC,EAAE,CAAC,6BAA6B,EAAE,KAAK,IAAI,EAAE,CAAC,4BAA4B,EAAE,CAAC,CAAC;IAC9E,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE,CACpD,mCAAmC,EAAE,CAAC,CAAC;IACzC,EAAE,CAAC,qCAAqC,EAAE,KAAK,IAAI,EAAE,CACnD,gCAAgC,EAAE,CAAC,CAAC;AACxC,CAAC,CAAC,CAAC;AAEH,K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