@stancer/stancer 1.0.0 → 1.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/CHANGELOG.md +17 -0
- package/dist/address/api-endpoint.d.ts +20 -0
- package/dist/address/api-endpoint.d.ts.map +1 -0
- package/dist/address/api-endpoint.js +28 -0
- package/dist/address/api-endpoint.js.map +1 -0
- package/dist/address/model.d.ts +35 -0
- package/dist/address/model.d.ts.map +1 -0
- package/dist/address/model.js +63 -0
- package/dist/address/model.js.map +1 -0
- package/dist/address/repository.d.ts +7 -0
- package/dist/address/repository.d.ts.map +1 -0
- package/dist/address/repository.js +14 -0
- package/dist/address/repository.js.map +1 -0
- package/dist/address/validator.d.ts +4 -0
- package/dist/address/validator.d.ts.map +1 -0
- package/dist/address/validator.js +32 -0
- package/dist/address/validator.js.map +1 -0
- package/dist/api-endpoint/abstract-api-endpoint.d.ts +46 -0
- package/dist/api-endpoint/abstract-api-endpoint.d.ts.map +1 -0
- package/dist/api-endpoint/abstract-api-endpoint.js +220 -0
- package/dist/api-endpoint/abstract-api-endpoint.js.map +1 -0
- package/dist/api-endpoint/configuration.d.ts +34 -0
- package/dist/api-endpoint/configuration.d.ts.map +1 -0
- package/dist/api-endpoint/configuration.js +99 -0
- package/dist/api-endpoint/configuration.js.map +1 -0
- package/dist/api-endpoint/http/fetch-http-client.d.ts +3 -0
- package/dist/api-endpoint/http/fetch-http-client.d.ts.map +1 -0
- package/dist/api-endpoint/http/fetch-http-client.js +28 -0
- package/dist/api-endpoint/http/fetch-http-client.js.map +1 -0
- package/dist/api-endpoint/http/http.d.ts +18 -0
- package/dist/api-endpoint/http/http.d.ts.map +1 -0
- package/dist/api-endpoint/http/http.js +47 -0
- package/dist/api-endpoint/http/http.js.map +1 -0
- package/dist/api-endpoint/http/index.d.ts +3 -0
- package/dist/api-endpoint/http/index.d.ts.map +1 -0
- package/dist/api-endpoint/http/index.js +3 -0
- package/dist/api-endpoint/http/index.js.map +1 -0
- package/dist/api-endpoint/version.d.ts +5 -0
- package/dist/api-endpoint/version.d.ts.map +1 -0
- package/dist/api-endpoint/version.js +6 -0
- package/dist/api-endpoint/version.js.map +1 -0
- package/dist/card/api-endpoint.d.ts +28 -0
- package/dist/card/api-endpoint.d.ts.map +1 -0
- package/dist/card/api-endpoint.js +37 -0
- package/dist/card/api-endpoint.js.map +1 -0
- package/dist/card/enum/funding.d.ts +3 -0
- package/dist/card/enum/funding.d.ts.map +1 -0
- package/dist/card/enum/funding.js +10 -0
- package/dist/card/enum/funding.js.map +1 -0
- package/dist/card/enum/nature.d.ts +3 -0
- package/dist/card/enum/nature.d.ts.map +1 -0
- package/dist/card/enum/nature.js +6 -0
- package/dist/card/enum/nature.js.map +1 -0
- package/dist/card/enum/network.d.ts +5 -0
- package/dist/card/enum/network.d.ts.map +1 -0
- package/dist/card/enum/network.js +12 -0
- package/dist/card/enum/network.js.map +1 -0
- package/dist/card/model.d.ts +55 -0
- package/dist/card/model.d.ts.map +1 -0
- package/dist/card/model.js +90 -0
- package/dist/card/model.js.map +1 -0
- package/dist/card/repository.d.ts +7 -0
- package/dist/card/repository.d.ts.map +1 -0
- package/dist/card/repository.js +10 -0
- package/dist/card/repository.js.map +1 -0
- package/dist/card/validator.d.ts +8 -0
- package/dist/card/validator.d.ts.map +1 -0
- package/dist/card/validator.js +71 -0
- package/dist/card/validator.js.map +1 -0
- package/dist/core/abstract-model.d.ts +51 -0
- package/dist/core/abstract-model.d.ts.map +1 -0
- package/dist/core/abstract-model.js +93 -0
- package/dist/core/abstract-model.js.map +1 -0
- package/dist/core/abstract-repository.d.ts +86 -0
- package/dist/core/abstract-repository.d.ts.map +1 -0
- package/dist/core/abstract-repository.js +97 -0
- package/dist/core/abstract-repository.js.map +1 -0
- package/dist/core/common/branded-type.d.ts +6 -0
- package/dist/core/common/branded-type.d.ts.map +1 -0
- package/dist/core/common/branded-type.js +9 -0
- package/dist/core/common/branded-type.js.map +1 -0
- package/dist/core/common/handler/date-handler.d.ts +5 -0
- package/dist/core/common/handler/date-handler.d.ts.map +1 -0
- package/dist/core/common/handler/date-handler.js +23 -0
- package/dist/core/common/handler/date-handler.js.map +1 -0
- package/dist/core/common/handler/enum-handler.d.ts +3 -0
- package/dist/core/common/handler/enum-handler.d.ts.map +1 -0
- package/dist/core/common/handler/enum-handler.js +14 -0
- package/dist/core/common/handler/enum-handler.js.map +1 -0
- package/dist/core/common/handler/handler.d.ts +24 -0
- package/dist/core/common/handler/handler.d.ts.map +1 -0
- package/dist/core/common/handler/handler.js +33 -0
- package/dist/core/common/handler/handler.js.map +1 -0
- package/dist/core/common/handler/id-handler.d.ts +4 -0
- package/dist/core/common/handler/id-handler.d.ts.map +1 -0
- package/dist/core/common/handler/id-handler.js +21 -0
- package/dist/core/common/handler/id-handler.js.map +1 -0
- package/dist/core/common/id-validator.d.ts +10 -0
- package/dist/core/common/id-validator.d.ts.map +1 -0
- package/dist/core/common/id-validator.js +17 -0
- package/dist/core/common/id-validator.js.map +1 -0
- package/dist/core/common/mutation-tracked-object.d.ts +8 -0
- package/dist/core/common/mutation-tracked-object.d.ts.map +1 -0
- package/dist/core/common/mutation-tracked-object.js +38 -0
- package/dist/core/common/mutation-tracked-object.js.map +1 -0
- package/dist/core/endpoint-interface.d.ts +38 -0
- package/dist/core/endpoint-interface.d.ts.map +1 -0
- package/dist/core/endpoint-interface.js +2 -0
- package/dist/core/endpoint-interface.js.map +1 -0
- package/dist/core/error/base-error.d.ts +3 -0
- package/dist/core/error/base-error.d.ts.map +1 -0
- package/dist/core/error/base-error.js +3 -0
- package/dist/core/error/base-error.js.map +1 -0
- package/dist/core/error/endpoint/api/api-conflict-error.d.ts +5 -0
- package/dist/core/error/endpoint/api/api-conflict-error.d.ts.map +1 -0
- package/dist/core/error/endpoint/api/api-conflict-error.js +7 -0
- package/dist/core/error/endpoint/api/api-conflict-error.js.map +1 -0
- package/dist/core/error/endpoint/api/api-error.d.ts +6 -0
- package/dist/core/error/endpoint/api/api-error.d.ts.map +1 -0
- package/dist/core/error/endpoint/api/api-error.js +9 -0
- package/dist/core/error/endpoint/api/api-error.js.map +1 -0
- package/dist/core/error/endpoint/api/api-not-found-error.d.ts +5 -0
- package/dist/core/error/endpoint/api/api-not-found-error.d.ts.map +1 -0
- package/dist/core/error/endpoint/api/api-not-found-error.js +7 -0
- package/dist/core/error/endpoint/api/api-not-found-error.js.map +1 -0
- package/dist/core/error/endpoint/api/api-unauthorized-error.d.ts +5 -0
- package/dist/core/error/endpoint/api/api-unauthorized-error.d.ts.map +1 -0
- package/dist/core/error/endpoint/api/api-unauthorized-error.js +7 -0
- package/dist/core/error/endpoint/api/api-unauthorized-error.js.map +1 -0
- package/dist/core/error/endpoint/api/api-unknown-error.d.ts +5 -0
- package/dist/core/error/endpoint/api/api-unknown-error.d.ts.map +1 -0
- package/dist/core/error/endpoint/api/api-unknown-error.js +7 -0
- package/dist/core/error/endpoint/api/api-unknown-error.js.map +1 -0
- package/dist/core/error/endpoint/api/api-validation-error.d.ts +11 -0
- package/dist/core/error/endpoint/api/api-validation-error.d.ts.map +1 -0
- package/dist/core/error/endpoint/api/api-validation-error.js +9 -0
- package/dist/core/error/endpoint/api/api-validation-error.js.map +1 -0
- package/dist/core/error/endpoint/api/index.d.ts +7 -0
- package/dist/core/error/endpoint/api/index.d.ts.map +1 -0
- package/dist/core/error/endpoint/api/index.js +7 -0
- package/dist/core/error/endpoint/api/index.js.map +1 -0
- package/dist/core/error/endpoint/route-inaccessible-error.d.ts +5 -0
- package/dist/core/error/endpoint/route-inaccessible-error.d.ts.map +1 -0
- package/dist/core/error/endpoint/route-inaccessible-error.js +8 -0
- package/dist/core/error/endpoint/route-inaccessible-error.js.map +1 -0
- package/dist/core/error/unpopulated-error.d.ts +4 -0
- package/dist/core/error/unpopulated-error.d.ts.map +1 -0
- package/dist/core/error/unpopulated-error.js +4 -0
- package/dist/core/error/unpopulated-error.js.map +1 -0
- package/dist/core/error/unsendable-error.d.ts +4 -0
- package/dist/core/error/unsendable-error.d.ts.map +1 -0
- package/dist/core/error/unsendable-error.js +4 -0
- package/dist/core/error/unsendable-error.js.map +1 -0
- package/dist/core/error/validation-error.d.ts +4 -0
- package/dist/core/error/validation-error.d.ts.map +1 -0
- package/dist/core/error/validation-error.js +4 -0
- package/dist/core/error/validation-error.js.map +1 -0
- package/dist/core/validator.d.ts +63 -0
- package/dist/core/validator.d.ts.map +1 -0
- package/dist/core/validator.js +73 -0
- package/dist/core/validator.js.map +1 -0
- package/dist/customer/api-endpoint.d.ts +21 -0
- package/dist/customer/api-endpoint.d.ts.map +1 -0
- package/dist/customer/api-endpoint.js +27 -0
- package/dist/customer/api-endpoint.js.map +1 -0
- package/dist/customer/model.d.ts +39 -0
- package/dist/customer/model.d.ts.map +1 -0
- package/dist/customer/model.js +73 -0
- package/dist/customer/model.js.map +1 -0
- package/dist/customer/repository.d.ts +7 -0
- package/dist/customer/repository.d.ts.map +1 -0
- package/dist/customer/repository.js +10 -0
- package/dist/customer/repository.js.map +1 -0
- package/dist/customer/validator.d.ts +4 -0
- package/dist/customer/validator.d.ts.map +1 -0
- package/dist/customer/validator.js +23 -0
- package/dist/customer/validator.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +2 -0
- package/dist/main.js.map +1 -0
- package/dist/payment/api-endpoint.d.ts +51 -0
- package/dist/payment/api-endpoint.d.ts.map +1 -0
- package/dist/payment/api-endpoint.js +110 -0
- package/dist/payment/api-endpoint.js.map +1 -0
- package/dist/payment/enum/currency.d.ts +3 -0
- package/dist/payment/enum/currency.d.ts.map +1 -0
- package/dist/payment/enum/currency.js +13 -0
- package/dist/payment/enum/currency.js.map +1 -0
- package/dist/payment/enum/method.d.ts +3 -0
- package/dist/payment/enum/method.d.ts.map +1 -0
- package/dist/payment/enum/method.js +2 -0
- package/dist/payment/enum/method.js.map +1 -0
- package/dist/payment/enum/status.d.ts +4 -0
- package/dist/payment/enum/status.d.ts.map +1 -0
- package/dist/payment/enum/status.js +19 -0
- package/dist/payment/enum/status.js.map +1 -0
- package/dist/payment/model.d.ts +135 -0
- package/dist/payment/model.d.ts.map +1 -0
- package/dist/payment/model.js +232 -0
- package/dist/payment/model.js.map +1 -0
- package/dist/payment/repository.d.ts +17 -0
- package/dist/payment/repository.d.ts.map +1 -0
- package/dist/payment/repository.js +56 -0
- package/dist/payment/repository.js.map +1 -0
- package/dist/payment/validator.d.ts +16 -0
- package/dist/payment/validator.d.ts.map +1 -0
- package/dist/payment/validator.js +81 -0
- package/dist/payment/validator.js.map +1 -0
- package/dist/payment-intent/api-endpoint.d.ts +48 -0
- package/dist/payment-intent/api-endpoint.d.ts.map +1 -0
- package/dist/payment-intent/api-endpoint.js +94 -0
- package/dist/payment-intent/api-endpoint.js.map +1 -0
- package/dist/payment-intent/enum/status.d.ts +5 -0
- package/dist/payment-intent/enum/status.d.ts.map +1 -0
- package/dist/payment-intent/enum/status.js +20 -0
- package/dist/payment-intent/enum/status.js.map +1 -0
- package/dist/payment-intent/enum/threeds.d.ts +3 -0
- package/dist/payment-intent/enum/threeds.d.ts.map +1 -0
- package/dist/payment-intent/enum/threeds.js +2 -0
- package/dist/payment-intent/enum/threeds.js.map +1 -0
- package/dist/payment-intent/model.d.ts +90 -0
- package/dist/payment-intent/model.d.ts.map +1 -0
- package/dist/payment-intent/model.js +177 -0
- package/dist/payment-intent/model.js.map +1 -0
- package/dist/payment-intent/repository.d.ts +13 -0
- package/dist/payment-intent/repository.d.ts.map +1 -0
- package/dist/payment-intent/repository.js +65 -0
- package/dist/payment-intent/repository.js.map +1 -0
- package/dist/payment-intent/validator.d.ts +4 -0
- package/dist/payment-intent/validator.d.ts.map +1 -0
- package/dist/payment-intent/validator.js +38 -0
- package/dist/payment-intent/validator.js.map +1 -0
- package/dist/payout/model.d.ts +7 -0
- package/dist/payout/model.d.ts.map +1 -0
- package/dist/payout/model.js +6 -0
- package/dist/payout/model.js.map +1 -0
- package/dist/refund/api-endpoint.d.ts +22 -0
- package/dist/refund/api-endpoint.d.ts.map +1 -0
- package/dist/refund/api-endpoint.js +32 -0
- package/dist/refund/api-endpoint.js.map +1 -0
- package/dist/refund/enum/refund-status.d.ts +3 -0
- package/dist/refund/enum/refund-status.d.ts.map +1 -0
- package/dist/refund/enum/refund-status.js +10 -0
- package/dist/refund/enum/refund-status.js.map +1 -0
- package/dist/refund/model.d.ts +38 -0
- package/dist/refund/model.d.ts.map +1 -0
- package/dist/refund/model.js +51 -0
- package/dist/refund/model.js.map +1 -0
- package/dist/refund/repository.d.ts +7 -0
- package/dist/refund/repository.d.ts.map +1 -0
- package/dist/refund/repository.js +10 -0
- package/dist/refund/repository.js.map +1 -0
- package/dist/refund/validator.d.ts +4 -0
- package/dist/refund/validator.d.ts.map +1 -0
- package/dist/refund/validator.js +41 -0
- package/dist/refund/validator.js.map +1 -0
- package/dist/sepa/api-endpoint.d.ts +19 -0
- package/dist/sepa/api-endpoint.d.ts.map +1 -0
- package/dist/sepa/api-endpoint.js +25 -0
- package/dist/sepa/api-endpoint.js.map +1 -0
- package/dist/sepa/model.d.ts +32 -0
- package/dist/sepa/model.d.ts.map +1 -0
- package/dist/sepa/model.js +53 -0
- package/dist/sepa/model.js.map +1 -0
- package/dist/sepa/repository.d.ts +7 -0
- package/dist/sepa/repository.d.ts.map +1 -0
- package/dist/sepa/repository.js +10 -0
- package/dist/sepa/repository.js.map +1 -0
- package/dist/sepa/validator.d.ts +8 -0
- package/dist/sepa/validator.d.ts.map +1 -0
- package/dist/sepa/validator.js +47 -0
- package/dist/sepa/validator.js.map +1 -0
- package/package.json +7 -1
- package/reports/base.css +362 -0
- package/reports/block-navigation.js +75 -0
- package/reports/cobertura-coverage.xml +18 -0
- package/reports/favicon.png +0 -0
- package/reports/index.html +177 -0
- package/reports/junit.xml +25 -0
- package/reports/prettify.css +101 -0
- package/reports/prettify.js +955 -0
- package/reports/sort-arrow-sprite.png +0 -0
- package/reports/sorter.js +205 -0
- package/.editorconfig +0 -14
- package/.gitlab-ci.yml +0 -159
- package/.prettierignore +0 -3
- package/eslint.config.js +0 -14
- package/pnpm-workspace.yaml +0 -19
- package/prettier.config.js +0 -3
- package/tsconfig.json +0 -50
- package/vitest.config.ts +0 -20
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { IdValidator } from '#core/common/id-validator.js';
|
|
2
|
+
import { createdAtValidator, enumValidator, goldilocksValidator } from '#core/validator.js';
|
|
3
|
+
import { CustomerModel } from '../customer/model.js';
|
|
4
|
+
import { FundingCardEnum } from './enum/funding.js';
|
|
5
|
+
import { NatureCardEnum } from './enum/nature.js';
|
|
6
|
+
import { NetworkCardEnum, PreferredNetworkCardEnum } from './enum/network.js';
|
|
7
|
+
import { CardModel } from './model.js';
|
|
8
|
+
const expMonthValidator = {
|
|
9
|
+
validate: (arg0) => typeof arg0 === 'number' && arg0 > 0 && arg0 <= 12,
|
|
10
|
+
errorMessage: (value) => `${value} is not a month (between 1 and 12)`,
|
|
11
|
+
};
|
|
12
|
+
const expYearValidator = {
|
|
13
|
+
validate: (arg0) => typeof arg0 === 'number' && String(arg0).length === 4,
|
|
14
|
+
errorMessage: (value) => `${value} is not a correct year (must be 4 digits)`,
|
|
15
|
+
};
|
|
16
|
+
export const cardNumberValidator = {
|
|
17
|
+
validate: (arg0) => {
|
|
18
|
+
if (typeof arg0 !== 'string') {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const numb = arg0.replaceAll(/\s/g, '').replaceAll(/\D/g, '');
|
|
22
|
+
if (!numb) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const reversed = numb.split('').reverse();
|
|
26
|
+
const calc = (digit) => {
|
|
27
|
+
const number = digit * 2;
|
|
28
|
+
if (number < 10) {
|
|
29
|
+
return number;
|
|
30
|
+
}
|
|
31
|
+
const splited = String(number).split('');
|
|
32
|
+
return Number(splited[0]) + Number(splited[1]);
|
|
33
|
+
};
|
|
34
|
+
const sum = reversed.reduce((n, sum, index) => {
|
|
35
|
+
if (index % 2) {
|
|
36
|
+
return String(Number(n) + calc(Number(sum)));
|
|
37
|
+
}
|
|
38
|
+
return String(Number(n) + Number(sum));
|
|
39
|
+
}, '0');
|
|
40
|
+
if (Number(sum) % 10) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
},
|
|
45
|
+
errorMessage: (value) => `${value} is not a valid credit card number`,
|
|
46
|
+
};
|
|
47
|
+
export const cardValidator = {
|
|
48
|
+
id: IdValidator(CardModel.regex),
|
|
49
|
+
brand: true,
|
|
50
|
+
country: goldilocksValidator('country', { size: 2 }),
|
|
51
|
+
customer: IdValidator(CustomerModel.regex),
|
|
52
|
+
cvc: {
|
|
53
|
+
validate: (arg0) => /^\d{3}$/.test(arg0),
|
|
54
|
+
errorMessage: (value) => `${value} is not a valid CVC (must be 3 digits)`,
|
|
55
|
+
},
|
|
56
|
+
createdAt: createdAtValidator,
|
|
57
|
+
deleted: true,
|
|
58
|
+
expMonth: expMonthValidator,
|
|
59
|
+
expYear: expYearValidator,
|
|
60
|
+
externalId: goldilocksValidator('externalID', { min: 1, max: 36 }),
|
|
61
|
+
funding: enumValidator(FundingCardEnum, false),
|
|
62
|
+
last4: true,
|
|
63
|
+
name: goldilocksValidator('name', { min: 1, max: 64 }),
|
|
64
|
+
nature: enumValidator(NatureCardEnum, false),
|
|
65
|
+
network: enumValidator(NetworkCardEnum, false),
|
|
66
|
+
number: cardNumberValidator,
|
|
67
|
+
preferredNetwork: enumValidator(PreferredNetworkCardEnum),
|
|
68
|
+
tokenize: true,
|
|
69
|
+
zipCode: goldilocksValidator('zipCode', { min: 0, max: 8 }),
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/card/validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,O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,CAAC,KAAK,CAAC;IACtD,GAAG,EAAE;QACH,QAAQ,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;QAChD,YAAY,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,GAAG,KAAK,wCAAwC;KAClF;IACD,SAAS,EAAE,kBAAkB;IAC7B,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,iBAAiB;IAC3B,OAAO,EAAE,gBAAgB;IACzB,UAAU,EAAE,mBAAmB,CAAC,YAAY,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;IAClE,OAAO,EAAE,aAAa,CAAC,eAAe,EAAE,KAAK,CAAC;IAC9C,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,mBAAmB,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;IACtD,MAAM,EAAE,aAAa,CAAC,cAAc,EAAE,KAAK,CAAC;IAC5C,OAAO,EAAE,aAAa,CAAC,eAAe,EAAE,KAAK,CAAC;IAC9C,MAAM,EAAE,mBAAmB;IAC3B,gBAAgB,EAAE,aAAa,CAAC,wBAAwB,CAAC;IACzD,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,mBAAmB,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;CAC5D,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Temporal } from 'temporal-polyfill';
|
|
2
|
+
import { type ValidationFunction, type Validator } from '#core/validator.js';
|
|
3
|
+
import { IdValue } from './common/branded-type.js';
|
|
4
|
+
import { type MutationTrackedObject } from './common/mutation-tracked-object.js';
|
|
5
|
+
export interface ModelData {
|
|
6
|
+
createdAt: Temporal.Instant;
|
|
7
|
+
deleted: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface ModelType extends ModelData {
|
|
10
|
+
id: IdValue;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* All setters and getters of AbstractModel and their children will be inconsistent.
|
|
14
|
+
* This is intentional to help users use only the values accessible to them.
|
|
15
|
+
*/
|
|
16
|
+
export declare abstract class AbstractModel<Data extends ModelType> {
|
|
17
|
+
protected _data: MutationTrackedObject<Partial<Data>>;
|
|
18
|
+
protected _id: Data['id'] | undefined;
|
|
19
|
+
protected validator: ValidationFunction<Data>;
|
|
20
|
+
/**
|
|
21
|
+
* Construct a model object.
|
|
22
|
+
* Prefer using repository.create() instead of constructing it directly.
|
|
23
|
+
* @param validator - The validator function for this model
|
|
24
|
+
* @param id - Optional ID string or partial data object
|
|
25
|
+
*/
|
|
26
|
+
constructor(validator: Validator<Data>, id?: string | Partial<Data>);
|
|
27
|
+
/**
|
|
28
|
+
* Recreate a DataTrackObject with no mutations.
|
|
29
|
+
* Call when data has been synced and is no longer considered mutated.
|
|
30
|
+
* @param data - The data to be tracked
|
|
31
|
+
*/
|
|
32
|
+
dataTrackMutations(data: Partial<Data>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Date of creation of this model in our API.
|
|
35
|
+
* Alias: createdAt
|
|
36
|
+
*/
|
|
37
|
+
get created(): Temporal.Instant | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Date of creation of this model in our API.
|
|
40
|
+
* Alias: created
|
|
41
|
+
*/
|
|
42
|
+
get createdAt(): Temporal.Instant | undefined;
|
|
43
|
+
get deleted(): boolean | undefined;
|
|
44
|
+
get id(): Data['id'] | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Get mutated data.
|
|
47
|
+
* This is what will be sent to our endpoint.
|
|
48
|
+
*/
|
|
49
|
+
get mutations(): Partial<Partial<Data>>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=abstract-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-model.d.ts","sourceRoot":"","sources":["../../src/core/abstract-model.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AS,2BAEZ;CAGF"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { processValidator } from '#core/validator.js';
|
|
2
|
+
import { IdValue } from './common/branded-type.js';
|
|
3
|
+
import { trackObjectMutations } from './common/mutation-tracked-object.js';
|
|
4
|
+
//#endregion
|
|
5
|
+
/**
|
|
6
|
+
* All setters and getters of AbstractModel and their children will be inconsistent.
|
|
7
|
+
* This is intentional to help users use only the values accessible to them.
|
|
8
|
+
*/
|
|
9
|
+
export class AbstractModel {
|
|
10
|
+
//#region Properties
|
|
11
|
+
_data;
|
|
12
|
+
_id;
|
|
13
|
+
validator;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region Constructor
|
|
16
|
+
/**
|
|
17
|
+
* Construct a model object.
|
|
18
|
+
* Prefer using repository.create() instead of constructing it directly.
|
|
19
|
+
* @param validator - The validator function for this model
|
|
20
|
+
* @param id - Optional ID string or partial data object
|
|
21
|
+
*/
|
|
22
|
+
constructor(validator, id) {
|
|
23
|
+
this.validator = processValidator(validator);
|
|
24
|
+
this._data = trackObjectMutations({}, this.validator);
|
|
25
|
+
if (typeof id === 'object' && id !== null) {
|
|
26
|
+
const data = id;
|
|
27
|
+
const keys = Object.keys(data);
|
|
28
|
+
keys.forEach((key) => {
|
|
29
|
+
if (data[key] === undefined) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this.validator(key, data[key]);
|
|
33
|
+
this._data[key] = data[key];
|
|
34
|
+
});
|
|
35
|
+
this._id = data.id ?? undefined;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (id) {
|
|
39
|
+
const stringID = IdValue(id);
|
|
40
|
+
this.validator('id', stringID);
|
|
41
|
+
this._id = stringID;
|
|
42
|
+
this._data['id'] = this._id;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region Public Methods
|
|
47
|
+
/**
|
|
48
|
+
* Recreate a DataTrackObject with no mutations.
|
|
49
|
+
* Call when data has been synced and is no longer considered mutated.
|
|
50
|
+
* @param data - The data to be tracked
|
|
51
|
+
*/
|
|
52
|
+
dataTrackMutations(data) {
|
|
53
|
+
const keys = Object.keys(data);
|
|
54
|
+
keys.forEach((key) => {
|
|
55
|
+
if (data[key] === undefined) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.validator(key, data[key]);
|
|
59
|
+
});
|
|
60
|
+
this._id = data.id;
|
|
61
|
+
this._data = trackObjectMutations(data, this.validator);
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region Getters
|
|
65
|
+
/**
|
|
66
|
+
* Date of creation of this model in our API.
|
|
67
|
+
* Alias: createdAt
|
|
68
|
+
*/
|
|
69
|
+
get created() {
|
|
70
|
+
return this._data.createdAt;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Date of creation of this model in our API.
|
|
74
|
+
* Alias: created
|
|
75
|
+
*/
|
|
76
|
+
get createdAt() {
|
|
77
|
+
return this._data.createdAt;
|
|
78
|
+
}
|
|
79
|
+
get deleted() {
|
|
80
|
+
return this._data.deleted;
|
|
81
|
+
}
|
|
82
|
+
get id() {
|
|
83
|
+
return this._id;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get mutated data.
|
|
87
|
+
* This is what will be sent to our endpoint.
|
|
88
|
+
*/
|
|
89
|
+
get mutations() {
|
|
90
|
+
return this._data.getMutations();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=abstract-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-model.js","sourceRoot":"","sources":["../../src/core/abstract-model.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2C,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE/F,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAA8B,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAavG,YAAY;AAE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AEZ,wBAAwB;IAExB;;;;OAIG;IACI,kBAAkB,CAAC,IAAmB;QAC3C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAA4B,CAAC;QAC1D,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;gBAC5B,OAAO;YACT,CAAC;YACD,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,oBAAoB,CAAO,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAChE,CAAC;IAED,YAAY;IAEZ,iBAAiB;IAEjB;;;OAGG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;IAC9B,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;IAC5B,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED;;;OAGG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;IACnC,CAAC;CAGF"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Url } from 'url';
|
|
2
|
+
import type { AbstractModel, ModelType } from '#core/abstract-model.js';
|
|
3
|
+
import type { EndpointInterface, ListParams } from '#core/endpoint-interface.js';
|
|
4
|
+
import type { Validator } from '#core/validator.js';
|
|
5
|
+
import { IdValue } from './common/branded-type.js';
|
|
6
|
+
export type ModelGenerator<Data extends ModelType, CurrentModel extends AbstractModel<Data>, ReturnType = void> = AsyncGenerator<CurrentModel, ReturnType, CurrentModel>;
|
|
7
|
+
export interface Repository<Data extends ModelType, CurrentModel extends AbstractModel<Data>> {
|
|
8
|
+
/**
|
|
9
|
+
* Create a model or get it from the API if Id is given.
|
|
10
|
+
* @param id either the Id of the object or data to construct our model
|
|
11
|
+
* @returns the created model.
|
|
12
|
+
*/
|
|
13
|
+
create: (id?: Data['id'] | Partial<Data>) => Promise<CurrentModel>;
|
|
14
|
+
/**
|
|
15
|
+
* Get a model from the API
|
|
16
|
+
* @param id The id of the model
|
|
17
|
+
* @returns the model from the API whose id is the given id
|
|
18
|
+
*/
|
|
19
|
+
get: (id: IdValue) => Promise<CurrentModel>;
|
|
20
|
+
/**
|
|
21
|
+
* Delete a model in API
|
|
22
|
+
* @param model the model to be deleted
|
|
23
|
+
* @returns the deleted model
|
|
24
|
+
*/
|
|
25
|
+
delete: (model: CurrentModel) => Promise<CurrentModel>;
|
|
26
|
+
/**
|
|
27
|
+
* Send a model in the API
|
|
28
|
+
* if The model has Id it will try to patch otherwise it will try to send.
|
|
29
|
+
* @param model the model to be sent
|
|
30
|
+
* @returns the sent model with data populated.
|
|
31
|
+
*/
|
|
32
|
+
send: (model: CurrentModel) => Promise<CurrentModel>;
|
|
33
|
+
/**
|
|
34
|
+
* List models.
|
|
35
|
+
* @param params listing parameters (start,limit,end...)
|
|
36
|
+
* @returns async generator of models
|
|
37
|
+
*/
|
|
38
|
+
list: (params?: ListParams, endpointUrl?: Url) => ModelGenerator<Data, CurrentModel>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Static model type definition
|
|
42
|
+
* Omit all the non static Method
|
|
43
|
+
*/
|
|
44
|
+
export interface StaticModel<Data extends ModelType> extends Omit<AbstractModel<Data>, 'id' | 'delete' | 'populate' | 'send' | 'mutations' | 'dataTrackMutations' | 'data' | 'created' | 'createdAt' | 'deleted'> {
|
|
45
|
+
new (validator: Validator<Data>, id: string | Partial<Data> | undefined): AbstractModel<Data>;
|
|
46
|
+
}
|
|
47
|
+
export interface RepositoryParameters<Data extends ModelType, Endpoint extends EndpointInterface<Data>> {
|
|
48
|
+
endpoint: Endpoint;
|
|
49
|
+
model: StaticModel<Data>;
|
|
50
|
+
validator: Validator<Data>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @remarks Type assertions (`as CurrentModel`) are used throughout this class
|
|
54
|
+
* due to TypeScript's limitation with abstract class constructors in generic
|
|
55
|
+
* contexts. The staticModel constructor returns AbstractModel<Data>, but we
|
|
56
|
+
* guarantee it's CurrentModel at runtime through proper inheritance.
|
|
57
|
+
*/
|
|
58
|
+
export declare abstract class AbstractRepository<Data extends ModelType, CurrentModel extends AbstractModel<Data>, Endpoint extends EndpointInterface<Data> = EndpointInterface<Data>> implements Repository<Data, CurrentModel> {
|
|
59
|
+
protected endpoint: Endpoint;
|
|
60
|
+
protected staticModel: StaticModel<Data>;
|
|
61
|
+
protected validator: Validator<Data>;
|
|
62
|
+
constructor({ endpoint, model, validator }: RepositoryParameters<Data, Endpoint>);
|
|
63
|
+
create(id?: Data['id'] | Partial<Data>): Promise<CurrentModel>;
|
|
64
|
+
/**
|
|
65
|
+
* Create a new model
|
|
66
|
+
* @param data initial data that will populate the model
|
|
67
|
+
* @returns a new model
|
|
68
|
+
*/
|
|
69
|
+
createNew(data?: Partial<Data>): CurrentModel;
|
|
70
|
+
delete(model: CurrentModel): Promise<CurrentModel>;
|
|
71
|
+
/**
|
|
72
|
+
* Get a model from the API
|
|
73
|
+
* @param id the Id of the model
|
|
74
|
+
* @returns the model got from the API
|
|
75
|
+
*/
|
|
76
|
+
get(id: IdValue): Promise<CurrentModel>;
|
|
77
|
+
list(params?: ListParams, endpointUrl?: Url): ModelGenerator<Data, CurrentModel>;
|
|
78
|
+
/**
|
|
79
|
+
* Send a model to the API only mutated fields will be sent.
|
|
80
|
+
*
|
|
81
|
+
* @param model the model whose data will be sent to the api
|
|
82
|
+
* @returns the model populated With data from the API
|
|
83
|
+
*/
|
|
84
|
+
send(model: CurrentModel): Promise<CurrentModel>;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=abstract-repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-repository.d.ts","sourceRoot":"","sources":["../../src/core/abstract-repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE/B,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,KAAK,EAAqB,iBAAiB,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACpG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAIpD,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAUnD,MAAM,MAAM,cAAc,CACxB,IAAI,SAAS,SAAS,EACtB,YAAY,SAAS,aAAa,CAAC,IAAI,CAAC,EACxC,UAAU,GAAG,IAAI,IACf,cAAc,CAAC,YAAY,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;AAE3D,MAAM,WAAW,UAAU,CAAC,IAAI,SAAS,SAAS,EAAE,YAAY,SAAS,aAAa,CAAC,IAAI,CAAC;IAC1F;;;;OAIG;IACH,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IACnE;;;;OAIG;IACH,GAAG,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5C;;;;OAIG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IACvD;;;;;OAKG;IACH,IAAI,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC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oB,CAAC,IAAI,EAAE,QAAQ,CAAC,EAI/E;IAEY,MAAM,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAM1E;IAED;;;;OAIG;IACI,SAAS,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,YAAY,CAEnD;IAEY,MAAM,CAAC,KAAK,EAAE,YAAY,yBAWtC;IAED;;;;OAIG;IACU,GAAG,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAQnD;IAEM,IAAI,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,GAAG,GAAG,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,CAItF;IAED;;;;;OAKG;IACU,IAAI,CAAC,KAAK,EAAE,YAAY,yBAgBpC;CACF"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { StancerError } from '#error/base-error.js';
|
|
2
|
+
import { UnsendableError } from '#error/unsendable-error.js';
|
|
3
|
+
import { IdValue } from './common/branded-type.js';
|
|
4
|
+
const CustomIteratorMapper = {
|
|
5
|
+
map: (func, gen) => (async function* () {
|
|
6
|
+
let curr;
|
|
7
|
+
while (!(curr = await gen.next()).done) {
|
|
8
|
+
const populated = func(curr.value);
|
|
9
|
+
yield populated;
|
|
10
|
+
}
|
|
11
|
+
return;
|
|
12
|
+
})(),
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region Repository class
|
|
16
|
+
/**
|
|
17
|
+
* @remarks Type assertions (`as CurrentModel`) are used throughout this class
|
|
18
|
+
* due to TypeScript's limitation with abstract class constructors in generic
|
|
19
|
+
* contexts. The staticModel constructor returns AbstractModel<Data>, but we
|
|
20
|
+
* guarantee it's CurrentModel at runtime through proper inheritance.
|
|
21
|
+
*/
|
|
22
|
+
export class AbstractRepository {
|
|
23
|
+
endpoint;
|
|
24
|
+
staticModel;
|
|
25
|
+
validator;
|
|
26
|
+
constructor({ endpoint, model, validator }) {
|
|
27
|
+
this.endpoint = endpoint;
|
|
28
|
+
this.staticModel = model;
|
|
29
|
+
this.validator = validator;
|
|
30
|
+
}
|
|
31
|
+
async create(id) {
|
|
32
|
+
if (typeof id === 'string') {
|
|
33
|
+
return this.get(IdValue(id));
|
|
34
|
+
}
|
|
35
|
+
return this.createNew(id);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create a new model
|
|
39
|
+
* @param data initial data that will populate the model
|
|
40
|
+
* @returns a new model
|
|
41
|
+
*/
|
|
42
|
+
createNew(data) {
|
|
43
|
+
return new this.staticModel(this.validator, data);
|
|
44
|
+
}
|
|
45
|
+
async delete(model) {
|
|
46
|
+
if (!model.id) {
|
|
47
|
+
throw new StancerError('could not delete the model, missing id');
|
|
48
|
+
}
|
|
49
|
+
const deletedData = await this.endpoint.delete(model.id);
|
|
50
|
+
if (deletedData) {
|
|
51
|
+
model.dataTrackMutations(deletedData);
|
|
52
|
+
}
|
|
53
|
+
return model;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get a model from the API
|
|
57
|
+
* @param id the Id of the model
|
|
58
|
+
* @returns the model got from the API
|
|
59
|
+
*/
|
|
60
|
+
async get(id) {
|
|
61
|
+
const model = new this.staticModel(this.validator, id);
|
|
62
|
+
const data = await this.endpoint.get(id);
|
|
63
|
+
if (data) {
|
|
64
|
+
model.dataTrackMutations(data);
|
|
65
|
+
}
|
|
66
|
+
return model;
|
|
67
|
+
}
|
|
68
|
+
async *list(params, endpointUrl) {
|
|
69
|
+
const generator = this.endpoint.list(params ?? {}, endpointUrl);
|
|
70
|
+
yield* CustomIteratorMapper.map((item) => this.createNew(item), generator);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Send a model to the API only mutated fields will be sent.
|
|
75
|
+
*
|
|
76
|
+
* @param model the model whose data will be sent to the api
|
|
77
|
+
* @returns the model populated With data from the API
|
|
78
|
+
*/
|
|
79
|
+
async send(model) {
|
|
80
|
+
try {
|
|
81
|
+
const newData = await this.endpoint.send(model.id, model.mutations);
|
|
82
|
+
if (!newData) {
|
|
83
|
+
return model;
|
|
84
|
+
}
|
|
85
|
+
model.dataTrackMutations(newData);
|
|
86
|
+
return model;
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
if (err instanceof UnsendableError) {
|
|
90
|
+
throw new UnsendableError(`${err.message} is required to send ${this.staticModel.name}`, { cause: err });
|
|
91
|
+
}
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
//# sourceMappingURL=abstract-repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-repository.js","sourceRoot":"","sources":["../../src/core/abstract-repository.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AA4EnD,MAAM,oBAAoB,GAAkC;IAC1D,GAAG,EAAE,CACH,IAA0C,EAC1C,GAA4B,EACQ,EAAE,CACtC,CAAC,KAAK,SAAS,CAAC;QACd,IAAI,IAAI,CAAC;QACT,OAAO,CAAC,CAAC,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YACvC,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnC,MAAM,SAAS,CAAC;QAClB,CAAC;QAED,OAAO;IACT,CAAC,CAAC,EAAE;CACP,CAAC;AAEF,YAAY;AAEZ,0BAA0B;AAE1B;;;;;GAKG;AACH,MAAM,OAAgB,kBAAkB;IAK5B,QAAQ,CAAW;IACnB,WAAW,C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,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAA;CAAE,CAAC;AAE1D,MAAM,MAAM,OAAO,CAAC,CAAC,GAAG,MAAM,IAAI,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;AAInD,eAAO,MAAM,OAAO,OAAQ,MAAM,KAAG,OAMpC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StancerValidationError } from '#error/validation-error.js';
|
|
2
|
+
const isId = (id) => Boolean(id);
|
|
3
|
+
export const IdValue = (id) => {
|
|
4
|
+
if (isId(id)) {
|
|
5
|
+
return id;
|
|
6
|
+
}
|
|
7
|
+
throw new StancerValidationError('not an ID');
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=branded-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branded-type.js","sourceRoot":"","sources":["../../../src/core/common/branded-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAMpE,MAAM,IAAI,GAAG,CAAC,EAAU,EAAiB,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAExD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,EAAU,EAAW,EAAE;IAC7C,IAAI,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;QACb,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,IAAI,sBAAsB,CAAC,WAAW,CAAC,CAAC;AAChD,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Temporal } from 'temporal-polyfill';
|
|
2
|
+
import { type AccessRight, type Handler } from './handler.js';
|
|
3
|
+
export declare const RFC9557Handler: (access: Partial<AccessRight>) => Handler<Temporal.PlainDate>;
|
|
4
|
+
export declare const timestampHandler: (access: Partial<AccessRight>, name?: string) => Handler<Temporal.Instant | undefined>;
|
|
5
|
+
//# sourceMappingURL=date-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-handler.d.ts","sourceRoot":"","sources":["../../../../src/core/common/handler/date-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,OAAO,EAAa,MAAM,cAAc,CAAC;AAKzE,eAAO,MAAM,cAAc,WAAY,OAAO,CAAC,WAAW,CAAC,KAAG,OAAO,CAAC,QAAQ,CAAC,SAAS,CAMvF,CAAC;AAEF,eAAO,MAAM,gBAAgB,WACnB,OAAO,CAAC,WAAW,CAAC,SACrB,MAAM,KACZ,OAAO,CAAC,QAAQ,CAAC,OAAO,GAAG,SAAS,CAYtC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Temporal } from 'temporal-polyfill';
|
|
2
|
+
import { setAccess } from './handler.js';
|
|
3
|
+
const isValidRfc9557String = (arg0) => typeof arg0 === 'string' && RegExp(/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/).test(arg0);
|
|
4
|
+
export const RFC9557Handler = (access) => {
|
|
5
|
+
return {
|
|
6
|
+
serialize: (arg0) => arg0.toString(),
|
|
7
|
+
deserialize: (arg0) => (isValidRfc9557String(arg0) ? Temporal.PlainDate.from(arg0) : undefined),
|
|
8
|
+
...setAccess(access),
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export const timestampHandler = (access, name) => {
|
|
12
|
+
const payloadName = name ? { payloadName: name } : {};
|
|
13
|
+
return {
|
|
14
|
+
serialize: (arg0) => (arg0 ? arg0.epochMilliseconds / 1000 : undefined),
|
|
15
|
+
deserialize: (arg0) => {
|
|
16
|
+
const timestamp = Number(arg0);
|
|
17
|
+
return isNaN(timestamp) ? undefined : Temporal.Instant.fromEpochMilliseconds(timestamp * 1000);
|
|
18
|
+
},
|
|
19
|
+
...setAccess(access),
|
|
20
|
+
...payloadName,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=date-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-handler.js","sourceRoot":"","sources":["../../../../src/core/common/handler/date-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAkC,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzE,MAAM,oBAAoB,GAAG,CAAC,IAAa,EAAkB,EAAE,CAC7D,OAAO,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,8BAA8B,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEhF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAA4B,EAA+B,EAAE;IAC1F,OAAO;QACL,SAAS,EAAE,CAAC,IAAwB,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE;QACxD,WAAW,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACxG,GAAG,SAAS,CAAC,MAAM,CAAC;KACrB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,MAA4B,EAC5B,IAAa,EAC0B,EAAE;IACzC,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAEtD,OAAO;QACL,SAAS,EAAE,CAAC,IAAkC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QACrG,WAAW,EAAE,CAAC,IAAa,EAAE,EAAE;YAC7B,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YAC/B,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,qBAAqB,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;QACjG,CAAC;QACD,GAAG,SAAS,CAAC,MAAM,CAAC;QACpB,GAAG,WAAW;KACf,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type AccessRight, type Handler } from './handler.js';
|
|
2
|
+
export declare const enumHandler: <Enum extends readonly string[]>(enumDeclaration: Enum, access?: Partial<AccessRight>) => Handler<(typeof enumDeclaration)[number]>;
|
|
3
|
+
//# sourceMappingURL=enum-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum-handler.d.ts","sourceRoot":"","sources":["../../../../src/core/common/handler/enum-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,OAAO,EAAa,MAAM,cAAc,CAAC;AAEzE,eAAO,MAAM,WAAW,GAAI,IAAI,SAAS,SAAS,MAAM,EAAE,mBACvC,IAAI,WACZ,OAAO,CAAC,WAAW,CAAC,KAC5B,OAAO,CAAC,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAY1C,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { setAccess } from './handler.js';
|
|
2
|
+
export const enumHandler = (enumDeclaration, access) => {
|
|
3
|
+
return {
|
|
4
|
+
deserialize: (arg0) => {
|
|
5
|
+
if (typeof arg0 === 'string' && enumDeclaration.includes(arg0)) {
|
|
6
|
+
return arg0;
|
|
7
|
+
}
|
|
8
|
+
return undefined;
|
|
9
|
+
},
|
|
10
|
+
serialize: (arg0) => arg0,
|
|
11
|
+
...setAccess(access ?? {}),
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=enum-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum-handler.js","sourceRoot":"","sources":["../../../../src/core/common/handler/enum-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzE,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,eAAqB,EACrB,MAA6B,EACc,EAAE;IAC7C,OAAO;QACL,WAAW,EAAE,CAAC,IAAa,EAAE,EAAE;YAC7B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC/D,OAAO,IAAwC,CAAC;YAClD,CAAC;YAED,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,SAAS,EAAE,CAAC,IAAsC,EAAE,EAAE,CAAC,IAAI;QAC3D,GAAG,SAAS,CAAC,MAAM,IAAI,EAAE,CAAC;KAC3B,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type AccessRight = {
|
|
2
|
+
gettable: boolean;
|
|
3
|
+
postable: boolean;
|
|
4
|
+
patchable: boolean;
|
|
5
|
+
postRequired: 'partial' | boolean;
|
|
6
|
+
patchRequired: 'partial' | boolean;
|
|
7
|
+
};
|
|
8
|
+
export type Serializer<SDKType> = {
|
|
9
|
+
deserialize: (arg0: unknown) => SDKType | undefined;
|
|
10
|
+
serialize: (arg0: SDKType) => unknown;
|
|
11
|
+
payloadName?: string;
|
|
12
|
+
};
|
|
13
|
+
export type Handler<SDKType> = AccessRight & Serializer<SDKType>;
|
|
14
|
+
export declare const defaultSerialize: <T>(value: T) => T;
|
|
15
|
+
export declare const defaultDeserialize: <T>(value: unknown, type: BasicType) => T | undefined;
|
|
16
|
+
export declare const useDefaultSerializer: <SDKType>(type: BasicType) => {
|
|
17
|
+
serialize: (value: SDKType) => SDKType;
|
|
18
|
+
deserialize: (value: unknown) => SDKType | undefined;
|
|
19
|
+
};
|
|
20
|
+
type BasicType = 'boolean' | 'string' | 'number' | 'array' | 'object';
|
|
21
|
+
export declare const defaultHandler: <SDKType>(type: BasicType, access?: Partial<AccessRight>) => Handler<SDKType>;
|
|
22
|
+
export declare const setAccess: ({ gettable, postable, patchable, postRequired, patchRequired, }: Partial<AccessRight>) => AccessRight;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../../src/core/common/handler/handler.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,SAAS,GAAG,OAAO,CAAC;IAClC,aAAa,EAAE,SAAS,GAAG,OAAO,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,OAAO,IAAI;IAChC,WAAW,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,GAAG,SAAS,CAAC;IACpD,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,OAAO,CAAC,OAAO,IAAI,WAAW,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;AAEjE,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,CAAC,MAAU,CAAC;AAEvD,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,OAAO,QAAQ,SAAS,KAAG,CAAC,GAAG,SAa3E,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,OAAO,QAAQ,SAAS;IAEzD,SAAS;IACT,WAAW,UAAU,OAAO;CAE/B,CAAC;AAEF,KAAK,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEtE,eAAO,MAAM,cAAc,GAAI,OAAO,QAAQ,SAAS,WAAW,OAAO,CAAC,WAAW,CAAC,KAAG,OAAO,CAAC,OAAO,CAKvG,CAAC;AAEF,eAAO,MAAM,SAAS,oEAMnB,OAAO,CAAC,WAAW,CAAC,KAAG,WAQzB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const defaultSerialize = (value) => value;
|
|
2
|
+
export const defaultDeserialize = (value, type) => {
|
|
3
|
+
if (value === undefined || value === null) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
const typeNarrowing = (value) => type === 'array' ? Array.isArray(value) : typeof value === type;
|
|
7
|
+
if (typeNarrowing(value)) {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
return undefined;
|
|
11
|
+
};
|
|
12
|
+
export const useDefaultSerializer = (type) => {
|
|
13
|
+
return {
|
|
14
|
+
serialize: defaultSerialize,
|
|
15
|
+
deserialize: (value) => defaultDeserialize(value, type),
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export const defaultHandler = (type, access) => {
|
|
19
|
+
return {
|
|
20
|
+
...useDefaultSerializer(type),
|
|
21
|
+
...setAccess(access ?? {}),
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export const setAccess = ({ gettable = true, postable = true, patchable = true, postRequired = false, patchRequired = false, }) => {
|
|
25
|
+
return {
|
|
26
|
+
gettable,
|
|
27
|
+
postable,
|
|
28
|
+
patchable,
|
|
29
|
+
postRequired,
|
|
30
|
+
patchRequired,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../../src/core/common/handler/handler.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAI,KAAQ,EAAE,EAAE,CAAC,KAAK,CAAC;AAEvD,MAAM,CAAC,MAAM,kBAAkB,G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Handler } from './handler.js';
|
|
3
|
+
export declare const IdHandler: <ID extends IdValue>(regex: RegExp, access?: Partial<AccessRight>) => Handler<ID>;
|
|
4
|
+
//# sourceMappingURL=id-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id-handler.d.ts","sourceRoot":"","sources":["../../../../src/core/common/handler/id-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,OAAO,EAA+B,MAAM,cAAc,CAAC;AAE3F,eAAO,MAAM,SAAS,GAAI,EAAE,SAAS,OAAO,SAAS,MAAM,WAAW,OAAO,CAAC,WAAW,CAAC,KAAG,OAAO,CAAC,EAAE,CAsBtG,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isValidID } from '../id-validator.js';
|
|
2
|
+
import { defaultSerialize, setAccess } from './handler.js';
|
|
3
|
+
export const IdHandler = (regex, access) => {
|
|
4
|
+
return {
|
|
5
|
+
deserialize: (id) => {
|
|
6
|
+
if (typeof id === 'string' && isValidID(id, regex)) {
|
|
7
|
+
return id;
|
|
8
|
+
}
|
|
9
|
+
if (typeof id === 'object' && id !== null && Object.hasOwn(id, 'id')) {
|
|
10
|
+
const data = id;
|
|
11
|
+
if (isValidID(data.id, regex)) {
|
|
12
|
+
return data.id;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
},
|
|
17
|
+
serialize: defaultSerialize,
|
|
18
|
+
...setAccess(access ?? { gettable: true, postable: false, patchable: false, postRequired: false, patchRequired: false }),
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=id-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id-handler.js","sourceRoot":"","sources":["../../../../src/core/common/handler/id-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAkC,gBAAgB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE3F,MAAM,CAAC,MAAM,SAAS,GAAG,CAAqB,KAAa,EAAE,MAA6B,EAAe,EAAE;IACzG,OAAO;QACL,WAAW,EAAE,CAAC,EAAW,EAAE,EAAE;YAC3B,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,SAAS,CAAK,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC;gBACvD,OAAO,EAAE,CAAC;YACZ,CAAC;YAED,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,KAAK,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC;gBACrE,MAAM,IAAI,GAAG,EAAoB,CAAC;gBAElC,IAAI,SAAS,CAAK,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC;oBAClC,OAAO,IAAI,CAAC,EAAE,CAAC;gBACjB,CAAC;YACH,CAAC;YAED,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,SAAS,EAAE,gBAAgB;QAC3B,GAAG,SAAS,CACV,MAAM,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,CAC3G;KACF,CAAC;AACJ,CAAC,CAAC"}
|