@twin.org/core 0.0.1-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +29 -0
  3. package/dist/cjs/index.cjs +4221 -0
  4. package/dist/esm/index.mjs +4184 -0
  5. package/dist/types/encoding/base32.d.ts +18 -0
  6. package/dist/types/encoding/base64.d.ts +24 -0
  7. package/dist/types/encoding/base64Url.d.ts +18 -0
  8. package/dist/types/errors/alreadyExistsError.d.ts +18 -0
  9. package/dist/types/errors/baseError.d.ts +103 -0
  10. package/dist/types/errors/conflictError.d.ts +19 -0
  11. package/dist/types/errors/generalError.d.ts +20 -0
  12. package/dist/types/errors/guardError.d.ts +19 -0
  13. package/dist/types/errors/notFoundError.d.ts +18 -0
  14. package/dist/types/errors/notImplementedError.d.ts +16 -0
  15. package/dist/types/errors/notSupportedError.d.ts +17 -0
  16. package/dist/types/errors/unauthorizedError.d.ts +17 -0
  17. package/dist/types/errors/unprocessableError.d.ts +20 -0
  18. package/dist/types/errors/validationError.d.ts +18 -0
  19. package/dist/types/factories/componentFactory.d.ts +6 -0
  20. package/dist/types/factories/factory.d.ts +67 -0
  21. package/dist/types/helpers/arrayHelper.d.ts +12 -0
  22. package/dist/types/helpers/errorHelper.d.ts +24 -0
  23. package/dist/types/helpers/filenameHelper.d.ts +11 -0
  24. package/dist/types/helpers/hexHelper.d.ts +30 -0
  25. package/dist/types/helpers/jsonHelper.d.ts +29 -0
  26. package/dist/types/helpers/objectHelper.d.ts +74 -0
  27. package/dist/types/helpers/randomHelper.d.ts +11 -0
  28. package/dist/types/helpers/stringHelper.d.ts +90 -0
  29. package/dist/types/index.d.ts +46 -0
  30. package/dist/types/models/IComponent.d.ts +29 -0
  31. package/dist/types/models/IError.d.ts +31 -0
  32. package/dist/types/models/IKeyValue.d.ts +13 -0
  33. package/dist/types/models/ILabelledValue.d.ts +13 -0
  34. package/dist/types/models/ILocale.d.ts +13 -0
  35. package/dist/types/models/ILocaleDictionary.d.ts +6 -0
  36. package/dist/types/models/ILocalesIndex.d.ts +10 -0
  37. package/dist/types/models/IPatchOperation.d.ts +21 -0
  38. package/dist/types/models/IUrlParts.d.ts +29 -0
  39. package/dist/types/models/IValidationFailure.d.ts +23 -0
  40. package/dist/types/models/compressionType.d.ts +17 -0
  41. package/dist/types/types/bitString.d.ts +41 -0
  42. package/dist/types/types/url.d.ts +56 -0
  43. package/dist/types/types/urn.d.ts +93 -0
  44. package/dist/types/utils/asyncCache.d.ts +33 -0
  45. package/dist/types/utils/coerce.d.ts +61 -0
  46. package/dist/types/utils/compression.d.ts +20 -0
  47. package/dist/types/utils/converter.d.ts +85 -0
  48. package/dist/types/utils/guards.d.ts +190 -0
  49. package/dist/types/utils/i18n.d.ts +81 -0
  50. package/dist/types/utils/is.d.ts +205 -0
  51. package/dist/types/utils/validation.d.ts +245 -0
  52. package/docs/changelog.md +5 -0
  53. package/docs/examples.md +1 -0
  54. package/docs/reference/classes/AlreadyExistsError.md +375 -0
  55. package/docs/reference/classes/ArrayHelper.md +37 -0
  56. package/docs/reference/classes/AsyncCache.md +117 -0
  57. package/docs/reference/classes/Base32.md +57 -0
  58. package/docs/reference/classes/Base64.md +74 -0
  59. package/docs/reference/classes/Base64Url.md +54 -0
  60. package/docs/reference/classes/BaseError.md +344 -0
  61. package/docs/reference/classes/BitString.md +123 -0
  62. package/docs/reference/classes/Coerce.md +209 -0
  63. package/docs/reference/classes/Compression.md +61 -0
  64. package/docs/reference/classes/ConflictError.md +379 -0
  65. package/docs/reference/classes/Converter.md +285 -0
  66. package/docs/reference/classes/ErrorHelper.md +73 -0
  67. package/docs/reference/classes/Factory.md +221 -0
  68. package/docs/reference/classes/FilenameHelper.md +33 -0
  69. package/docs/reference/classes/GeneralError.md +375 -0
  70. package/docs/reference/classes/GuardError.md +379 -0
  71. package/docs/reference/classes/Guards.md +711 -0
  72. package/docs/reference/classes/HexHelper.md +97 -0
  73. package/docs/reference/classes/I18n.md +237 -0
  74. package/docs/reference/classes/Is.md +693 -0
  75. package/docs/reference/classes/JsonHelper.md +92 -0
  76. package/docs/reference/classes/NotFoundError.md +375 -0
  77. package/docs/reference/classes/NotImplementedError.md +367 -0
  78. package/docs/reference/classes/NotSupportedError.md +371 -0
  79. package/docs/reference/classes/ObjectHelper.md +287 -0
  80. package/docs/reference/classes/RandomHelper.md +33 -0
  81. package/docs/reference/classes/StringHelper.md +270 -0
  82. package/docs/reference/classes/UnauthorizedError.md +371 -0
  83. package/docs/reference/classes/UnprocessableError.md +375 -0
  84. package/docs/reference/classes/Url.md +167 -0
  85. package/docs/reference/classes/Urn.md +295 -0
  86. package/docs/reference/classes/Validation.md +821 -0
  87. package/docs/reference/classes/ValidationError.md +371 -0
  88. package/docs/reference/index.md +60 -0
  89. package/docs/reference/interfaces/IComponent.md +79 -0
  90. package/docs/reference/interfaces/IError.md +55 -0
  91. package/docs/reference/interfaces/IKeyValue.md +23 -0
  92. package/docs/reference/interfaces/ILabelledValue.md +23 -0
  93. package/docs/reference/interfaces/ILocale.md +19 -0
  94. package/docs/reference/interfaces/ILocaleDictionary.md +7 -0
  95. package/docs/reference/interfaces/ILocalesIndex.md +11 -0
  96. package/docs/reference/interfaces/IPatchOperation.md +35 -0
  97. package/docs/reference/interfaces/IUrlParts.md +51 -0
  98. package/docs/reference/interfaces/IValidationFailure.md +39 -0
  99. package/docs/reference/type-aliases/CompressionType.md +5 -0
  100. package/docs/reference/variables/ComponentFactory.md +5 -0
  101. package/docs/reference/variables/CompressionType.md +19 -0
  102. package/locales/en.json +98 -0
  103. package/package.json +65 -0
