@digitraffic/common 2026.3.17-1 → 2026.3.26-1-beta

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 (238) hide show
  1. package/README.md +18 -1
  2. package/dist/__test__/asserter.d.ts +13 -0
  3. package/dist/__test__/asserter.js +39 -0
  4. package/dist/__test__/db-testutils.d.ts +3 -0
  5. package/dist/__test__/db-testutils.js +38 -0
  6. package/dist/__test__/dependencies.test.d.ts +1 -0
  7. package/dist/__test__/dependencies.test.js +21 -0
  8. package/dist/__test__/imports.test.d.ts +1 -0
  9. package/dist/__test__/imports.test.js +318 -0
  10. package/dist/__test__/infra/acl-builder.test.d.ts +1 -0
  11. package/dist/__test__/infra/acl-builder.test.js +72 -0
  12. package/dist/__test__/infra/api/handler-factory.test.d.ts +1 -0
  13. package/dist/__test__/infra/api/handler-factory.test.js +42 -0
  14. package/dist/__test__/infra/api/integration.test.d.ts +1 -0
  15. package/dist/__test__/infra/api/integration.test.js +162 -0
  16. package/dist/__test__/infra/api/response.test.d.ts +1 -0
  17. package/dist/__test__/infra/api/response.test.js +77 -0
  18. package/dist/__test__/infra/api/static-integration.test.d.ts +1 -0
  19. package/dist/__test__/infra/api/static-integration.test.js +35 -0
  20. package/dist/__test__/infra/documentation.test.d.ts +1 -0
  21. package/dist/__test__/infra/documentation.test.js +38 -0
  22. package/dist/__test__/infra/scheduler.test.d.ts +1 -0
  23. package/dist/__test__/infra/scheduler.test.js +23 -0
  24. package/dist/__test__/infra/security-rule.test.d.ts +1 -0
  25. package/dist/__test__/infra/security-rule.test.js +21 -0
  26. package/dist/__test__/infra/stack/rest-apis.test.d.ts +1 -0
  27. package/dist/__test__/infra/stack/rest-apis.test.js +47 -0
  28. package/dist/__test__/marine/id_utils.test.d.ts +1 -0
  29. package/dist/__test__/marine/id_utils.test.js +45 -0
  30. package/dist/__test__/mock-ky.d.ts +2 -0
  31. package/dist/__test__/mock-ky.js +15 -0
  32. package/dist/__test__/promise/promise.test.d.ts +1 -0
  33. package/dist/__test__/promise/promise.test.js +126 -0
  34. package/dist/__test__/runtime/dt-logger.test.d.ts +1 -0
  35. package/dist/__test__/runtime/dt-logger.test.js +193 -0
  36. package/dist/__test__/secrets/secret-holder.test.d.ts +1 -0
  37. package/dist/__test__/secrets/secret-holder.test.js +96 -0
  38. package/dist/__test__/secrets/secret.test.d.ts +1 -0
  39. package/dist/__test__/secrets/secret.test.js +57 -0
  40. package/dist/__test__/stack/dt-function.test.d.ts +1 -0
  41. package/dist/__test__/stack/dt-function.test.js +340 -0
  42. package/dist/__test__/stack/rest-apis.test.d.ts +1 -0
  43. package/dist/__test__/stack/rest-apis.test.js +45 -0
  44. package/dist/__test__/test/mock-ky.test.d.ts +1 -0
  45. package/dist/__test__/test/mock-ky.test.js +46 -0
  46. package/dist/__test__/testutils.d.ts +12 -0
  47. package/dist/__test__/testutils.js +32 -0
  48. package/dist/__test__/types/lambda-proxy-types.test.d.ts +8 -0
  49. package/dist/__test__/types/lambda-proxy-types.test.js +155 -0
  50. package/dist/__test__/types/lambda-response-builder.test.d.ts +1 -0
  51. package/dist/__test__/types/lambda-response-builder.test.js +81 -0
  52. package/dist/__test__/types/lambda-response.test.d.ts +9 -0
  53. package/dist/__test__/types/lambda-response.test.js +73 -0
  54. package/dist/__test__/utils/base64.test.d.ts +1 -0
  55. package/dist/__test__/utils/base64.test.js +38 -0
  56. package/dist/__test__/utils/date-utils.test.d.ts +1 -0
  57. package/dist/__test__/utils/date-utils.test.js +32 -0
  58. package/dist/__test__/utils/geometry.test.d.ts +1 -0
  59. package/dist/__test__/utils/geometry.test.js +25 -0
  60. package/dist/__test__/utils/lambda-proxy-event.test.d.ts +1 -0
  61. package/dist/__test__/utils/lambda-proxy-event.test.js +45 -0
  62. package/dist/__test__/utils/logging.test.d.ts +1 -0
  63. package/dist/__test__/utils/logging.test.js +75 -0
  64. package/dist/__test__/utils/stop-watch.test.d.ts +1 -0
  65. package/dist/__test__/utils/stop-watch.test.js +118 -0
  66. package/dist/__test__/utils/utils.test.d.ts +1 -0
  67. package/dist/__test__/utils/utils.test.js +48 -0
  68. package/dist/aws/infra/acl-builder.d.ts +53 -0
  69. package/dist/aws/infra/acl-builder.js +407 -0
  70. package/dist/aws/infra/api/handler-factory.d.ts +22 -0
  71. package/dist/aws/infra/api/handler-factory.js +68 -0
  72. package/dist/aws/infra/api/integration.d.ts +49 -0
  73. package/dist/aws/infra/api/integration.js +162 -0
  74. package/dist/aws/infra/api/response.d.ts +62 -0
  75. package/dist/aws/infra/api/response.js +132 -0
  76. package/dist/aws/infra/api/responses.d.ts +60 -0
  77. package/dist/aws/infra/api/responses.js +90 -0
  78. package/dist/aws/infra/api/static-integration.d.ts +16 -0
  79. package/dist/aws/infra/api/static-integration.js +76 -0
  80. package/dist/aws/infra/bucket-policy.d.ts +38 -0
  81. package/dist/aws/infra/bucket-policy.js +30 -0
  82. package/dist/aws/infra/canaries/canary-alarm.d.ts +6 -0
  83. package/dist/aws/infra/canaries/canary-alarm.js +20 -0
  84. package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
  85. package/dist/aws/infra/canaries/canary-keys.js +4 -0
  86. package/dist/aws/infra/canaries/canary-parameters.d.ts +19 -0
  87. package/dist/aws/infra/canaries/canary-parameters.js +2 -0
  88. package/dist/aws/infra/canaries/canary-role.d.ts +14 -0
  89. package/dist/aws/infra/canaries/canary-role.js +51 -0
  90. package/dist/aws/infra/canaries/canary.d.ts +8 -0
  91. package/dist/aws/infra/canaries/canary.js +26 -0
  92. package/dist/aws/infra/canaries/database-canary.d.ts +17 -0
  93. package/dist/aws/infra/canaries/database-canary.js +65 -0
  94. package/dist/aws/infra/canaries/database-checker.d.ts +33 -0
  95. package/dist/aws/infra/canaries/database-checker.js +119 -0
  96. package/dist/aws/infra/canaries/url-canary.d.ts +16 -0
  97. package/dist/aws/infra/canaries/url-canary.js +55 -0
  98. package/dist/aws/infra/canaries/url-checker.d.ts +45 -0
  99. package/dist/aws/infra/canaries/url-checker.js +256 -0
  100. package/dist/aws/infra/documentation.d.ts +56 -0
  101. package/dist/aws/infra/documentation.js +90 -0
  102. package/dist/aws/infra/import-util.d.ts +17 -0
  103. package/dist/aws/infra/import-util.js +41 -0
  104. package/dist/aws/infra/scheduler.d.ts +12 -0
  105. package/dist/aws/infra/scheduler.js +27 -0
  106. package/dist/aws/infra/security-rule.d.ts +12 -0
  107. package/dist/aws/infra/security-rule.js +35 -0
  108. package/dist/aws/infra/sqs-integration.d.ts +4 -0
  109. package/dist/aws/infra/sqs-integration.js +85 -0
  110. package/dist/aws/infra/sqs-queue.d.ts +19 -0
  111. package/dist/aws/infra/sqs-queue.js +145 -0
  112. package/dist/aws/infra/stack/dt-function-alarms.d.ts +29 -0
  113. package/dist/aws/infra/stack/dt-function-alarms.js +54 -0
  114. package/dist/aws/infra/stack/dt-function.d.ts +124 -0
  115. package/dist/aws/infra/stack/dt-function.js +315 -0
  116. package/dist/aws/infra/stack/lambda-configs.d.ts +44 -0
  117. package/dist/aws/infra/stack/lambda-configs.js +71 -0
  118. package/dist/aws/infra/stack/lambda-log-group.d.ts +15 -0
  119. package/dist/aws/infra/stack/lambda-log-group.js +24 -0
  120. package/dist/aws/infra/stack/monitoredfunction.d.ts +85 -0
  121. package/dist/aws/infra/stack/monitoredfunction.js +147 -0
  122. package/dist/aws/infra/stack/parameters.d.ts +40 -0
  123. package/dist/aws/infra/stack/parameters.js +50 -0
  124. package/dist/aws/infra/stack/rest-api.d.ts +74 -0
  125. package/dist/aws/infra/stack/rest-api.js +235 -0
  126. package/dist/aws/infra/stack/stack-checking-aspect.d.ts +20 -0
  127. package/dist/aws/infra/stack/stack-checking-aspect.js +183 -0
  128. package/dist/aws/infra/stack/stack.d.ts +56 -0
  129. package/dist/aws/infra/stack/stack.js +71 -0
  130. package/dist/aws/infra/stack/subscription.d.ts +17 -0
  131. package/dist/aws/infra/stack/subscription.js +37 -0
  132. package/dist/aws/infra/stacks/db-dns-stack.d.ts +13 -0
  133. package/dist/aws/infra/stacks/db-dns-stack.js +60 -0
  134. package/dist/aws/infra/stacks/db-proxy-stack.d.ts +24 -0
  135. package/dist/aws/infra/stacks/db-proxy-stack.js +74 -0
  136. package/dist/aws/infra/stacks/db-stack.d.ts +65 -0
  137. package/dist/aws/infra/stacks/db-stack.js +189 -0
  138. package/dist/aws/infra/stacks/intra-stack-configuration.d.ts +5 -0
  139. package/dist/aws/infra/stacks/intra-stack-configuration.js +2 -0
  140. package/dist/aws/infra/stacks/network-stack.d.ts +14 -0
  141. package/dist/aws/infra/stacks/network-stack.js +45 -0
  142. package/dist/aws/infra/usage-plans.d.ts +16 -0
  143. package/dist/aws/infra/usage-plans.js +38 -0
  144. package/dist/aws/runtime/apikey.d.ts +2 -0
  145. package/dist/aws/runtime/apikey.js +13 -0
  146. package/dist/aws/runtime/digitraffic-integration-response.d.ts +8 -0
  147. package/dist/aws/runtime/digitraffic-integration-response.js +25 -0
  148. package/dist/aws/runtime/dt-logger-default.d.ts +9 -0
  149. package/dist/aws/runtime/dt-logger-default.js +6 -0
  150. package/dist/aws/runtime/dt-logger.d.ts +117 -0
  151. package/dist/aws/runtime/dt-logger.js +159 -0
  152. package/dist/aws/runtime/environment.d.ts +5 -0
  153. package/dist/aws/runtime/environment.js +7 -0
  154. package/dist/aws/runtime/s3.d.ts +3 -0
  155. package/dist/aws/runtime/s3.js +21 -0
  156. package/dist/aws/runtime/secrets/dbsecret.d.ts +16 -0
  157. package/dist/aws/runtime/secrets/dbsecret.js +26 -0
  158. package/dist/aws/runtime/secrets/proxy-holder.d.ts +9 -0
  159. package/dist/aws/runtime/secrets/proxy-holder.js +25 -0
  160. package/dist/aws/runtime/secrets/rds-holder.d.ts +9 -0
  161. package/dist/aws/runtime/secrets/rds-holder.js +25 -0
  162. package/dist/aws/runtime/secrets/secret-holder.d.ts +30 -0
  163. package/dist/aws/runtime/secrets/secret-holder.js +81 -0
  164. package/dist/aws/runtime/secrets/secret.d.ts +8 -0
  165. package/dist/aws/runtime/secrets/secret.js +61 -0
  166. package/dist/aws/types/errors.d.ts +8 -0
  167. package/dist/aws/types/errors.js +13 -0
  168. package/dist/aws/types/lambda-proxy-types.d.ts +59 -0
  169. package/dist/aws/types/lambda-proxy-types.js +210 -0
  170. package/dist/aws/types/lambda-response.d.ts +89 -0
  171. package/dist/aws/types/lambda-response.js +204 -0
  172. package/dist/aws/types/mediatypes.d.ts +11 -0
  173. package/dist/aws/types/mediatypes.js +14 -0
  174. package/dist/aws/types/model-with-reference.d.ts +7 -0
  175. package/dist/aws/types/model-with-reference.js +2 -0
  176. package/dist/aws/types/tags.d.ts +2 -0
  177. package/dist/aws/types/tags.js +4 -0
  178. package/dist/database/database.d.ts +27 -0
  179. package/dist/database/database.js +95 -0
  180. package/dist/database/last-updated.d.ts +15 -0
  181. package/dist/database/last-updated.js +46 -0
  182. package/dist/database/models.d.ts +6 -0
  183. package/dist/database/models.js +2 -0
  184. package/dist/index.d.ts +2 -0
  185. package/dist/index.js +2 -0
  186. package/dist/marine/id_utils.d.ts +3 -0
  187. package/dist/marine/id_utils.js +36 -0
  188. package/dist/marine/rtz.d.ts +48 -0
  189. package/dist/marine/rtz.js +2 -0
  190. package/dist/types/async-timeout-error.d.ts +3 -0
  191. package/dist/types/async-timeout-error.js +6 -0
  192. package/dist/types/either.d.ts +9 -0
  193. package/dist/types/either.js +2 -0
  194. package/dist/types/geojson.d.ts +47 -0
  195. package/dist/types/geojson.js +51 -0
  196. package/dist/types/http-error.d.ts +4 -0
  197. package/dist/types/http-error.js +8 -0
  198. package/dist/types/input-error.d.ts +2 -0
  199. package/dist/types/input-error.js +3 -0
  200. package/dist/types/language.d.ts +5 -0
  201. package/dist/types/language.js +7 -0
  202. package/dist/types/nullable.d.ts +24 -0
  203. package/dist/types/nullable.js +2 -0
  204. package/dist/types/openapi-schema.d.ts +932 -0
  205. package/dist/types/openapi-schema.js +151 -0
  206. package/dist/types/traffictype.d.ts +11 -0
  207. package/dist/types/traffictype.js +13 -0
  208. package/dist/types/urn.d.ts +1 -0
  209. package/dist/types/urn.js +2 -0
  210. package/dist/types/util-types.d.ts +11 -0
  211. package/dist/types/util-types.js +2 -0
  212. package/dist/types/validator.d.ts +4 -0
  213. package/dist/types/validator.js +9 -0
  214. package/dist/utils/api-model.d.ts +51 -0
  215. package/dist/utils/api-model.js +118 -0
  216. package/dist/utils/base64.d.ts +34 -0
  217. package/dist/utils/base64.js +53 -0
  218. package/dist/utils/date-utils.d.ts +27 -0
  219. package/dist/utils/date-utils.js +45 -0
  220. package/dist/utils/geojson-types.d.ts +14 -0
  221. package/dist/utils/geojson-types.js +15 -0
  222. package/dist/utils/geometry.d.ts +44 -0
  223. package/dist/utils/geometry.js +154 -0
  224. package/dist/utils/lambda-proxy-event.d.ts +9 -0
  225. package/dist/utils/lambda-proxy-event.js +31 -0
  226. package/dist/utils/logging.d.ts +40 -0
  227. package/dist/utils/logging.js +88 -0
  228. package/dist/utils/retry.d.ts +33 -0
  229. package/dist/utils/retry.js +135 -0
  230. package/dist/utils/slack.d.ts +5 -0
  231. package/dist/utils/slack.js +24 -0
  232. package/dist/utils/stop-watch.d.ts +46 -0
  233. package/dist/utils/stop-watch.js +114 -0
  234. package/dist/utils/utils.d.ts +95 -0
  235. package/dist/utils/utils.js +178 -0
  236. package/dist/utils/zod-utils.d.ts +27 -0
  237. package/dist/utils/zod-utils.js +57 -0
  238. package/package.json +30 -28
