@croct/sdk 0.17.9 → 0.17.11

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 (209) hide show
  1. package/activeRecord.cjs +135 -0
  2. package/apiKey.cjs +178 -0
  3. package/base64Url.cjs +41 -0
  4. package/cache/cache.cjs +34 -0
  5. package/cache/cookieCache.cjs +85 -0
  6. package/cache/fallbackCache.cjs +47 -0
  7. package/cache/inMemoryCache.cjs +41 -0
  8. package/cache/index.cjs +37 -0
  9. package/cache/localStorageCache.cjs +81 -0
  10. package/channel/channel.cjs +48 -0
  11. package/channel/encodedChannel.cjs +39 -0
  12. package/channel/guaranteedChannel.cjs +105 -0
  13. package/channel/httpBeaconChannel.cjs +111 -0
  14. package/channel/index.cjs +46 -0
  15. package/channel/queuedChannel.cjs +122 -0
  16. package/channel/retryChannel.cjs +87 -0
  17. package/channel/sandboxChannel.cjs +63 -0
  18. package/cid/assigner.cjs +16 -0
  19. package/cid/cachedAssigner.cjs +66 -0
  20. package/cid/fixedAssigner.cjs +35 -0
  21. package/cid/index.cjs +37 -0
  22. package/cid/remoteAssigner.cjs +65 -0
  23. package/constants.cjs +37 -0
  24. package/constants.cjs.map +1 -1
  25. package/constants.d.ts +2 -2
  26. package/constants.js +1 -1
  27. package/constants.js.map +1 -1
  28. package/container.cjs +305 -0
  29. package/contentFetcher.cjs +193 -0
  30. package/context.cjs +114 -0
  31. package/error.cjs +52 -0
  32. package/evaluator.cjs +219 -0
  33. package/eventManager.cjs +53 -0
  34. package/eventSubjectProcessor.cjs +84 -0
  35. package/facade/contentFetcherFacade.cjs +61 -0
  36. package/facade/evaluatorFacade.cjs +94 -0
  37. package/facade/index.cjs +52 -0
  38. package/facade/sdkFacade.cjs +229 -0
  39. package/facade/sessionFacade.cjs +36 -0
  40. package/facade/sessionPatch.cjs +48 -0
  41. package/facade/trackerFacade.cjs +87 -0
  42. package/facade/userFacade.cjs +43 -0
  43. package/facade/userPatch.cjs +48 -0
  44. package/help.cjs +45 -0
  45. package/index.cjs +33 -0
  46. package/logging/consoleLogger.cjs +50 -0
  47. package/logging/filteredLogger.cjs +62 -0
  48. package/logging/index.cjs +40 -0
  49. package/logging/logger.cjs +16 -0
  50. package/logging/namespacedLogger.cjs +48 -0
  51. package/logging/nullLogger.cjs +37 -0
  52. package/namespacedStorage.cjs +77 -0
  53. package/package.json +7 -6
  54. package/patch.cjs +16 -0
  55. package/queue/capacityRestrictedQueue.cjs +57 -0
  56. package/queue/inMemoryQueue.cjs +58 -0
  57. package/queue/index.cjs +40 -0
  58. package/queue/monitoredQueue.cjs +141 -0
  59. package/queue/persistentQueue.cjs +78 -0
  60. package/queue/queue.cjs +16 -0
  61. package/retry/arbitraryPolicy.cjs +41 -0
  62. package/retry/backoffPolicy.cjs +81 -0
  63. package/retry/index.cjs +40 -0
  64. package/retry/maxAttemptsPolicy.cjs +45 -0
  65. package/retry/neverPolicy.cjs +35 -0
  66. package/retry/policy.cjs +16 -0
  67. package/schema/attributeSchema.cjs +32 -0
  68. package/schema/contentFetcherSchemas.cjs +49 -0
  69. package/schema/contentSchemas.cjs +70 -0
  70. package/schema/contextSchemas.cjs +31 -0
  71. package/schema/ecommerceSchemas.cjs +209 -0
  72. package/schema/evaluatorSchemas.cjs +64 -0
  73. package/schema/eventSchemas.cjs +162 -0
  74. package/schema/index.cjs +42 -0
  75. package/schema/loggerSchema.cjs +38 -0
  76. package/schema/operationSchemas.cjs +122 -0
  77. package/schema/sdkFacadeSchemas.cjs +82 -0
  78. package/schema/sdkSchemas.cjs +110 -0
  79. package/schema/tokenSchema.cjs +68 -0
  80. package/schema/userSchema.cjs +202 -0
  81. package/sdk.cjs +134 -0
  82. package/sdkEvents.cjs +16 -0
  83. package/sourceLocation.cjs +92 -0
  84. package/tab.cjs +122 -0
  85. package/token/cachedTokenStore.cjs +51 -0
  86. package/token/inMemoryTokenStore.cjs +38 -0
  87. package/token/index.cjs +37 -0
  88. package/token/replicatedTokenStore.cjs +40 -0
  89. package/token/token.cjs +239 -0
  90. package/tracker.cjs +358 -0
  91. package/trackingEvents.cjs +94 -0
  92. package/transformer.cjs +30 -0
  93. package/utilityTypes.cjs +16 -0
  94. package/uuid.cjs +55 -0
  95. package/validation/arrayType.cjs +75 -0
  96. package/validation/booleanType.cjs +46 -0
  97. package/validation/functionType.cjs +46 -0
  98. package/validation/index.cjs +66 -0
  99. package/validation/jsonType.cjs +142 -0
  100. package/validation/mixedSchema.cjs +31 -0
  101. package/validation/nullType.cjs +46 -0
  102. package/validation/numberType.cjs +69 -0
  103. package/validation/objectType.cjs +114 -0
  104. package/validation/schema.cjs +34 -0
  105. package/validation/stringType.cjs +106 -0
  106. package/validation/unionType.cjs +67 -0
  107. package/validation/violation.cjs +47 -0
  108. package/src/activeRecord.ts +0 -150
  109. package/src/apiKey.ts +0 -208
  110. package/src/base64Url.ts +0 -22
  111. package/src/cache/cache.ts +0 -22
  112. package/src/cache/cookieCache.ts +0 -88
  113. package/src/cache/fallbackCache.ts +0 -29
  114. package/src/cache/inMemoryCache.ts +0 -21
  115. package/src/cache/index.ts +0 -4
  116. package/src/cache/localStorageCache.ts +0 -85
  117. package/src/channel/channel.ts +0 -52
  118. package/src/channel/encodedChannel.ts +0 -21
  119. package/src/channel/guaranteedChannel.ts +0 -131
  120. package/src/channel/httpBeaconChannel.ts +0 -128
  121. package/src/channel/index.ts +0 -7
  122. package/src/channel/queuedChannel.ts +0 -143
  123. package/src/channel/retryChannel.ts +0 -94
  124. package/src/channel/sandboxChannel.ts +0 -47
  125. package/src/cid/assigner.ts +0 -3
  126. package/src/cid/cachedAssigner.ts +0 -68
  127. package/src/cid/fixedAssigner.ts +0 -13
  128. package/src/cid/index.ts +0 -4
  129. package/src/cid/remoteAssigner.ts +0 -57
  130. package/src/constants.ts +0 -4
  131. package/src/container.ts +0 -410
  132. package/src/contentFetcher.ts +0 -290
  133. package/src/context.ts +0 -139
  134. package/src/error.ts +0 -31
  135. package/src/evaluator.ts +0 -314
  136. package/src/eventManager.ts +0 -53
  137. package/src/eventSubjectProcessor.ts +0 -85
  138. package/src/facade/contentFetcherFacade.ts +0 -69
  139. package/src/facade/evaluatorFacade.ts +0 -111
  140. package/src/facade/index.ts +0 -7
  141. package/src/facade/sdkFacade.ts +0 -310
  142. package/src/facade/sessionFacade.ts +0 -14
  143. package/src/facade/sessionPatch.ts +0 -32
  144. package/src/facade/trackerFacade.ts +0 -98
  145. package/src/facade/userFacade.ts +0 -26
  146. package/src/facade/userPatch.ts +0 -32
  147. package/src/help.ts +0 -24
  148. package/src/index.ts +0 -4
  149. package/src/logging/consoleLogger.ts +0 -38
  150. package/src/logging/filteredLogger.ts +0 -57
  151. package/src/logging/index.ts +0 -5
  152. package/src/logging/logger.ts +0 -13
  153. package/src/logging/namespacedLogger.ts +0 -32
  154. package/src/logging/nullLogger.ts +0 -19
  155. package/src/namespacedStorage.ts +0 -69
  156. package/src/patch.ts +0 -64
  157. package/src/queue/capacityRestrictedQueue.ts +0 -44
  158. package/src/queue/inMemoryQueue.ts +0 -43
  159. package/src/queue/index.ts +0 -5
  160. package/src/queue/monitoredQueue.ts +0 -168
  161. package/src/queue/persistentQueue.ts +0 -73
  162. package/src/queue/queue.ts +0 -15
  163. package/src/retry/arbitraryPolicy.ts +0 -21
  164. package/src/retry/backoffPolicy.ts +0 -84
  165. package/src/retry/index.ts +0 -5
  166. package/src/retry/maxAttemptsPolicy.ts +0 -28
  167. package/src/retry/neverPolicy.ts +0 -11
  168. package/src/retry/policy.ts +0 -5
  169. package/src/schema/attributeSchema.ts +0 -6
  170. package/src/schema/contentFetcherSchemas.ts +0 -23
  171. package/src/schema/contentSchemas.ts +0 -44
  172. package/src/schema/contextSchemas.ts +0 -5
  173. package/src/schema/ecommerceSchemas.ts +0 -179
  174. package/src/schema/evaluatorSchemas.ts +0 -52
  175. package/src/schema/eventSchemas.ts +0 -134
  176. package/src/schema/index.ts +0 -11
  177. package/src/schema/loggerSchema.ts +0 -12
  178. package/src/schema/operationSchemas.ts +0 -102
  179. package/src/schema/sdkFacadeSchemas.ts +0 -64
  180. package/src/schema/sdkSchemas.ts +0 -82
  181. package/src/schema/tokenSchema.ts +0 -42
  182. package/src/schema/userSchema.ts +0 -184
  183. package/src/sdk.ts +0 -183
  184. package/src/sdkEvents.ts +0 -15
  185. package/src/sourceLocation.ts +0 -85
  186. package/src/tab.ts +0 -148
  187. package/src/token/cachedTokenStore.ts +0 -34
  188. package/src/token/inMemoryTokenStore.ts +0 -13
  189. package/src/token/index.ts +0 -4
  190. package/src/token/replicatedTokenStore.ts +0 -21
  191. package/src/token/token.ts +0 -301
  192. package/src/tracker.ts +0 -504
  193. package/src/trackingEvents.ts +0 -452
  194. package/src/transformer.ts +0 -7
  195. package/src/utilityTypes.ts +0 -3
  196. package/src/uuid.ts +0 -43
  197. package/src/validation/arrayType.ts +0 -71
  198. package/src/validation/booleanType.ts +0 -22
  199. package/src/validation/functionType.ts +0 -22
  200. package/src/validation/index.ts +0 -12
  201. package/src/validation/jsonType.ts +0 -156
  202. package/src/validation/mixedSchema.ts +0 -7
  203. package/src/validation/nullType.ts +0 -22
  204. package/src/validation/numberType.ts +0 -59
  205. package/src/validation/objectType.ts +0 -138
  206. package/src/validation/schema.ts +0 -21
  207. package/src/validation/stringType.ts +0 -118
  208. package/src/validation/unionType.ts +0 -53
  209. package/src/validation/violation.ts +0 -23
