@terreno/api 0.31.0 → 56.0.0-beta.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.
Files changed (232) hide show
  1. package/dist/api.d.ts +10 -0
  2. package/dist/api.js +110 -361
  3. package/dist/auth.d.ts +26 -0
  4. package/dist/auth.js +121 -26
  5. package/dist/betterAuth.d.ts +5 -0
  6. package/dist/betterAuthSetup.js +23 -4
  7. package/dist/docLoader.js +12 -9
  8. package/dist/errors.d.ts +13 -0
  9. package/dist/errors.js +29 -1
  10. package/dist/index.d.ts +17 -1
  11. package/dist/index.js +29 -1
  12. package/dist/middleware.d.ts +7 -0
  13. package/dist/middleware.js +16 -1
  14. package/dist/openApiCompat.d.ts +10 -1
  15. package/dist/openApiCompat.js +115 -47
  16. package/dist/permissions.d.ts +27 -0
  17. package/dist/permissions.js +42 -1
  18. package/dist/plugins.d.ts +13 -0
  19. package/dist/plugins.js +47 -1
  20. package/dist/realtime/changeStreamWatcher.d.ts +100 -3
  21. package/dist/realtime/changeStreamWatcher.js +542 -137
  22. package/dist/realtime/realtimeApp.d.ts +2 -0
  23. package/dist/realtime/realtimeApp.js +83 -27
  24. package/dist/realtime/sessionRevalidation.d.ts +90 -0
  25. package/dist/realtime/sessionRevalidation.js +438 -0
  26. package/dist/realtime/socketAuth.d.ts +97 -0
  27. package/dist/realtime/socketAuth.js +272 -0
  28. package/dist/realtime/socketUser.d.ts +54 -0
  29. package/dist/realtime/socketUser.js +75 -5
  30. package/dist/realtime/types.d.ts +54 -0
  31. package/dist/secretProviders.d.ts +23 -0
  32. package/dist/secretProviders.js +9 -3
  33. package/dist/sync/executors.d.ts +198 -0
  34. package/dist/sync/executors.js +670 -0
  35. package/dist/sync/loadHarness.js +807 -0
  36. package/dist/sync/models.d.ts +216 -0
  37. package/dist/sync/models.js +644 -0
  38. package/dist/sync/mutationHandler.d.ts +97 -0
  39. package/dist/sync/mutationHandler.js +886 -0
  40. package/dist/sync/registry.d.ts +73 -0
  41. package/dist/sync/registry.js +223 -0
  42. package/dist/sync/routes.d.ts +62 -0
  43. package/dist/sync/routes.js +936 -0
  44. package/dist/sync/scripts/compactTombstones.d.ts +47 -0
  45. package/dist/sync/scripts/compactTombstones.js +270 -0
  46. package/dist/sync/serialize.d.ts +20 -0
  47. package/dist/{tests/bunSetup.js → sync/serialize.js} +35 -68
  48. package/dist/sync/socketHandlers.d.ts +54 -0
  49. package/dist/sync/socketHandlers.js +470 -0
  50. package/dist/sync/streams.d.ts +85 -0
  51. package/dist/sync/streams.js +221 -0
  52. package/dist/sync/syncApp.d.ts +29 -0
  53. package/dist/sync/syncApp.js +44 -0
  54. package/dist/sync/syncBatch.d.ts +71 -0
  55. package/dist/sync/syncBatch.js +252 -0
  56. package/dist/sync/syncSeqPlugin.d.ts +8 -0
  57. package/dist/sync/syncSeqPlugin.js +899 -0
  58. package/dist/sync/types.d.ts +254 -0
  59. package/dist/sync/types.js +9 -0
  60. package/dist/terrenoApp.js +90 -27
  61. package/dist/vendor/wesleytodd-openapi/index.d.ts +1 -1
  62. package/dist/vendor/wesleytodd-openapi/lib/ui.d.ts +2 -1
  63. package/package.json +7 -6
  64. package/src/__tests__/openApiCompat.test.ts +20 -0
  65. package/src/api.errors.test.ts +32 -23
  66. package/src/api.test.ts +12 -0
  67. package/src/api.ts +87 -296
  68. package/src/auth.test.ts +202 -0
  69. package/src/auth.ts +134 -23
  70. package/src/betterAuth.ts +6 -0
  71. package/src/betterAuthSetup.test.ts +34 -0
  72. package/src/betterAuthSetup.ts +20 -1
  73. package/src/configuration.test.ts +59 -38
  74. package/src/configurationPlugin.test.ts +72 -42
  75. package/src/docLoader.ts +3 -1
  76. package/src/errors.ts +33 -0
  77. package/src/expressServer.test.ts +7 -1
  78. package/src/index.ts +42 -0
  79. package/src/middleware.test.ts +56 -1
  80. package/src/middleware.ts +15 -0
  81. package/src/openApiCompat.ts +99 -45
  82. package/src/permissions.test.ts +101 -17
  83. package/src/permissions.ts +49 -0
  84. package/src/plugins.test.ts +64 -0
  85. package/src/plugins.ts +56 -0
  86. package/src/realtime/changeStreamWatcher.ts +552 -114
  87. package/src/realtime/realtime.test.ts +157 -0
  88. package/src/realtime/realtimeApp.ts +82 -14
  89. package/src/realtime/realtimeAppSetup.test.ts +25 -27
  90. package/src/realtime/sessionRevalidation.test.ts +423 -0
  91. package/src/realtime/sessionRevalidation.ts +273 -0
  92. package/src/realtime/socketAuth.test.ts +355 -0
  93. package/src/realtime/socketAuth.ts +228 -0
  94. package/src/realtime/socketUser.ts +69 -0
  95. package/src/realtime/types.ts +54 -0
  96. package/src/secretProviders.test.ts +7 -1
  97. package/src/secretProviders.ts +15 -3
  98. package/src/secretProvidersGcpClient.test.ts +66 -0
  99. package/src/sync/ensureSyncIndexes.test.ts +144 -0
  100. package/src/sync/executors.test.ts +882 -0
  101. package/src/sync/executors.ts +705 -0
  102. package/src/sync/integration.test.ts +1160 -0
  103. package/src/sync/loadHarness.ts +618 -0
  104. package/src/sync/models.ts +641 -0
  105. package/src/sync/mutationHandler.test.ts +1252 -0
  106. package/src/sync/mutationHandler.ts +850 -0
  107. package/src/sync/registry.ts +232 -0
  108. package/src/sync/routes.ts +812 -0
  109. package/src/sync/scripts/compactTombstones.test.ts +249 -0
  110. package/src/sync/scripts/compactTombstones.ts +145 -0
  111. package/src/sync/serialize.ts +48 -0
  112. package/src/sync/sessionRevalidationIntegration.test.ts +281 -0
  113. package/src/sync/socketHandlers.ts +320 -0
  114. package/src/sync/streams.ts +188 -0
  115. package/src/sync/sync.test.ts +582 -0
  116. package/src/sync/syncApp.ts +44 -0
  117. package/src/sync/syncBatch.ts +219 -0
  118. package/src/sync/syncFrontier.test.ts +494 -0
  119. package/src/sync/syncPhaseC.test.ts +718 -0
  120. package/src/sync/syncRoutes.test.ts +865 -0
  121. package/src/sync/syncSeqPlugin.ts +730 -0
  122. package/src/sync/syncSocket.test.ts +1440 -0
  123. package/src/sync/types.ts +270 -0
  124. package/src/terrenoApp.ts +37 -17
  125. package/src/tests/bunSetup.ts +8 -0
  126. package/tsconfig.json +4 -4
  127. package/tsconfig.typedoc.json +7 -1
  128. package/dist/__tests__/openApiCompat.test.js +0 -317
  129. package/dist/__tests__/versionCheckPlugin.test.d.ts +0 -1
  130. package/dist/__tests__/versionCheckPlugin.test.js +0 -597
  131. package/dist/actions.openApi.test.d.ts +0 -1
  132. package/dist/actions.openApi.test.js +0 -253
  133. package/dist/actions.test.d.ts +0 -1
  134. package/dist/actions.test.js +0 -1087
  135. package/dist/api.arrayOperations.test.d.ts +0 -1
  136. package/dist/api.arrayOperations.test.js +0 -878
  137. package/dist/api.asyncHandler.test.d.ts +0 -1
  138. package/dist/api.asyncHandler.test.js +0 -236
  139. package/dist/api.coverage.test.d.ts +0 -1
  140. package/dist/api.coverage.test.js +0 -192
  141. package/dist/api.errorPaths.test.d.ts +0 -1
  142. package/dist/api.errorPaths.test.js +0 -887
  143. package/dist/api.errors.test.d.ts +0 -1
  144. package/dist/api.errors.test.js +0 -185
  145. package/dist/api.hooks.test.d.ts +0 -1
  146. package/dist/api.hooks.test.js +0 -950
  147. package/dist/api.query.test.d.ts +0 -1
  148. package/dist/api.query.test.js +0 -948
  149. package/dist/api.test.d.ts +0 -1
  150. package/dist/api.test.js +0 -2820
  151. package/dist/auth.compile.test.d.ts +0 -1
  152. package/dist/auth.compile.test.js +0 -201
  153. package/dist/auth.coverage.test.d.ts +0 -1
  154. package/dist/auth.coverage.test.js +0 -202
  155. package/dist/auth.test.d.ts +0 -1
  156. package/dist/auth.test.js +0 -2286
  157. package/dist/betterAuth.test.d.ts +0 -1
  158. package/dist/betterAuth.test.js +0 -181
  159. package/dist/betterAuthApp.test.d.ts +0 -1
  160. package/dist/betterAuthApp.test.js +0 -242
  161. package/dist/betterAuthSetup.test.d.ts +0 -1
  162. package/dist/betterAuthSetup.test.js +0 -762
  163. package/dist/config.test.d.ts +0 -1
  164. package/dist/config.test.js +0 -353
  165. package/dist/configuration.test.d.ts +0 -1
  166. package/dist/configuration.test.js +0 -980
  167. package/dist/configurationPlugin.test.d.ts +0 -1
  168. package/dist/configurationPlugin.test.js +0 -827
  169. package/dist/consentApp.test.d.ts +0 -1
  170. package/dist/consentApp.test.js +0 -1411
  171. package/dist/docLoader.test.d.ts +0 -1
  172. package/dist/docLoader.test.js +0 -137
  173. package/dist/envConfigurationPlugin.test.d.ts +0 -1
  174. package/dist/envConfigurationPlugin.test.js +0 -369
  175. package/dist/errors.test.d.ts +0 -1
  176. package/dist/errors.test.js +0 -607
  177. package/dist/expressServer.test.d.ts +0 -1
  178. package/dist/expressServer.test.js +0 -1249
  179. package/dist/githubAuth.test.d.ts +0 -1
  180. package/dist/githubAuth.test.js +0 -1142
  181. package/dist/httpClient.test.d.ts +0 -1
  182. package/dist/httpClient.test.js +0 -1471
  183. package/dist/logger.test.d.ts +0 -1
  184. package/dist/logger.test.js +0 -685
  185. package/dist/middleware.test.d.ts +0 -1
  186. package/dist/middleware.test.js +0 -241
  187. package/dist/notifiers/googleChatNotifier.test.d.ts +0 -1
  188. package/dist/notifiers/googleChatNotifier.test.js +0 -298
  189. package/dist/notifiers/slackNotifier.test.d.ts +0 -1
  190. package/dist/notifiers/slackNotifier.test.js +0 -297
  191. package/dist/notifiers/zoomNotifier.test.d.ts +0 -1
  192. package/dist/notifiers/zoomNotifier.test.js +0 -373
  193. package/dist/openApi.test.d.ts +0 -1
  194. package/dist/openApi.test.js +0 -620
  195. package/dist/openApiBuilder.test.d.ts +0 -1
  196. package/dist/openApiBuilder.test.js +0 -599
  197. package/dist/openApiEtag.test.d.ts +0 -1
  198. package/dist/openApiEtag.test.js +0 -86
  199. package/dist/openApiValidator.test.d.ts +0 -1
  200. package/dist/openApiValidator.test.js +0 -795
  201. package/dist/permissions.middleware.test.d.ts +0 -1
  202. package/dist/permissions.middleware.test.js +0 -308
  203. package/dist/permissions.test.d.ts +0 -1
  204. package/dist/permissions.test.js +0 -439
  205. package/dist/plugins.test.d.ts +0 -1
  206. package/dist/plugins.test.js +0 -902
  207. package/dist/populate.test.d.ts +0 -1
  208. package/dist/populate.test.js +0 -370
  209. package/dist/realtime/realtime.test.d.ts +0 -10
  210. package/dist/realtime/realtime.test.js +0 -4213
  211. package/dist/realtime/realtimeAppSetup.test.d.ts +0 -1
  212. package/dist/realtime/realtimeAppSetup.test.js +0 -213
  213. package/dist/requestContext.test.d.ts +0 -1
  214. package/dist/requestContext.test.js +0 -412
  215. package/dist/scriptRunner.test.d.ts +0 -1
  216. package/dist/scriptRunner.test.js +0 -386
  217. package/dist/secretProviders.test.d.ts +0 -1
  218. package/dist/secretProviders.test.js +0 -726
  219. package/dist/syncConsents.test.d.ts +0 -1
  220. package/dist/syncConsents.test.js +0 -522
  221. package/dist/terrenoApp.test.d.ts +0 -1
  222. package/dist/terrenoApp.test.js +0 -489
  223. package/dist/tests/bunSetup.d.ts +0 -1
  224. package/dist/tests/fixtures/compileAuthEntry.d.ts +0 -1
  225. package/dist/tests/fixtures/compileAuthEntry.js +0 -37
  226. package/dist/tests/testEnv.d.ts +0 -0
  227. package/dist/tests/testEnv.js +0 -6
  228. package/dist/transformers.test.d.ts +0 -1
  229. package/dist/transformers.test.js +0 -423
  230. package/dist/utils.test.d.ts +0 -1
  231. package/dist/utils.test.js +0 -242
  232. /package/dist/{__tests__/openApiCompat.test.d.ts → sync/loadHarness.d.ts} +0 -0