@@ -0,0 +1,151 @@
1
+ import { z } from "zod";
2
+ export const serverObject = z.object({
3
+ url: z.string(),
4
+ description: z.string().optional(),
5
+ variables: z.record(z.string(), z.unknown()).optional(),
6
+ });
7
+ export const parameterObject = z.object({
8
+ name: z.string(),
9
+ in: z.enum(["query", "header", "path", "cookie"]),
10
+ description: z.string().optional(),
11
+ required: z.boolean().optional(),
12
+ deprecated: z.boolean().optional(),
13
+ allowEmptyValue: z.boolean().optional(),
14
+ style: z
15
+ .enum([
16
+ "matrix",
17
+ "label",
18
+ "form",
19
+ "simple",
20
+ "spaceDelimited",
21
+ "pipeDelimited",
22
+ "deepObject",
23
+ ])
24
+ .optional(),
25
+ explode: z.string().optional(),
26
+ allowReserved: z.boolean().optional(),
27
+ schema: z.unknown().optional(),
28
+ example: z.unknown().optional(),
29
+ examples: z.record(z.string(), z.unknown()).optional(),
30
+ content: z.record(z.string(), z.unknown()).optional(),
31
+ });
32
+ export const referenceObject = z.object({
33
+ $ref: z.string(),
34
+ summary: z.string().optional(),
35
+ description: z.string().optional(),
36
+ });
37
+ export const openapiOperation = z
38
+ .object({
39
+ tags: z.array(z.string()),
40
+ summary: z.string(),
41
+ description: z.string(),
42
+ externalDocs: z.unknown(),
43
+ operationId: z.string(),
44
+ parameters: z.array(parameterObject.or(referenceObject)),
45
+ requestBody: z.unknown(),
46
+ responses: z.unknown(),
47
+ callbacks: z.unknown(),
48
+ deprecated: z.boolean(),
49
+ security: z.array(z.record(z.string(), z.array(z.string()))),
50
+ servers: z.array(z.unknown()),
51
+ })
52
+ .partial();
53
+ // Path items have some fixed fields but also allow for extended fields starting with "x-".
54
+ //export const openapiPathItem = z.record(openapiOperation.or(serverObject).or(parameterObject));
55
+ export const openapiPathItem = z
56
+ .object({
57
+ summary: z.string(),
58
+ description: z.string(),
59
+ get: openapiOperation,
60
+ put: openapiOperation,
61
+ post: openapiOperation,
62
+ delete: openapiOperation,
63
+ options: openapiOperation,
64
+ head: openapiOperation,
65
+ patch: openapiOperation,
66
+ trace: openapiOperation,
67
+ servers: serverObject,
68
+ parameters: z.array(parameterObject),
69
+ })
70
+ .partial();
71
+ export const openapiSchema = z
72
+ .object({
73
+ openapi: z.string().regex(/^3\.\d\.\d(-.+)?$/),
74
+ info: z
75
+ .object({
76
+ title: z.string(),
77
+ description: z.string().optional(),
78
+ termsOfService: z.string().optional(),
79
+ contact: z
80
+ .object({
81
+ name: z.string().optional(),
82
+ url: z.string().optional(),
83
+ email: z.email().optional(),
84
+ })
85
+ .strict()
86
+ .optional(),
87
+ license: z
88
+ .object({ name: z.string(), url: z.string().optional() })
89
+ .strict()
90
+ .optional(),
91
+ version: z.string(),
92
+ })
93
+ .strict(),
94
+ externalDocs: z
95
+ .object({
96
+ description: z.string().optional(),
97
+ url: z.string(),
98
+ })
99
+ .strict()
100
+ .optional(),
101
+ servers: z
102
+ .array(z
103
+ .object({
104
+ url: z.string(),
105
+ description: z.string().optional(),
106
+ variables: z
107
+ .record(z.string(), z
108
+ .object({
109
+ enum: z.array(z.string()).optional(),
110
+ default: z.string(),
111
+ description: z.string().optional(),
112
+ })
113
+ .strict())
114
+ .optional(),
115
+ })
116
+ .strict())
117
+ .optional(),
118
+ security: z.array(z.record(z.string(), z.array(z.string()))).optional(),
119
+ tags: z
120
+ .array(z
121
+ .object({
122
+ name: z.string(),
123
+ description: z.string().optional(),
124
+ externalDocs: z
125
+ .object({
126
+ description: z.string().optional(),
127
+ url: z.string(),
128
+ })
129
+ .strict()
130
+ .optional(),
131
+ })
132
+ .strict())
133
+ .optional(),
134
+ paths: z.record(z.string(), openapiPathItem),
135
+ components: z
136
+ .object({
137
+ schemas: z.record(z.string(), z.any()).optional(),
138
+ responses: z.record(z.string(), z.any()).optional(),
139
+ parameters: z.record(z.string(), z.any()).optional(),
140
+ examples: z.record(z.string(), z.any()).optional(),
141
+ requestBodies: z.record(z.string(), z.any()).optional(),
142
+ headers: z.record(z.string(), z.any()).optional(),
143
+ securitySchemes: z.record(z.string(), z.any()).optional(),
144
+ links: z.record(z.string(), z.any()).optional(),
145
+ callbacks: z.record(z.string(), z.any()).optional(),
146
+ })
147
+ .strict()
148
+ .optional(),
149
+ })
150
+ .describe("The description of OpenAPI v3.0.x documents, as defined by https://spec.openapis.org/oas/v3.0.3");
151
+ //# sourceMappingURL=openapi-schema.js.map
@@ -0,0 +1,11 @@
1
+ export declare enum TrafficType {
2
+ ROAD = "Road",
3
+ MARINE = "Marine",
4
+ RAIL = "Rail",
5
+ PARKING = "Parking",
6
+ AVIATION = "Aviation",
7
+ AFIR = "Afir",
8
+ MCP = "MCP",
9
+ CATALOG = "Catalog",
10
+ OTHER = "Other"
11
+ }
@@ -0,0 +1,13 @@
1
+ export var TrafficType;
2
+ (function (TrafficType) {
3
+ TrafficType["ROAD"] = "Road";
4
+ TrafficType["MARINE"] = "Marine";
5
+ TrafficType["RAIL"] = "Rail";
6
+ TrafficType["PARKING"] = "Parking";
7
+ TrafficType["AVIATION"] = "Aviation";
8
+ TrafficType["AFIR"] = "Afir";
9
+ TrafficType["MCP"] = "MCP";
10
+ TrafficType["CATALOG"] = "Catalog";
11
+ TrafficType["OTHER"] = "Other";
12
+ })(TrafficType || (TrafficType = {}));
13
+ //# sourceMappingURL=traffictype.js.map
@@ -0,0 +1 @@
1
+ export type URN<Namespace extends string, NamespaceSpecificString extends string = ""> = `urn:${Namespace}:${NamespaceSpecificString}`;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=urn.js.map
@@ -0,0 +1,11 @@
1
+ export type ValueOf<Obj> = Obj[keyof Obj];
2
+ /**
3
+ * Type-level conversion from readonly object to mutable object. Use with caution!
4
+ *
5
+ * Only converts in the type-level. Caution must be used, as the typescript cannot enforce readonly-ness at
6
+ * runtime. This is only useful for type-checking and especially in cases where 3rd party code requires
7
+ * mutable even though it is not needed.
8
+ */
9
+ export type Writable<T> = {
10
+ -readonly [P in keyof T]: T[P];
11
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=util-types.js.map
@@ -0,0 +1,4 @@
1
+ export declare const MIN_YEAR = 1900;
2
+ export declare const MAX_YEAR = 2100;
3
+ export declare function validateYear(year: number, minYear?: number, maxYear?: number): boolean;
4
+ export declare function validateMonth(month: number): boolean;
@@ -0,0 +1,9 @@
1
+ export const MIN_YEAR = 1900;
2
+ export const MAX_YEAR = 2100;
3
+ export function validateYear(year, minYear = MIN_YEAR, maxYear = MAX_YEAR) {
4
+ return year >= minYear && year <= maxYear;
5
+ }
6
+ export function validateMonth(month) {
7
+ return month > 0 && month < 13;
8
+ }
9
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1,51 @@
1
+ import type { JsonSchema, Model, RequestValidator, RestApi } from "aws-cdk-lib/aws-apigateway";
2
+ import type { ModelWithReference } from "../aws/types/model-with-reference.js";
3
+ type ModelReferenceUrl = `https://apigateway.amazonaws.com/restapis/${string}/models/${string}`;
4
+ /**
5
+ * Get a reference to an OpenAPI model object in a REST API.
6
+ * Can be used to supply a reference to properties of a GeoJSON feature.
7
+ * @param modelId Id of the referenced object
8
+ * @param restApiId Id of the REST API
9
+ */
10
+ export declare function getModelReference(modelId: string, restApiId: string): ModelReferenceUrl;
11
+ /**
12
+ * Adds a request validator to a REST API to enforce request parameters/body requirements.
13
+ * https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-request-validation.html
14
+ * @param api REST API
15
+ */
16
+ export declare function addDefaultValidator(api: RestApi): RequestValidator;
17
+ /**
18
+ * Adds a JSON Schema model to an API Gateway API. Can be used later to generate OpenAPI specifications.
19
+ * This method adds a schema for _a single object._
20
+ * @param modelName
21
+ * @param api REST API
22
+ * @param schema JSON Schema
23
+ * @return ModelWithReference A model object with a reference to an API Gateway model object.
24
+ */
25
+ export declare function addServiceModel(modelName: string, api: RestApi, schema: JsonSchema): ModelWithReference;
26
+ /**
27
+ * Add an empty JSON schema model to an API Gateway API.
28
+ * Usable for example if the incoming data is in XML format but some template transformation is necessary.
29
+ * @param modelName
30
+ * @param api
31
+ * @param contentType
32
+ */
33
+ export declare function addSimpleServiceModel(modelName: string, api: RestApi, contentType?: `${string}/${string}`): Model;
34
+ /**
35
+ * Adds a JSON Schema model to an API Gateway API. Can be used later to generate OpenAPI specifications.
36
+ * This method adds a schema for _an array._
37
+ * @param model
38
+ * @param api
39
+ */
40
+ export declare function createArraySchema(model: Model, api: RestApi): JsonSchema;
41
+ /**
42
+ * Creates a JSON Schema for a GeoJSON Feature. Can be used to generate OpenAPI descriptions.
43
+ * @param modelReference Reference to a model object
44
+ */
45
+ export declare function featureSchema(modelReference: string): JsonSchema;
46
+ /**
47
+ * Creates a JSON Schema for a GeoJSON Feature Collection. Can be used to generate OpenAPI descriptions.
48
+ * @param modelReference Reference to a model object, in this case Features.
49
+ */
50
+ export declare function geojsonSchema(modelReference: string): JsonSchema;
51
+ export {};
@@ -0,0 +1,118 @@
1
+ import { JsonSchemaType, JsonSchemaVersion } from "aws-cdk-lib/aws-apigateway";
2
+ /**
3
+ * Get a reference to an OpenAPI model object in a REST API.
4
+ * Can be used to supply a reference to properties of a GeoJSON feature.
5
+ * @param modelId Id of the referenced object
6
+ * @param restApiId Id of the REST API
7
+ */
8
+ export function getModelReference(modelId, restApiId) {
9
+ return `https://apigateway.amazonaws.com/restapis/${restApiId}/models/${modelId}`;
10
+ }
11
+ /**
12
+ * Adds a request validator to a REST API to enforce request parameters/body requirements.
13
+ * https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-request-validation.html
14
+ * @param api REST API
15
+ */
16
+ export function addDefaultValidator(api) {
17
+ return api.addRequestValidator("DefaultValidator", {
18
+ validateRequestParameters: true,
19
+ validateRequestBody: true,
20
+ });
21
+ }
22
+ /**
23
+ * Adds a JSON Schema model to an API Gateway API. Can be used later to generate OpenAPI specifications.
24
+ * This method adds a schema for _a single object._
25
+ * @param modelName
26
+ * @param api REST API
27
+ * @param schema JSON Schema
28
+ * @return ModelWithReference A model object with a reference to an API Gateway model object.
29
+ */
30
+ export function addServiceModel(modelName, api, schema) {
31
+ const mwr = api.addModel(modelName, {
32
+ contentType: "application/json",
33
+ modelName,
34
+ schema,
35
+ });
36
+ mwr.modelReference = getModelReference(mwr.modelId, api.restApiId);
37
+ return mwr;
38
+ }
39
+ /**
40
+ * Add an empty JSON schema model to an API Gateway API.
41
+ * Usable for example if the incoming data is in XML format but some template transformation is necessary.
42
+ * @param modelName
43
+ * @param api
44
+ * @param contentType
45
+ */
46
+ export function addSimpleServiceModel(modelName, api, contentType = "application/xml") {
47
+ return api.addModel(modelName, {
48
+ contentType,
49
+ modelName,
50
+ schema: {},
51
+ });
52
+ }
53
+ /**
54
+ * Adds a JSON Schema model to an API Gateway API. Can be used later to generate OpenAPI specifications.
55
+ * This method adds a schema for _an array._
56
+ * @param model
57
+ * @param api
58
+ */
59
+ export function createArraySchema(model, api) {
60
+ return {
61
+ type: JsonSchemaType.ARRAY,
62
+ items: {
63
+ ref: getModelReference(model.modelId, api.restApiId),
64
+ },
65
+ };
66
+ }
67
+ /**
68
+ * Creates a JSON Schema for a GeoJSON Feature. Can be used to generate OpenAPI descriptions.
69
+ * @param modelReference Reference to a model object
70
+ */
71
+ export function featureSchema(modelReference) {
72
+ return {
73
+ schema: JsonSchemaVersion.DRAFT4,
74
+ type: JsonSchemaType.OBJECT,
75
+ description: "GeoJson Feature",
76
+ required: ["type", "properties", "geometry"],
77
+ properties: {
78
+ type: {
79
+ type: JsonSchemaType.STRING,
80
+ description: "Feature",
81
+ enum: ["Feature"],
82
+ },
83
+ properties: {
84
+ ref: modelReference,
85
+ },
86
+ geometry: {
87
+ type: JsonSchemaType.OBJECT,
88
+ description: "GeoJSON geometry",
89
+ },
90
+ },
91
+ };
92
+ }
93
+ /**
94
+ * Creates a JSON Schema for a GeoJSON Feature Collection. Can be used to generate OpenAPI descriptions.
95
+ * @param modelReference Reference to a model object, in this case Features.
96
+ */
97
+ export function geojsonSchema(modelReference) {
98
+ return {
99
+ schema: JsonSchemaVersion.DRAFT4,
100
+ type: JsonSchemaType.OBJECT,
101
+ description: "GeoJson FeatureCollection",
102
+ required: ["type", "features"],
103
+ properties: {
104
+ type: {
105
+ type: JsonSchemaType.STRING,
106
+ description: "FeatureCollection",
107
+ enum: ["FeatureCollection"],
108
+ },
109
+ features: {
110
+ type: JsonSchemaType.ARRAY,
111
+ items: {
112
+ ref: modelReference,
113
+ },
114
+ },
115
+ },
116
+ };
117
+ }
118
+ //# sourceMappingURL=api-model.js.map
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Encode given string to base64
3
+ * @param str
4
+ * @param encoding
5
+ */
6
+ export declare function encodeBase64(str: string, encoding: BufferEncoding): string;
7
+ /**
8
+ * Decode given string from base64 to given encoding
9
+ * @param str
10
+ * @param encoding
11
+ */
12
+ export declare function decodeBase64(str: string, encoding: BufferEncoding): string;
13
+ /**
14
+ * Encode given string from ascii to Base64 string
15
+ * @param token
16
+ */
17
+ export declare function encodeAsciiToBase64(token: string): string;
18
+ /**
19
+ * Decode given string from base64 to ascii
20
+ * @param str string
21
+ */
22
+ export declare function decodeBase64ToAscii(str: string): string;
23
+ /**
24
+ * Encode given string from base64 to utf8 string
25
+ * @param str
26
+ */
27
+ export declare function encodeUtf8ToBase64(str: string): string;
28
+ /**
29
+ * Decode given string from base64 to utf8 string. If compressed is true, decompresses it first.
30
+ * @param str String to decode from base64.
31
+ * @param compressed Whether the input string is compressed (gzip) or not.
32
+ */
33
+ export declare function decodeBase64ToUtf8(str: string, compressed?: boolean): string;
34
+ export declare function compressBuffer(buffer: Buffer): Buffer;
@@ -0,0 +1,53 @@
1
+ import * as zlib from "node:zlib";
2
+ /**
3
+ * Encode given string to base64
4
+ * @param str
5
+ * @param encoding
6
+ */
7
+ export function encodeBase64(str, encoding) {
8
+ return Buffer.from(str, encoding).toString("base64");
9
+ }
10
+ /**
11
+ * Decode given string from base64 to given encoding
12
+ * @param str
13
+ * @param encoding
14
+ */
15
+ export function decodeBase64(str, encoding) {
16
+ return Buffer.from(str, "base64").toString(encoding);
17
+ }
18
+ /**
19
+ * Encode given string from ascii to Base64 string
20
+ * @param token
21
+ */
22
+ export function encodeAsciiToBase64(token) {
23
+ return encodeBase64(token, "ascii");
24
+ }
25
+ /**
26
+ * Decode given string from base64 to ascii
27
+ * @param str string
28
+ */
29
+ export function decodeBase64ToAscii(str) {
30
+ return decodeBase64(str, "ascii");
31
+ }
32
+ /**
33
+ * Encode given string from base64 to utf8 string
34
+ * @param str
35
+ */
36
+ export function encodeUtf8ToBase64(str) {
37
+ return encodeBase64(str, "utf8");
38
+ }
39
+ /**
40
+ * Decode given string from base64 to utf8 string. If compressed is true, decompresses it first.
41
+ * @param str String to decode from base64.
42
+ * @param compressed Whether the input string is compressed (gzip) or not.
43
+ */
44
+ export function decodeBase64ToUtf8(str, compressed = false) {
45
+ const buffer = Buffer.from(str, "base64");
46
+ return compressed
47
+ ? zlib.gunzipSync(buffer).toString("utf8")
48
+ : buffer.toString("utf8");
49
+ }
50
+ export function compressBuffer(buffer) {
51
+ return zlib.gzipSync(buffer);
52
+ }
53
+ //# sourceMappingURL=base64.js.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Constant for the 1970-01-01T00:00:00Z epoch Date.
3
+ */
4
+ export declare const EPOCH: Date;
5
+ export declare const UTC = "UTC";
6
+ export declare const MYSQL_DATETIME_FORMAT = "yyyy-MM-dd HH:mm";
7
+ /**
8
+ * Counts difference in milliseconds between dates.
9
+ * @param start
10
+ * @param end
11
+ */
12
+ export declare function countDiffMs(start: Date, end: Date): number;
13
+ /**
14
+ * Counts difference in seconds between dates.
15
+ * @param start
16
+ * @param end
17
+ */
18
+ export declare function countDiffInSeconds(start: Date, end: Date): number;
19
+ /**
20
+ * Converts ISO 8601 date-time -string to Date object
21
+ * @param isoString to convert
22
+ */
23
+ export declare function dateFromIsoString(isoString: string): Date;
24
+ /**
25
+ * Formats a date in UTC in the given format, regardless of system time zone
26
+ */
27
+ export declare function dateToUTCString(date: Date, formatString: string): string;
@@ -0,0 +1,45 @@
1
+ import { TZDate } from "@date-fns/tz";
2
+ import { format } from "date-fns";
3
+ /**
4
+ * Constant for the 1970-01-01T00:00:00Z epoch Date.
5
+ */
6
+ export const EPOCH = new Date(Date.UTC(1970, 0, 1));
7
+ export const UTC = "UTC";
8
+ export const MYSQL_DATETIME_FORMAT = "yyyy-MM-dd HH:mm";
9
+ /**
10
+ * Counts difference in milliseconds between dates.
11
+ * @param start
12
+ * @param end
13
+ */
14
+ export function countDiffMs(start, end) {
15
+ return end.getTime() - start.getTime();
16
+ }
17
+ /**
18
+ * Counts difference in seconds between dates.
19
+ * @param start
20
+ * @param end
21
+ */
22
+ export function countDiffInSeconds(start, end) {
23
+ return countDiffMs(start, end) / 1000;
24
+ }
25
+ /**
26
+ * Converts ISO 8601 date-time -string to Date object
27
+ * @param isoString to convert
28
+ */
29
+ export function dateFromIsoString(isoString) {
30
+ const parsed = new Date(isoString);
31
+ if (!isValidDate(parsed)) {
32
+ throw new Error(`Could not parse iso date-time string: "${isoString}" to date`);
33
+ }
34
+ return parsed;
35
+ }
36
+ function isValidDate(d) {
37
+ return d instanceof Date && !Number.isNaN(d.getTime());
38
+ }
39
+ /**
40
+ * Formats a date in UTC in the given format, regardless of system time zone
41
+ */
42
+ export function dateToUTCString(date, formatString) {
43
+ return format(new TZDate(date, UTC), formatString);
44
+ }
45
+ //# sourceMappingURL=date-utils.js.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * GeoJSON types
3
+ */
4
+ import type { LineString, Point, Position } from "geojson";
5
+ export declare class GeoJsonPoint implements Point {
6
+ readonly type: "Point";
7
+ readonly coordinates: Position;
8
+ constructor(coordinates: Position);
9
+ }
10
+ export declare class GeoJsonLineString implements LineString {
11
+ readonly type: "LineString";
12
+ readonly coordinates: Position[];
13
+ constructor(coordinates: Position[]);
14
+ }
@@ -0,0 +1,15 @@
1
+ export class GeoJsonPoint {
2
+ type = "Point";
3
+ coordinates;
4
+ constructor(coordinates) {
5
+ this.coordinates = coordinates;
6
+ }
7
+ }
8
+ export class GeoJsonLineString {
9
+ type = "LineString";
10
+ coordinates;
11
+ constructor(coordinates) {
12
+ this.coordinates = coordinates;
13
+ }
14
+ }
15
+ //# sourceMappingURL=geojson-types.js.map
@@ -0,0 +1,44 @@
1
+ /**
2
+ * GeoJSON functions and tools
3
+ */
4
+ import type { Feature, FeatureCollection, GeoJsonProperties, Geometry, Position } from "geojson";
5
+ export declare const SRID_WGS84 = 4326;
6
+ /**
7
+ * Creates WKT geometry from GeoJSON geometry
8
+ * @param geometry GeoJson geometry to convert to WKT
9
+ */
10
+ export declare function createGeometry(geometry: Geometry): string;
11
+ /**
12
+ * Create a GeoJSON FeatureCollection from a list of GeoJSON features with a 'last updated' property.
13
+ * Geometry is nullable. According to the GeoJSON specification, if coordinates are unavailable,
14
+ * the value of geometry should be null.
15
+ * @param features List of Features
16
+ * @param lastUpdated Last updated date
17
+ */
18
+ export declare function createFeatureCollection<G extends Geometry | null, P extends GeoJsonProperties>(features: Feature<G, P>[], lastUpdated: Date | null): FeatureCollection<G, P> & {
19
+ lastUpdated: Date | null;
20
+ };
21
+ export declare function isValidGeoJson<T>(json: T): boolean;
22
+ export declare function isFeatureCollection<T>(json: T): boolean;
23
+ /**
24
+ * Returns the distance between two WGS84 GeoJSON positions in kilometers. Doesn't take in account altitude.
25
+ * Based on the following Stack Overflow question:
26
+ * http://stackoverflow.com/questions/27928/calculate-distance-between-two-latitude-longitude-points-haversine-formula,
27
+ * which is based on https://en.wikipedia.org/wiki/Haversine_formula (error rate: ~0.55%).
28
+ * @param pos1 first position
29
+ * @param pos2 second position
30
+ */
31
+ export declare function distanceBetweenPositionsInKm(pos1: Position, pos2: Position): number;
32
+ export declare function areDistinctPositions(previous: Position, next: Position): boolean;
33
+ /**
34
+ * Calculates distance between two GeoJSON points (WGS84)
35
+ * @param pos1
36
+ * @param pos2
37
+ */
38
+ export declare function distanceBetweenPositionsInM(pos1: Position, pos2: Position): number;
39
+ export interface GmlLineString {
40
+ srsName: `${string}:${string}`;
41
+ posList: string;
42
+ }
43
+ export declare function createGmlLineString(geometry: Geometry, srsName?: `${string}:${string}`): GmlLineString;
44
+ export declare function positionToList(position: Position, precision?: number): string;