@@ -0,0 +1,51 @@
1
+ # Interface: IUrlParts
2
+
3
+ Model to describe the parts of a url.
4
+
5
+ ## Properties
6
+
7
+ ### schema
8
+
9
+ > **schema**: `string`
10
+
11
+ The schema for the url.
12
+
13
+ ***
14
+
15
+ ### host
16
+
17
+ > **host**: `string`
18
+
19
+ The host for the url.
20
+
21
+ ***
22
+
23
+ ### port?
24
+
25
+ > `optional` **port**: `number`
26
+
27
+ The port for the url.
28
+
29
+ ***
30
+
31
+ ### path
32
+
33
+ > **path**: `string`
34
+
35
+ The path for the url.
36
+
37
+ ***
38
+
39
+ ### params?
40
+
41
+ > `optional` **params**: `string`
42
+
43
+ The params for the url.
44
+
45
+ ***
46
+
47
+ ### hash?
48
+
49
+ > `optional` **hash**: `string`
50
+
51
+ The hash for the url.
@@ -0,0 +1,39 @@
1
+ # Interface: IValidationFailure
2
+
3
+ Interface describing the reason a validation failed.
4
+
5
+ ## Properties
6
+
7
+ ### property
8
+
9
+ > **property**: `string`
10
+
11
+ The property that failed validation.
12
+
13
+ ***
14
+
15
+ ### reason
16
+
17
+ > **reason**: `string`
18
+
19
+ The reason the validation failed as an i18 resource error.
20
+
21
+ ***
22
+
23
+ ### fieldName?
24
+
25
+ > `optional` **fieldName**: `string`
26
+
27
+ The optional human readable name for the field as an i18 resource.
28
+
29
+ ***
30
+
31
+ ### properties?
32
+
33
+ > `optional` **properties**: `object`
34
+
35
+ Additional properties for the validation failure.
36
+
37
+ #### Index Signature
38
+
39
+ \[`id`: `string`\]: `unknown`
@@ -0,0 +1,5 @@
1
+ # Type Alias: CompressionType
2
+
3
+ > **CompressionType**: *typeof* [`CompressionType`](../variables/CompressionType.md)\[keyof *typeof* [`CompressionType`](../variables/CompressionType.md)\]
4
+
5
+ Compression types.
@@ -0,0 +1,5 @@
1
+ # Variable: ComponentFactory
2
+
3
+ > `const` **ComponentFactory**: [`Factory`](../classes/Factory.md)\<[`IComponent`](../interfaces/IComponent.md)\>
4
+
5
+ Factory for creating implementation of component types.
@@ -0,0 +1,19 @@
1
+ # Variable: CompressionType
2
+
3
+ > `const` **CompressionType**: `object`
4
+
5
+ Compression types.
6
+
7
+ ## Type declaration
8
+
9
+ ### Gzip
10
+
11
+ > `readonly` **Gzip**: `"gzip"` = `"gzip"`
12
+
13
+ Gzip.
14
+
15
+ ### Deflate
16
+
17
+ > `readonly` **Deflate**: `"deflate"` = `"deflate"`
18
+
19
+ deflate.
@@ -0,0 +1,98 @@
1
+ {
2
+ "error": {
3
+ "validation": {
4
+ "beEmpty": "{fieldName} must be empty",
5
+ "beNotEmpty": "{fieldName} must not be empty",
6
+ "beText": "{fieldName} must be text",
7
+ "beTextValue": "{fieldName} must contain some text",
8
+ "beTextMinMax": "{fieldName} must be longer than {minLength} and shorter than {maxLength} characters",
9
+ "beTextMin": "{fieldName} must be longer than {minLength} characters",
10
+ "beTextMax": "{fieldName} must be shorter than {maxLength} characters",
11
+ "beNumber": "{fieldName} must be a number",
12
+ "beNumberMinMax": "{fieldName} must be >= {minValue} and <= {maxValue}",
13
+ "beNumberMin": "{fieldName} must be >= {minValue}",
14
+ "beNumberMax": "{fieldName} must be <= {maxValue}",
15
+ "beWholeNumber": "{fieldName} must be a whole number",
16
+ "beWholeNumberMinMax": "{fieldName} must be a whole number >= {minValue} and <= {maxValue}",
17
+ "beWholeNumberMin": "{fieldName} must be a whole number >= {minValue}",
18
+ "beWholeNumberMax": "{fieldName} must be a whole number <= {maxValue}",
19
+ "beBigInteger": "{fieldName} must be a bigint",
20
+ "beBigIntegerMinMax": "{fieldName} must be a bigint >= {minValue} and <= {maxValue}",
21
+ "beBigIntegerMin": "{fieldName} must be a bigint >= {minValue}",
22
+ "beBigIntegerMax": "{fieldName} must be a bigint <= {maxValue}",
23
+ "beBoolean": "{fieldName} must be true or false",
24
+ "beDate": "{fieldName} must be a date",
25
+ "beDateTime": "{fieldName} must be a date/time",
26
+ "beTime": "{fieldName} must be a time",
27
+ "beTimestampMilliseconds": "{fieldName} must be a timestamp in milliseconds",
28
+ "beTimestampSeconds": "{fieldName} must be a timestamp in seconds",
29
+ "beObject": "{fieldName} must be an object",
30
+ "beArray": "{fieldName} must be an array",
31
+ "beArrayValue": "{fieldName} must be an array with at least one item",
32
+ "beIncluded": "{fieldName} is unrecognised",
33
+ "beByteArray": "{fieldName} must be a byte array",
34
+ "beUrn": "{fieldName} must be a correctly formatted urn",
35
+ "beUrl": "{fieldName} must be a correctly formatted url",
36
+ "beJSON": "{fieldName} must be correctly formatted JSON",
37
+ "beEmail": "{fieldName} must be a correctly formatted e-mail address",
38
+ "failed": "Validation failed",
39
+ "failedObject": "Validation of \"{objectName}\" failed"
40
+ },
41
+ "guard": {
42
+ "undefined": "Property \"{property}\" must be defined, it is \"{value}\"",
43
+ "string": "Property \"{property}\" must be a string, it is \"{value}\"",
44
+ "stringEmpty": "Property \"{property}\" must have a value, it is empty",
45
+ "stringBase64": "Property \"{property}\" must be a base64 encoded string, it is \"{value}\"",
46
+ "stringBase64Url": "Property \"{property}\" must be a base64 url encoded string, it is \"{value}\"",
47
+ "stringHex": "Property \"{property}\" must be a hex string, it is \"{value}\"",
48
+ "stringHexLength": "Property \"{property}\" must be a hex string of length \"{options}\", it is \"{value}\"",
49
+ "number": "Property \"{property}\" must be a number, it is \"{value}\"",
50
+ "integer": "Property \"{property}\" must be an integer, it is \"{value}\"",
51
+ "bigint": "Property \"{property}\" must be a bigint, it is \"{value}\"",
52
+ "boolean": "Property \"{property}\" must be a boolean, it is \"{value}\"",
53
+ "date": "Property \"{property}\" must be a date, it is \"{value}\"",
54
+ "timestampMilliseconds": "Property \"{property}\" must be a timestamp in milliseconds, it is \"{value}\"",
55
+ "timestampSeconds": "Property \"{property}\" must be a timestamp in seconds, it is \"{value}\"",
56
+ "objectUndefined": "Property \"{property}\" must be an object, it is \"undefined\"",
57
+ "object": "Property \"{property}\" must be an object, it is \"{value}\"",
58
+ "objectValue": "Property \"{property}\" must be an object, with at least one property, it is \"{value}\"",
59
+ "array": "Property \"{property}\" must be an array, it is \"{value}\"",
60
+ "arrayValue": "Property \"{property}\" must be an array with at least one item",
61
+ "arrayOneOf": "Property \"{property}\" must be one of [{options}], it is \"{value}\"",
62
+ "uint8Array": "Property \"{property}\" must be a Uint8Array, it is \"{value}\"",
63
+ "function": "Property \"{property}\" must be a function, it is \"{value}\"",
64
+ "urn": "Property \"{property}\" must be a Urn formatted string, it is \"{value}\"",
65
+ "url": "Property \"{property}\" must be a Url formatted string, it is \"{value}\"",
66
+ "email": "Property \"{property}\" must be string in e-mail format, it is \"{value}\""
67
+ },
68
+ "objectHelper": {
69
+ "failedBytesToJSON": "Failed converting bytes to JSON"
70
+ },
71
+ "common": {
72
+ "notImplementedMethod": "The method \"{method}\" has not been implemented",
73
+ "validation": "Validation failed"
74
+ },
75
+ "factory": {
76
+ "noUnregister": "There is no {typeName} registered with the name \"{name}\"",
77
+ "noGet": "The requested {typeName} \"{name}\" does not exist in the factory"
78
+ },
79
+ "bitString": {
80
+ "outOfRange": "The index should be >= 0 and less than the length of the bit string"
81
+ }
82
+ },
83
+ "errorNames": {
84
+ "error": "Error",
85
+ "generalError": "General",
86
+ "guardError": "Guard",
87
+ "conflictError": "Conflict",
88
+ "notFoundError": "Not Found",
89
+ "notSupportedError": "Not Supported",
90
+ "alreadyExistsError": "Already Exists",
91
+ "notImplementedError": "Not Implemented",
92
+ "validationError": "Validation",
93
+ "unprocessableError": "Unprocessable"
94
+ },
95
+ "validation": {
96
+ "defaultFieldName": "The field"
97
+ }
98
+ }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@twin.org/core",
3
+ "version": "0.0.1-next.1",
4
+ "description": "Helper methods/classes for data type checking/validation/guarding/error handling",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/twinfoundation/framework.git",
8
+ "directory": "packages/core"
9
+ },
10
+ "author": "martyn.janes@iota.org",
11
+ "license": "Apache-2.0",
12
+ "type": "module",
13
+ "engines": {
14
+ "node": ">=20.0.0"
15
+ },
16
+ "scripts": {
17
+ "clean": "rimraf dist coverage docs/reference",
18
+ "build": "tspc",
19
+ "test": "vitest --run --config ./vitest.config.ts --no-cache",
20
+ "coverage": "vitest --run --coverage --config ./vitest.config.ts --no-cache",
21
+ "bundle:esm": "rollup --config rollup.config.mjs --environment MODULE:esm",
22
+ "bundle:cjs": "rollup --config rollup.config.mjs --environment MODULE:cjs",
23
+ "bundle": "npm run bundle:esm && npm run bundle:cjs",
24
+ "docs:clean": "rimraf docs/reference",
25
+ "docs:generate": "typedoc",
26
+ "docs": "npm run docs:clean && npm run docs:generate",
27
+ "dist": "npm run clean && npm run build && npm run test && npm run bundle && npm run docs"
28
+ },
29
+ "dependencies": {
30
+ "@twin.org/nameof": "next",
31
+ "intl-messageformat": "10.5.14",
32
+ "rfc6902": "5.1.1"
33
+ },
34
+ "devDependencies": {
35
+ "@twin.org/nameof-transformer": "next",
36
+ "@vitest/coverage-v8": "2.1.1",
37
+ "copyfiles": "2.4.1",
38
+ "rimraf": "6.0.1",
39
+ "rollup": "4.21.3",
40
+ "rollup-plugin-typescript2": "0.36.0",
41
+ "ts-patch": "3.2.1",
42
+ "typedoc": "0.26.7",
43
+ "typedoc-plugin-markdown": "4.2.7",
44
+ "typescript": "5.6.2",
45
+ "vitest": "2.1.1"
46
+ },
47
+ "main": "./dist/cjs/index.cjs",
48
+ "module": "./dist/esm/index.mjs",
49
+ "types": "./dist/types/index.d.ts",
50
+ "exports": {
51
+ ".": {
52
+ "require": "./dist/cjs/index.cjs",
53
+ "import": "./dist/esm/index.mjs",
54
+ "types": "./dist/types/index.d.ts"
55
+ },
56
+ "./locales": "./locales"
57
+ },
58
+ "files": [
59
+ "dist/cjs",
60
+ "dist/esm",
61
+ "dist/types",
62
+ "locales",
63
+ "docs"
64
+ ]
65
+ }