@@ -1 +0,0 @@
1
- export {};
@@ -1,353 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __values = (this && this.__values) || function(o) {
39
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
40
- if (m) return m.call(o);
41
- if (o && typeof o.length === "number") return {
42
- next: function () {
43
- if (o && i >= o.length) o = void 0;
44
- return { value: o && o[i++], done: !o };
45
- }
46
- };
47
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
- };
49
- var __read = (this && this.__read) || function (o, n) {
50
- var m = typeof Symbol === "function" && o[Symbol.iterator];
51
- if (!m) return o;
52
- var i = m.call(o), r, ar = [], e;
53
- try {
54
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
55
- }
56
- catch (error) { e = { error: error }; }
57
- finally {
58
- try {
59
- if (r && !r.done && (m = i["return"])) m.call(i);
60
- }
61
- finally { if (e) throw e.error; }
62
- }
63
- return ar;
64
- };
65
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
66
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
67
- if (ar || !(i in from)) {
68
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
69
- ar[i] = from[i];
70
- }
71
- }
72
- return to.concat(ar || Array.prototype.slice.call(from));
73
- };
74
- Object.defineProperty(exports, "__esModule", { value: true });
75
- var bun_test_1 = require("bun:test");
76
- var config_1 = require("./config");
77
- var errors_1 = require("./errors");
78
- var KEYS = [
79
- "TERRENO_CFG_STRING",
80
- "TERRENO_CFG_DEFAULTED",
81
- "TERRENO_CFG_NUM",
82
- "TERRENO_CFG_BOOL",
83
- "TERRENO_CFG_JSON",
84
- "TERRENO_CFG_UNDEFAULTED",
85
- "TERRENO_CFG_UNREGISTERED",
86
- ];
87
- var resetEnv = function () {
88
- var e_1, _a;
89
- try {
90
- for (var KEYS_1 = __values(KEYS), KEYS_1_1 = KEYS_1.next(); !KEYS_1_1.done; KEYS_1_1 = KEYS_1.next()) {
91
- var key = KEYS_1_1.value;
92
- Reflect.deleteProperty(process.env, key);
93
- }
94
- }
95
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
96
- finally {
97
- try {
98
- if (KEYS_1_1 && !KEYS_1_1.done && (_a = KEYS_1.return)) _a.call(KEYS_1);
99
- }
100
- finally { if (e_1) throw e_1.error; }
101
- }
102
- };
103
- (0, bun_test_1.describe)("Config", function () {
104
- (0, bun_test_1.beforeEach)(function () {
105
- config_1.Config.clearRegistryForTesting();
106
- config_1.Config.clearOverrides();
107
- config_1.Config.setCachedEnv(null);
108
- config_1.Config.setEnvLoader(null);
109
- resetEnv();
110
- config_1.Config.register("TERRENO_CFG_STRING");
111
- config_1.Config.register("TERRENO_CFG_DEFAULTED", { default: "fallback" });
112
- config_1.Config.register("TERRENO_CFG_NUM", { default: "1000" });
113
- config_1.Config.register("TERRENO_CFG_BOOL", { default: "false" });
114
- config_1.Config.register("TERRENO_CFG_JSON", { default: "{}" });
115
- config_1.Config.register("TERRENO_CFG_UNDEFAULTED");
116
- });
117
- (0, bun_test_1.afterEach)(function () {
118
- resetEnv();
119
- config_1.Config.clearRegistryForTesting();
120
- config_1.Config.clearOverrides();
121
- config_1.Config.setCachedEnv(null);
122
- config_1.Config.setEnvLoader(null);
123
- });
124
- (0, bun_test_1.describe)("resolution order", function () {
125
- (0, bun_test_1.it)("returns the registered default when nothing is set", function () {
126
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_DEFAULTED")).toBe("fallback");
127
- });
128
- (0, bun_test_1.it)("returns process.env when set and no cache/override is present", function () {
129
- process.env.TERRENO_CFG_STRING = "fromEnv";
130
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_STRING")).toBe("fromEnv");
131
- });
132
- (0, bun_test_1.it)("cache wins over process.env", function () {
133
- process.env.TERRENO_CFG_STRING = "fromEnv";
134
- config_1.Config.setCachedEnv({ TERRENO_CFG_STRING: "fromCache" });
135
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_STRING")).toBe("fromCache");
136
- });
137
- (0, bun_test_1.it)("override wins over cache and process.env", function () {
138
- process.env.TERRENO_CFG_STRING = "fromEnv";
139
- config_1.Config.setCachedEnv({ TERRENO_CFG_STRING: "fromCache" });
140
- config_1.Config.setOverride("TERRENO_CFG_STRING", "fromOverride");
141
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_STRING")).toBe("fromOverride");
142
- });
143
- (0, bun_test_1.it)("falls through empty-string cache values to process.env", function () {
144
- process.env.TERRENO_CFG_STRING = "fromEnv";
145
- config_1.Config.setCachedEnv({ TERRENO_CFG_STRING: "" });
146
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_STRING")).toBe("fromEnv");
147
- });
148
- (0, bun_test_1.it)("falls through empty-string process.env to default", function () {
149
- process.env.TERRENO_CFG_DEFAULTED = "";
150
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_DEFAULTED")).toBe("fallback");
151
- });
152
- (0, bun_test_1.it)("returns undefined for an unregistered key with nothing set", function () {
153
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_UNREGISTERED")).toBeUndefined();
154
- });
155
- (0, bun_test_1.it)("returns process.env for an unregistered key when set", function () {
156
- process.env.TERRENO_CFG_UNREGISTERED = "value";
157
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_UNREGISTERED")).toBe("value");
158
- });
159
- (0, bun_test_1.it)("setOverride(key, undefined) is treated as 'force unset'", function () {
160
- process.env.TERRENO_CFG_STRING = "fromEnv";
161
- config_1.Config.setOverride("TERRENO_CFG_STRING", undefined);
162
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_STRING")).toBeUndefined();
163
- });
164
- });
165
- (0, bun_test_1.describe)("getNumber", function () {
166
- (0, bun_test_1.it)("parses numeric process.env values", function () {
167
- process.env.TERRENO_CFG_NUM = "5000";
168
- (0, bun_test_1.expect)(config_1.Config.getNumber("TERRENO_CFG_NUM")).toBe(5000);
169
- });
170
- (0, bun_test_1.it)("parses the registered default", function () {
171
- (0, bun_test_1.expect)(config_1.Config.getNumber("TERRENO_CFG_NUM")).toBe(1000);
172
- });
173
- (0, bun_test_1.it)("returns undefined when no value is available", function () {
174
- (0, bun_test_1.expect)(config_1.Config.getNumber("TERRENO_CFG_UNDEFAULTED")).toBeUndefined();
175
- });
176
- (0, bun_test_1.it)("throws on non-numeric values", function () {
177
- process.env.TERRENO_CFG_NUM = "not-a-number";
178
- try {
179
- config_1.Config.getNumber("TERRENO_CFG_NUM");
180
- bun_test_1.expect.unreachable("expected throw");
181
- }
182
- catch (error) {
183
- (0, bun_test_1.expect)(error).toBeInstanceOf(errors_1.APIError);
184
- (0, bun_test_1.expect)(error.title).toBe("Invalid config value");
185
- (0, bun_test_1.expect)(error.detail).toContain("not a valid number");
186
- }
187
- });
188
- (0, bun_test_1.it)("throws on partially-numeric strings like '5000ms'", function () {
189
- process.env.TERRENO_CFG_NUM = "5000ms";
190
- try {
191
- config_1.Config.getNumber("TERRENO_CFG_NUM");
192
- bun_test_1.expect.unreachable("expected throw");
193
- }
194
- catch (error) {
195
- (0, bun_test_1.expect)(error).toBeInstanceOf(errors_1.APIError);
196
- (0, bun_test_1.expect)(error.title).toBe("Invalid config value");
197
- (0, bun_test_1.expect)(error.detail).toContain("not a valid number");
198
- }
199
- });
200
- (0, bun_test_1.it)("supports floats", function () {
201
- process.env.TERRENO_CFG_NUM = "3.14";
202
- (0, bun_test_1.expect)(config_1.Config.getNumber("TERRENO_CFG_NUM")).toBe(3.14);
203
- });
204
- });
205
- (0, bun_test_1.describe)("getBoolean", function () {
206
- (0, bun_test_1.it)("returns true for 'true'", function () {
207
- process.env.TERRENO_CFG_BOOL = "true";
208
- (0, bun_test_1.expect)(config_1.Config.getBoolean("TERRENO_CFG_BOOL")).toBe(true);
209
- });
210
- (0, bun_test_1.it)("returns true for 'TRUE' (case-insensitive)", function () {
211
- process.env.TERRENO_CFG_BOOL = "TRUE";
212
- (0, bun_test_1.expect)(config_1.Config.getBoolean("TERRENO_CFG_BOOL")).toBe(true);
213
- });
214
- (0, bun_test_1.it)("returns false for 'false'", function () {
215
- process.env.TERRENO_CFG_BOOL = "false";
216
- (0, bun_test_1.expect)(config_1.Config.getBoolean("TERRENO_CFG_BOOL")).toBe(false);
217
- });
218
- (0, bun_test_1.it)("returns false when unset and default is 'false'", function () {
219
- (0, bun_test_1.expect)(config_1.Config.getBoolean("TERRENO_CFG_BOOL")).toBe(false);
220
- });
221
- (0, bun_test_1.it)("returns false for any non-true string", function () {
222
- process.env.TERRENO_CFG_BOOL = "yes";
223
- (0, bun_test_1.expect)(config_1.Config.getBoolean("TERRENO_CFG_BOOL")).toBe(false);
224
- });
225
- });
226
- (0, bun_test_1.describe)("getJSON", function () {
227
- (0, bun_test_1.it)("parses valid JSON", function () {
228
- process.env.TERRENO_CFG_JSON = JSON.stringify({ hook: "https://example.com" });
229
- (0, bun_test_1.expect)(config_1.Config.getJSON("TERRENO_CFG_JSON")).toEqual({
230
- hook: "https://example.com",
231
- });
232
- });
233
- (0, bun_test_1.it)("parses the registered default", function () {
234
- (0, bun_test_1.expect)(config_1.Config.getJSON("TERRENO_CFG_JSON")).toEqual({});
235
- });
236
- (0, bun_test_1.it)("returns undefined when nothing is set and no default exists", function () {
237
- (0, bun_test_1.expect)(config_1.Config.getJSON("TERRENO_CFG_UNDEFAULTED")).toBeUndefined();
238
- });
239
- (0, bun_test_1.it)("throws on malformed JSON instead of silently returning undefined", function () {
240
- process.env.TERRENO_CFG_JSON = "{not json";
241
- try {
242
- config_1.Config.getJSON("TERRENO_CFG_JSON");
243
- bun_test_1.expect.unreachable("expected throw");
244
- }
245
- catch (error) {
246
- (0, bun_test_1.expect)(error).toBeInstanceOf(errors_1.APIError);
247
- (0, bun_test_1.expect)(error.title).toBe("Invalid config value");
248
- (0, bun_test_1.expect)(error.detail).toContain("not valid JSON");
249
- }
250
- });
251
- });
252
- (0, bun_test_1.describe)("registry", function () {
253
- (0, bun_test_1.it)("exposes registered keys in sorted order", function () {
254
- var keys = config_1.Config.getRegisteredKeys();
255
- var sorted = __spreadArray([], __read(keys), false).sort();
256
- (0, bun_test_1.expect)(keys).toEqual(sorted);
257
- });
258
- (0, bun_test_1.it)("isRegistered returns true for known keys", function () {
259
- (0, bun_test_1.expect)(config_1.Config.isRegistered("TERRENO_CFG_STRING")).toBe(true);
260
- });
261
- (0, bun_test_1.it)("isRegistered returns false for unknown keys", function () {
262
- (0, bun_test_1.expect)(config_1.Config.isRegistered("NOT_A_REAL_KEY")).toBe(false);
263
- });
264
- (0, bun_test_1.it)("getDefault returns the registered default", function () {
265
- (0, bun_test_1.expect)(config_1.Config.getDefault("TERRENO_CFG_DEFAULTED")).toBe("fallback");
266
- });
267
- (0, bun_test_1.it)("getDefault returns undefined for keys with no default", function () {
268
- (0, bun_test_1.expect)(config_1.Config.getDefault("TERRENO_CFG_STRING")).toBeUndefined();
269
- });
270
- (0, bun_test_1.it)("getRegistration exposes secret + description metadata", function () {
271
- config_1.Config.register("TERRENO_CFG_WITH_META", {
272
- description: "A secret thing",
273
- secret: true,
274
- });
275
- var meta = config_1.Config.getRegistration("TERRENO_CFG_WITH_META");
276
- (0, bun_test_1.expect)(meta === null || meta === void 0 ? void 0 : meta.secret).toBe(true);
277
- (0, bun_test_1.expect)(meta === null || meta === void 0 ? void 0 : meta.description).toBe("A secret thing");
278
- });
279
- (0, bun_test_1.it)("re-registering the same key throws", function () {
280
- (0, bun_test_1.expect)(function () { return config_1.Config.register("TERRENO_CFG_STRING"); }).toThrow(/registered more than once/);
281
- });
282
- (0, bun_test_1.it)("does not treat Object prototype keys as registered", function () {
283
- (0, bun_test_1.expect)(config_1.Config.isRegistered("constructor")).toBe(false);
284
- (0, bun_test_1.expect)(config_1.Config.isRegistered("toString")).toBe(false);
285
- (0, bun_test_1.expect)(config_1.Config.isRegistered("hasOwnProperty")).toBe(false);
286
- // And re-registering one of these names should still succeed.
287
- (0, bun_test_1.expect)(function () { return config_1.Config.register("toString", { default: "x" }); }).not.toThrow();
288
- (0, bun_test_1.expect)(config_1.Config.get("toString")).toBe("x");
289
- });
290
- });
291
- (0, bun_test_1.describe)("clearOverrides", function () {
292
- (0, bun_test_1.it)("removes all overrides", function () {
293
- config_1.Config.setOverride("TERRENO_CFG_STRING", "x");
294
- config_1.Config.setOverride("TERRENO_CFG_DEFAULTED", "y");
295
- config_1.Config.clearOverrides();
296
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_STRING")).toBeUndefined();
297
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_DEFAULTED")).toBe("fallback");
298
- });
299
- });
300
- (0, bun_test_1.describe)("refresh", function () {
301
- (0, bun_test_1.it)("loads values via the registered env loader", function () { return __awaiter(void 0, void 0, void 0, function () {
302
- return __generator(this, function (_a) {
303
- switch (_a.label) {
304
- case 0:
305
- config_1.Config.setEnvLoader(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
306
- return [2 /*return*/, ({ TERRENO_CFG_STRING: "fromLoader" })];
307
- }); }); });
308
- return [4 /*yield*/, config_1.Config.refresh()];
309
- case 1:
310
- _a.sent();
311
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_STRING")).toBe("fromLoader");
312
- return [2 /*return*/];
313
- }
314
- });
315
- }); });
316
- (0, bun_test_1.it)("clears the cache when no loader is registered", function () { return __awaiter(void 0, void 0, void 0, function () {
317
- return __generator(this, function (_a) {
318
- switch (_a.label) {
319
- case 0:
320
- config_1.Config.setCachedEnv({ TERRENO_CFG_STRING: "stale" });
321
- config_1.Config.setEnvLoader(null);
322
- return [4 /*yield*/, config_1.Config.refresh()];
323
- case 1:
324
- _a.sent();
325
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_STRING")).toBeUndefined();
326
- return [2 /*return*/];
327
- }
328
- });
329
- }); });
330
- (0, bun_test_1.it)("updates the cache on each refresh", function () { return __awaiter(void 0, void 0, void 0, function () {
331
- var payload;
332
- return __generator(this, function (_a) {
333
- switch (_a.label) {
334
- case 0:
335
- payload = { TERRENO_CFG_STRING: "first" };
336
- config_1.Config.setEnvLoader(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
337
- return [2 /*return*/, payload];
338
- }); }); });
339
- return [4 /*yield*/, config_1.Config.refresh()];
340
- case 1:
341
- _a.sent();
342
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_STRING")).toBe("first");
343
- payload = { TERRENO_CFG_STRING: "second" };
344
- return [4 /*yield*/, config_1.Config.refresh()];
345
- case 2:
346
- _a.sent();
347
- (0, bun_test_1.expect)(config_1.Config.get("TERRENO_CFG_STRING")).toBe("second");
348
- return [2 /*return*/];
349
- }
350
- });
351
- }); });
352
- });
353
- });
@@ -1 +0,0 @@
1
- export {};