@@ -0,0 +1,16 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var utilityTypes_exports = {};
15
+ module.exports = __toCommonJS(utilityTypes_exports);
16
+ //# sourceMappingURL=utilityTypes.cjs.map
package/uuid.cjs ADDED
@@ -0,0 +1,55 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var uuid_exports = {};
19
+ __export(uuid_exports, {
20
+ uuid4: () => uuid4
21
+ });
22
+ module.exports = __toCommonJS(uuid_exports);
23
+ function uuid4(sortable = false) {
24
+ let uuid = "";
25
+ if (sortable) {
26
+ const prefix = Date.now().toString(16).padStart(12, "0").substring(0, 12);
27
+ uuid = `${prefix.substring(0, 8)}-${prefix.substring(8, 12)}`;
28
+ }
29
+ for (let index = uuid.length; index < 36; index++) {
30
+ switch (index) {
31
+ case 8:
32
+ case 13:
33
+ case 18:
34
+ case 23:
35
+ uuid += "-";
36
+ break;
37
+ case 14:
38
+ uuid += "4";
39
+ break;
40
+ default: {
41
+ let random = Math.random() * 16 | 0;
42
+ if (index === 19) {
43
+ random = random & 3 | 8;
44
+ }
45
+ uuid += random.toString(16);
46
+ }
47
+ }
48
+ }
49
+ return uuid;
50
+ }
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ uuid4
54
+ });
55
+ //# sourceMappingURL=uuid.cjs.map
@@ -0,0 +1,75 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var arrayType_exports = {};
19
+ __export(arrayType_exports, {
20
+ ArrayType: () => ArrayType
21
+ });
22
+ module.exports = __toCommonJS(arrayType_exports);
23
+ var import_schema = require("./schema");
24
+ var import_violation = require("./violation");
25
+ class ArrayType {
26
+ constructor(definition = {}) {
27
+ this.definition = {
28
+ ...definition,
29
+ minItems: definition.minItems ?? -1,
30
+ maxItems: definition.maxItems ?? -1
31
+ };
32
+ }
33
+ getTypes() {
34
+ return ["array"];
35
+ }
36
+ isValidType(value) {
37
+ return Array.isArray(value);
38
+ }
39
+ validate(value, path = []) {
40
+ if (!this.isValidType(value)) {
41
+ throw new import_schema.Violation(
42
+ `Expected value of type array at path '${(0, import_violation.formatPath)(path)}', actual ${(0, import_violation.describe)(value)}.`,
43
+ path,
44
+ { type: "string" }
45
+ );
46
+ }
47
+ const { minItems, maxItems } = this.definition;
48
+ const { length } = value;
49
+ if (minItems >= 0 && minItems > length) {
50
+ throw new import_schema.Violation(
51
+ `Expected ${minItems === maxItems ? "exactly" : "at least"} ${minItems} ${minItems === 1 ? "item" : "items"} at path '${(0, import_violation.formatPath)(path)}', actual ${length}.`,
52
+ path,
53
+ { limit: minItems }
54
+ );
55
+ }
56
+ if (maxItems >= 0 && maxItems < length) {
57
+ throw new import_schema.Violation(
58
+ `Expected ${minItems === maxItems ? "exactly" : "at most"} ${maxItems} ${maxItems === 1 ? "item" : "items"} at path '${(0, import_violation.formatPath)(path)}', actual ${length}.`,
59
+ path,
60
+ { limit: maxItems }
61
+ );
62
+ }
63
+ if (this.definition.items === void 0) {
64
+ return;
65
+ }
66
+ for (let index = 0; index < length; index++) {
67
+ this.definition.items.validate(value[index], path.concat([index.toString()]));
68
+ }
69
+ }
70
+ }
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ ArrayType
74
+ });
75
+ //# sourceMappingURL=arrayType.cjs.map
@@ -0,0 +1,46 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var booleanType_exports = {};
19
+ __export(booleanType_exports, {
20
+ BooleanType: () => BooleanType
21
+ });
22
+ module.exports = __toCommonJS(booleanType_exports);
23
+ var import_schema = require("./schema");
24
+ var import_violation = require("./violation");
25
+ class BooleanType {
26
+ getTypes() {
27
+ return ["boolean"];
28
+ }
29
+ isValidType(value) {
30
+ return typeof value === "boolean";
31
+ }
32
+ validate(value, path = []) {
33
+ if (!this.isValidType(value)) {
34
+ throw new import_schema.Violation(
35
+ `Expected value of type boolean at path '${(0, import_violation.formatPath)(path)}', actual ${(0, import_violation.describe)(value)}.`,
36
+ path,
37
+ { type: "boolean" }
38
+ );
39
+ }
40
+ }
41
+ }
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ BooleanType
45
+ });
46
+ //# sourceMappingURL=booleanType.cjs.map
@@ -0,0 +1,46 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var functionType_exports = {};
19
+ __export(functionType_exports, {
20
+ FunctionType: () => FunctionType
21
+ });
22
+ module.exports = __toCommonJS(functionType_exports);
23
+ var import_schema = require("./schema");
24
+ var import_violation = require("./violation");
25
+ class FunctionType {
26
+ getTypes() {
27
+ return ["function"];
28
+ }
29
+ isValidType(value) {
30
+ return typeof value === "function";
31
+ }
32
+ validate(value, path = []) {
33
+ if (!this.isValidType(value)) {
34
+ throw new import_schema.Violation(
35
+ `Expected value of type function at path '${(0, import_violation.formatPath)(path)}', actual ${(0, import_violation.describe)(value)}.`,
36
+ path,
37
+ { type: "function" }
38
+ );
39
+ }
40
+ }
41
+ }
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ FunctionType
45
+ });
46
+ //# sourceMappingURL=functionType.cjs.map
@@ -0,0 +1,66 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var validation_exports = {};
20
+ __export(validation_exports, {
21
+ ArrayType: () => import_arrayType.ArrayType,
22
+ BooleanType: () => import_booleanType.BooleanType,
23
+ FunctionType: () => import_functionType.FunctionType,
24
+ JsonArrayType: () => import_jsonType.JsonArrayType,
25
+ JsonObjectType: () => import_jsonType.JsonObjectType,
26
+ JsonPrimitiveType: () => import_jsonType.JsonPrimitiveType,
27
+ JsonType: () => import_jsonType.JsonType,
28
+ MixedSchema: () => import_mixedSchema.MixedSchema,
29
+ NullType: () => import_nullType.NullType,
30
+ NumberType: () => import_numberType.NumberType,
31
+ ObjectType: () => import_objectType.ObjectType,
32
+ StringType: () => import_stringType.StringType,
33
+ UnionType: () => import_unionType.UnionType
34
+ });
35
+ module.exports = __toCommonJS(validation_exports);
36
+ __reExport(validation_exports, require("./schema"), module.exports);
37
+ __reExport(validation_exports, require("./violation"), module.exports);
38
+ var import_arrayType = require("./arrayType");
39
+ var import_booleanType = require("./booleanType");
40
+ var import_functionType = require("./functionType");
41
+ var import_jsonType = require("./jsonType");
42
+ var import_mixedSchema = require("./mixedSchema");
43
+ var import_nullType = require("./nullType");
44
+ var import_numberType = require("./numberType");
45
+ var import_objectType = require("./objectType");
46
+ var import_stringType = require("./stringType");
47
+ var import_unionType = require("./unionType");
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ ArrayType,
51
+ BooleanType,
52
+ FunctionType,
53
+ JsonArrayType,
54
+ JsonObjectType,
55
+ JsonPrimitiveType,
56
+ JsonType,
57
+ MixedSchema,
58
+ NullType,
59
+ NumberType,
60
+ ObjectType,
61
+ StringType,
62
+ UnionType,
63
+ ...require("./schema"),
64
+ ...require("./violation")
65
+ });
66
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,142 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var jsonType_exports = {};
19
+ __export(jsonType_exports, {
20
+ JsonArrayType: () => JsonArrayType,
21
+ JsonObjectType: () => JsonObjectType,
22
+ JsonPrimitiveType: () => JsonPrimitiveType,
23
+ JsonType: () => JsonType
24
+ });
25
+ module.exports = __toCommonJS(jsonType_exports);
26
+ var import_schema = require("./schema");
27
+ var import_violation = require("./violation");
28
+ function isJsonPrimitive(value) {
29
+ return value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number";
30
+ }
31
+ function isPlainObject(value) {
32
+ return Object.prototype.toString.call(value) === "[object Object]";
33
+ }
34
+ function isJsonArray(value) {
35
+ return Array.isArray(value) && value.every(isJsonValue);
36
+ }
37
+ function isJsonObject(value) {
38
+ return isPlainObject(value) && Object.values(value).every(isJsonValue);
39
+ }
40
+ function isJsonValue(value) {
41
+ return isJsonPrimitive(value) || isJsonArray(value) || isJsonObject(value);
42
+ }
43
+ class JsonObjectType {
44
+ constructor(definition = {}) {
45
+ this.definition = definition;
46
+ }
47
+ getTypes() {
48
+ return ["object"];
49
+ }
50
+ isValidType(value) {
51
+ return isPlainObject(value);
52
+ }
53
+ validate(value, path = []) {
54
+ if (!isJsonObject(value)) {
55
+ throw new import_schema.Violation(
56
+ `Expected a JSON object at path '${(0, import_violation.formatPath)(path)}', actual ${(0, import_violation.describe)(value)}.`,
57
+ path,
58
+ { type: "object" }
59
+ );
60
+ }
61
+ if (this.definition.properties === void 0 && this.definition.propertyNames === void 0) {
62
+ return;
63
+ }
64
+ for (const [entryName, entryValue] of Object.entries(value)) {
65
+ const propertyPath = path.concat([entryName]);
66
+ if (this.definition.propertyNames !== void 0) {
67
+ this.definition.propertyNames.validate(entryName, propertyPath);
68
+ }
69
+ if (this.definition.properties !== void 0) {
70
+ this.definition.properties.validate(entryValue, path.concat([entryName]));
71
+ }
72
+ }
73
+ }
74
+ }
75
+ class JsonArrayType {
76
+ constructor(definition = {}) {
77
+ this.definition = definition;
78
+ }
79
+ getTypes() {
80
+ return ["array"];
81
+ }
82
+ isValidType(value) {
83
+ return Array.isArray(value);
84
+ }
85
+ validate(value, path = []) {
86
+ if (!isJsonArray(value)) {
87
+ throw new import_schema.Violation(
88
+ `Expected a JSON array at path '${(0, import_violation.formatPath)(path)}', actual ${(0, import_violation.describe)(value)}.`,
89
+ path,
90
+ { type: "array" }
91
+ );
92
+ }
93
+ if (this.definition.items === void 0) {
94
+ return;
95
+ }
96
+ for (let index = 0; index < value.length; index++) {
97
+ this.definition.items.validate(value[index], path.concat([index.toString()]));
98
+ }
99
+ }
100
+ }
101
+ class JsonPrimitiveType {
102
+ getTypes() {
103
+ return ["null", "number", "string", "boolean"];
104
+ }
105
+ isValidType(value) {
106
+ return isJsonPrimitive(value);
107
+ }
108
+ validate(value, path = []) {
109
+ if (!this.isValidType(value)) {
110
+ throw new import_schema.Violation(
111
+ `Expected a JSON primitive at path '${(0, import_violation.formatPath)(path)}', actual ${(0, import_violation.describe)(value)}.`,
112
+ path,
113
+ { type: this.getTypes().join("|") }
114
+ );
115
+ }
116
+ }
117
+ }
118
+ class JsonType {
119
+ getTypes() {
120
+ return ["null", "number", "string", "boolean", "array", "object"];
121
+ }
122
+ isValidType(value) {
123
+ return isJsonPrimitive(value) || Array.isArray(value) || isPlainObject(value);
124
+ }
125
+ validate(value, path = []) {
126
+ if (!isJsonValue(value)) {
127
+ throw new import_schema.Violation(
128
+ `Expected a JSON value at path '${(0, import_violation.formatPath)(path)}', actual ${(0, import_violation.describe)(value)}.`,
129
+ path,
130
+ { type: this.getTypes().join("|") }
131
+ );
132
+ }
133
+ }
134
+ }
135
+ // Annotate the CommonJS export names for ESM import in node:
136
+ 0 && (module.exports = {
137
+ JsonArrayType,
138
+ JsonObjectType,
139
+ JsonPrimitiveType,
140
+ JsonType
141
+ });
142
+ //# sourceMappingURL=jsonType.cjs.map
@@ -0,0 +1,31 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var mixedSchema_exports = {};
19
+ __export(mixedSchema_exports, {
20
+ MixedSchema: () => MixedSchema
21
+ });
22
+ module.exports = __toCommonJS(mixedSchema_exports);
23
+ class MixedSchema {
24
+ validate() {
25
+ }
26
+ }
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ MixedSchema
30
+ });
31
+ //# sourceMappingURL=mixedSchema.cjs.map
@@ -0,0 +1,46 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var nullType_exports = {};
19
+ __export(nullType_exports, {
20
+ NullType: () => NullType
21
+ });
22
+ module.exports = __toCommonJS(nullType_exports);
23
+ var import_schema = require("./schema");
24
+ var import_violation = require("./violation");
25
+ class NullType {
26
+ getTypes() {
27
+ return ["null"];
28
+ }
29
+ isValidType(value) {
30
+ return value === null;
31
+ }
32
+ validate(value, path = []) {
33
+ if (!this.isValidType(value)) {
34
+ throw new import_schema.Violation(
35
+ `Expected value of type null at path '${(0, import_violation.formatPath)(path)}', actual ${(0, import_violation.describe)(value)}.`,
36
+ path,
37
+ { type: "null" }
38
+ );
39
+ }
40
+ }
41
+ }
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ NullType
45
+ });
46
+ //# sourceMappingURL=nullType.cjs.map
@@ -0,0 +1,69 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var numberType_exports = {};
19
+ __export(numberType_exports, {
20
+ NumberType: () => NumberType
21
+ });
22
+ module.exports = __toCommonJS(numberType_exports);
23
+ var import_schema = require("./schema");
24
+ var import_violation = require("./violation");
25
+ class NumberType {
26
+ constructor(definition = {}) {
27
+ this.definition = {
28
+ ...definition,
29
+ integer: definition.integer ?? false,
30
+ minimum: definition.minimum ?? Number.NEGATIVE_INFINITY,
31
+ maximum: definition.maximum ?? Number.POSITIVE_INFINITY
32
+ };
33
+ }
34
+ getTypes() {
35
+ return [this.definition.integer ? "integer" : "number"];
36
+ }
37
+ isValidType(value) {
38
+ return typeof value === "number" && (!this.definition.integer || Number.isInteger(value));
39
+ }
40
+ validate(value, path = []) {
41
+ if (!this.isValidType(value)) {
42
+ const type = this.getTypes()[0];
43
+ throw new import_schema.Violation(
44
+ `Expected value of type ${type} at path '${(0, import_violation.formatPath)(path)}', actual ${(0, import_violation.describe)(value)}.`,
45
+ path,
46
+ { type }
47
+ );
48
+ }
49
+ if (value < this.definition.minimum) {
50
+ throw new import_schema.Violation(
51
+ `Expected a value greater than or equal to ${this.definition.minimum} at path '${(0, import_violation.formatPath)(path)}', actual ${value}.`,
52
+ path,
53
+ { limit: this.definition.minimum }
54
+ );
55
+ }
56
+ if (value > this.definition.maximum) {
57
+ throw new import_schema.Violation(
58
+ `Expected a value less than or equal to ${this.definition.maximum} at path '${(0, import_violation.formatPath)(path)}', actual ${value}.`,
59
+ path,
60
+ { limit: this.definition.maximum }
61
+ );
62
+ }
63
+ }
64
+ }
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ NumberType
68
+ });
69
+ //# sourceMappingURL=numberType.cjs.map