@everyonesoftware/common 2.0.0 → 4.0.0

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 (176) hide show
  1. package/outputs/chunk-AY3YWKOM.js +7741 -0
  2. package/outputs/chunk-AY3YWKOM.js.map +1 -0
  3. package/outputs/sources.cjs +9007 -0
  4. package/outputs/sources.cjs.map +1 -0
  5. package/outputs/sources.d.cts +4082 -0
  6. package/outputs/sources.d.ts +4082 -0
  7. package/outputs/sources.js +1370 -0
  8. package/outputs/sources.js.map +1 -0
  9. package/outputs/tests.cjs +17208 -0
  10. package/outputs/tests.cjs.map +1 -0
  11. package/outputs/tests.d.cts +3 -0
  12. package/outputs/tests.d.ts +3 -0
  13. package/outputs/tests.js +9798 -0
  14. package/outputs/tests.js.map +1 -0
  15. package/package.json +11 -2
  16. package/.c8rc.json +0 -12
  17. package/.github/workflows/publish.yml +0 -36
  18. package/.mocharc.json +0 -9
  19. package/sources/assertMessageParameters.ts +0 -22
  20. package/sources/asyncIterator.ts +0 -437
  21. package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +0 -48
  22. package/sources/asyncResult.ts +0 -95
  23. package/sources/basicDisposable.ts +0 -57
  24. package/sources/byteList.ts +0 -202
  25. package/sources/byteListStream.ts +0 -121
  26. package/sources/byteReadStream.ts +0 -24
  27. package/sources/byteWriteStream.ts +0 -16
  28. package/sources/bytes.ts +0 -25
  29. package/sources/characterList.ts +0 -195
  30. package/sources/characterListStream.ts +0 -151
  31. package/sources/characterReadStream.ts +0 -81
  32. package/sources/characterReadStreamIterator.ts +0 -128
  33. package/sources/characterWriteStream.ts +0 -45
  34. package/sources/commandLineParameter.ts +0 -45
  35. package/sources/commandLineParameters.ts +0 -21
  36. package/sources/comparable.ts +0 -144
  37. package/sources/comparer.ts +0 -133
  38. package/sources/comparison.ts +0 -20
  39. package/sources/concatenateIterable.ts +0 -119
  40. package/sources/concatenateIterator.ts +0 -165
  41. package/sources/condition.ts +0 -329
  42. package/sources/currentProcess.ts +0 -158
  43. package/sources/dateTime.ts +0 -130
  44. package/sources/depthFirstSearch.ts +0 -230
  45. package/sources/disposable.ts +0 -31
  46. package/sources/emptyError.ts +0 -10
  47. package/sources/english.ts +0 -45
  48. package/sources/equalFunctions.ts +0 -123
  49. package/sources/fetchHttpClient.ts +0 -89
  50. package/sources/fetchHttpResponse.ts +0 -106
  51. package/sources/flatMapIterable.ts +0 -104
  52. package/sources/flatMapIterator.ts +0 -152
  53. package/sources/generator.ts +0 -251
  54. package/sources/httpClient.ts +0 -36
  55. package/sources/httpHeader.ts +0 -37
  56. package/sources/httpHeaders.ts +0 -216
  57. package/sources/httpIncomingRequest.ts +0 -30
  58. package/sources/httpIncomingResponse.ts +0 -19
  59. package/sources/httpMethod.ts +0 -164
  60. package/sources/httpOutgoingRequest.ts +0 -119
  61. package/sources/httpOutgoingResponse.ts +0 -113
  62. package/sources/httpServer.ts +0 -34
  63. package/sources/inMemoryCharacterWriteStream.ts +0 -78
  64. package/sources/index.ts +0 -101
  65. package/sources/iterable.ts +0 -345
  66. package/sources/iterator.ts +0 -481
  67. package/sources/iteratorToJavascriptIteratorAdapter.ts +0 -48
  68. package/sources/javascript.ts +0 -59
  69. package/sources/javascriptArrayList.ts +0 -175
  70. package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +0 -124
  71. package/sources/javascriptIteratorToIteratorAdapter.ts +0 -133
  72. package/sources/javascriptMapMap.ts +0 -143
  73. package/sources/javascriptSetSet.ts +0 -134
  74. package/sources/list.ts +0 -330
  75. package/sources/listQueue.ts +0 -62
  76. package/sources/listStack.ts +0 -62
  77. package/sources/luxonDateTime.ts +0 -109
  78. package/sources/map.ts +0 -302
  79. package/sources/mapAsyncIterator.ts +0 -141
  80. package/sources/mapIterable.ts +0 -105
  81. package/sources/mapIterator.ts +0 -145
  82. package/sources/mutableCondition.ts +0 -451
  83. package/sources/mutableHttpHeaders.ts +0 -204
  84. package/sources/mutableMap.ts +0 -292
  85. package/sources/network.ts +0 -18
  86. package/sources/node.ts +0 -37
  87. package/sources/nodeJSCharacterWriteStream.ts +0 -42
  88. package/sources/nodeJSHttpIncomingRequest.ts +0 -132
  89. package/sources/nodeJSHttpServer.ts +0 -134
  90. package/sources/notFoundError.ts +0 -12
  91. package/sources/postCondition.ts +0 -284
  92. package/sources/postConditionError.ts +0 -12
  93. package/sources/preCondition.ts +0 -284
  94. package/sources/preConditionError.ts +0 -12
  95. package/sources/promiseAsyncResult.ts +0 -174
  96. package/sources/property.ts +0 -63
  97. package/sources/queue.ts +0 -49
  98. package/sources/realNetwork.ts +0 -28
  99. package/sources/recreationDotGovClient.ts +0 -259
  100. package/sources/searchControl.ts +0 -42
  101. package/sources/set.ts +0 -244
  102. package/sources/skipAsyncIterator.ts +0 -145
  103. package/sources/skipIterator.ts +0 -155
  104. package/sources/stack.ts +0 -48
  105. package/sources/stringComparer.ts +0 -33
  106. package/sources/stringIterator.ts +0 -149
  107. package/sources/strings.ts +0 -322
  108. package/sources/syncResult.ts +0 -300
  109. package/sources/takeAsyncIterator.ts +0 -141
  110. package/sources/takeIterator.ts +0 -151
  111. package/sources/toStringFunctions.ts +0 -185
  112. package/sources/types.ts +0 -371
  113. package/sources/whereAsyncIterator.ts +0 -143
  114. package/sources/whereIterable.ts +0 -108
  115. package/sources/whereIterator.ts +0 -157
  116. package/sources/wonderlandTrailClient.ts +0 -1503
  117. package/tests/assertTest.ts +0 -113
  118. package/tests/assertTestTests.ts +0 -75
  119. package/tests/basicTestSkip.ts +0 -51
  120. package/tests/byteListStreamTests.ts +0 -390
  121. package/tests/byteListTests.ts +0 -27
  122. package/tests/bytesTests.ts +0 -43
  123. package/tests/characterListStreamTests.ts +0 -391
  124. package/tests/characterListTests.ts +0 -250
  125. package/tests/characterWriteStreamTests.ts +0 -12
  126. package/tests/comparerTests.ts +0 -92
  127. package/tests/conditionTests.ts +0 -877
  128. package/tests/consoleTestRunner.ts +0 -404
  129. package/tests/consoleTestRunnerTests.ts +0 -651
  130. package/tests/dateTimeTests.ts +0 -30
  131. package/tests/depthFirstSearchTests.ts +0 -106
  132. package/tests/disposableTests.ts +0 -121
  133. package/tests/englishTests.ts +0 -103
  134. package/tests/equalFunctionsTests.ts +0 -223
  135. package/tests/failedTest.ts +0 -43
  136. package/tests/fetchHttpClientTests.ts +0 -33
  137. package/tests/generatorTests.ts +0 -86
  138. package/tests/httpClientTests.ts +0 -18
  139. package/tests/inMemoryCharacterWriteStreamTests.ts +0 -117
  140. package/tests/iterableTests.ts +0 -141
  141. package/tests/iteratorTests.ts +0 -1086
  142. package/tests/javascriptMapMapTests.ts +0 -21
  143. package/tests/listTests.ts +0 -338
  144. package/tests/mapIteratorTests.ts +0 -55
  145. package/tests/mapTests.ts +0 -104
  146. package/tests/mutableConditionTests.ts +0 -273
  147. package/tests/mutableMapTests.ts +0 -154
  148. package/tests/nodeJSHttpServerTests.ts +0 -75
  149. package/tests/notFoundErrorTests.ts +0 -24
  150. package/tests/postConditionErrorTests.ts +0 -24
  151. package/tests/preConditionErrorTests.ts +0 -24
  152. package/tests/promiseAsyncResultTests.ts +0 -688
  153. package/tests/propertyTests.ts +0 -63
  154. package/tests/queueTests.ts +0 -29
  155. package/tests/recreationDotGovClientTests.ts +0 -191
  156. package/tests/setTests.ts +0 -140
  157. package/tests/skippedTest.ts +0 -39
  158. package/tests/stackTests.ts +0 -66
  159. package/tests/stringComparerTests.ts +0 -60
  160. package/tests/stringIteratorTests.ts +0 -156
  161. package/tests/stringsTests.ts +0 -516
  162. package/tests/syncResultTests.ts +0 -1251
  163. package/tests/test.ts +0 -228
  164. package/tests/testAction.ts +0 -75
  165. package/tests/testActionTests.ts +0 -93
  166. package/tests/testFailureTests.ts +0 -12
  167. package/tests/testRunner.ts +0 -267
  168. package/tests/testRunnerTests.ts +0 -895
  169. package/tests/testSkip.ts +0 -34
  170. package/tests/tests.ts +0 -103
  171. package/tests/toStringFunctionsTests.ts +0 -55
  172. package/tests/typesTests.ts +0 -257
  173. package/tests/whereIteratorTests.ts +0 -77
  174. package/tests/wonderlandTrailClientTests.ts +0 -452
  175. package/tsconfig.json +0 -20
  176. package/tsup.config.ts +0 -13
@@ -1,174 +0,0 @@
1
- import { PreCondition } from "./preCondition";
2
- import { AsyncResult } from "./asyncResult";
3
- import { instanceOfType, isPromise, isUndefinedOrNull, Type } from "./types";
4
-
5
- export class PromiseAsyncResult<T> implements AsyncResult<T>
6
- {
7
- private readonly promise: Promise<T>;
8
-
9
- private constructor(promise: Promise<T>)
10
- {
11
- PreCondition.assertNotUndefinedAndNotNull(promise, "promise");
12
-
13
- this.promise = promise;
14
- }
15
-
16
- public static create<T>(action: () => (T | Promise<T>)): PromiseAsyncResult<T>;
17
- public static create<T>(promise: Promise<T>): PromiseAsyncResult<T>;
18
- static create<T>(actionOrPromise: (() => (T | Promise<T>)) | Promise<T>): PromiseAsyncResult<T>
19
- {
20
- PreCondition.assertNotUndefinedAndNotNull(actionOrPromise, "action or promise");
21
-
22
- return new PromiseAsyncResult(Promise.resolve(isPromise<T>(actionOrPromise) ? actionOrPromise : actionOrPromise()));
23
- }
24
-
25
- public static value<T>(value: T): PromiseAsyncResult<T>
26
- {
27
- return PromiseAsyncResult.create(Promise.resolve(value));
28
- }
29
-
30
- public static error<T>(error: unknown): PromiseAsyncResult<T>
31
- {
32
- return PromiseAsyncResult.create(Promise.reject(error));
33
- }
34
-
35
- public static yield(): PromiseAsyncResult<void>
36
- {
37
- return PromiseAsyncResult.create(Promise.resolve());
38
- }
39
-
40
- public then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseAsyncResult<TResult1 | TResult2>
41
- {
42
- return PromiseAsyncResult.create(this.promise.then(onfulfilled, onrejected));
43
- }
44
-
45
- public onValue(onValueFunction: (value: T) => (void | Promise<void>)): PromiseAsyncResult<T>
46
- {
47
- return this.then<T>(async (value: T) =>
48
- {
49
- let result: PromiseAsyncResult<T>;
50
- try
51
- {
52
- await onValueFunction(value);
53
- result = this;
54
- }
55
- catch (error)
56
- {
57
- result = PromiseAsyncResult.error(error);
58
- }
59
- return result;
60
- })
61
- }
62
-
63
- public catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): PromiseAsyncResult<T | TResult>
64
- public catch<TError,TResult = never>(errorType: Type<TError>, onrejected: (reason: TError) => (TResult | PromiseLike<TResult>)): PromiseAsyncResult<T | TResult>
65
- catch<TResult = never>(errorTypeOrOnRejected?: Type<Error> | ((reason: unknown) => TResult | PromiseLike<TResult>) | null, onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): PromiseAsyncResult<T | TResult>
66
- {
67
- let errorType: Type<Error> | undefined;
68
- if (!isUndefinedOrNull(onrejected))
69
- {
70
- errorType = errorTypeOrOnRejected as Type<unknown>;
71
-
72
- PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
73
- }
74
- else
75
- {
76
- onrejected = errorTypeOrOnRejected as ((reason: any) => TResult | PromiseLike<TResult>) | null;
77
- }
78
-
79
- return PromiseAsyncResult.create<T | TResult>(this.promise.catch((reason: unknown) =>
80
- {
81
- let value: TResult | PromiseLike<TResult> | undefined;
82
- if (errorType && !instanceOfType(reason, errorType))
83
- {
84
- throw reason;
85
- }
86
- else if (!isUndefinedOrNull(onrejected))
87
- {
88
- value = onrejected(reason);
89
- }
90
- return value!;
91
- }));
92
- }
93
-
94
- public onError(onErrorFunction: (reason: unknown) => (void | PromiseLike<void>)): PromiseAsyncResult<T>;
95
- public onError<TError>(errorType: Type<TError>, onErrorFunction: (reason: TError) => (void | PromiseLike<void>)): PromiseAsyncResult<T>;
96
- onError(errorTypeOrOnErrorFunction: Type<unknown> | ((reason: unknown) => (void | PromiseLike<void>)), onErrorFunction?: (reason: unknown) => (void | PromiseLike<void>)): PromiseAsyncResult<T>
97
- {
98
- let errorType: Type<unknown> | undefined;
99
- if (!isUndefinedOrNull(onErrorFunction))
100
- {
101
- errorType = errorTypeOrOnErrorFunction as Type<unknown>;
102
-
103
- PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
104
- }
105
- else
106
- {
107
- onErrorFunction = errorTypeOrOnErrorFunction as ((reason: unknown) => void | PromiseLike<void>);
108
- }
109
- PreCondition.assertNotUndefinedAndNotNull(onErrorFunction, "onErrorFunction");
110
-
111
- let result: PromiseAsyncResult<T>;
112
- if (errorType)
113
- {
114
- result = this.catch(errorType, async (reason: unknown) =>
115
- {
116
- await onErrorFunction(reason);
117
- throw reason;
118
- });
119
- }
120
- else
121
- {
122
- result = this.catch(async (reason: unknown) =>
123
- {
124
- await onErrorFunction(reason);
125
- throw reason;
126
- });
127
- }
128
-
129
- return result;
130
- }
131
-
132
- public convertError(convertErrorFunction: (reason: unknown) => (unknown | PromiseLike<unknown>)): PromiseAsyncResult<T>;
133
- public convertError<TError>(errorType: Type<TError>, convertErrorFunction: (reason: TError) => (unknown | PromiseLike<unknown>)): PromiseAsyncResult<T>;
134
- convertError(errorTypeOrConvertErrorFunction: Type<unknown> | ((reason: unknown) => (unknown | PromiseLike<unknown>)), convertErrorFunction?: (reason: unknown) => (unknown | PromiseLike<unknown>)): PromiseAsyncResult<T>
135
- {
136
- let errorType: Type<unknown> | undefined;
137
- if (!isUndefinedOrNull(convertErrorFunction))
138
- {
139
- errorType = errorTypeOrConvertErrorFunction as Type<unknown>;
140
-
141
- PreCondition.assertNotUndefinedAndNotNull(errorType, "errorType");
142
- }
143
- else
144
- {
145
- convertErrorFunction = errorTypeOrConvertErrorFunction as ((reason: unknown) => void | PromiseLike<void>);
146
- }
147
- PreCondition.assertNotUndefinedAndNotNull(convertErrorFunction, "convertErrorFunction");
148
-
149
- let result: PromiseAsyncResult<T>;
150
- if (errorType)
151
- {
152
- result = this.catch(errorType, async (reason: unknown) =>
153
- {
154
- throw await convertErrorFunction(reason);
155
- });
156
- }
157
- else
158
- {
159
- result = this.catch(async (reason: unknown) =>
160
- {
161
- throw await convertErrorFunction(reason);
162
- });
163
- }
164
-
165
- return result;
166
- }
167
-
168
- public finally(onfinally?: (() => (void | Promise<void>)) | null): PromiseAsyncResult<T>
169
- {
170
- return PromiseAsyncResult.create(this.promise.finally(onfinally));
171
- }
172
-
173
- readonly [Symbol.toStringTag]: string = "AsyncResult";
174
- }
@@ -1,63 +0,0 @@
1
- import { PreCondition } from "./preCondition";
2
- import { hasProperty, isFunction, isObject } from "./types";
3
-
4
- export class Property<T>
5
- {
6
- private readonly getter: () => T;
7
- private readonly setter: (value: T) => void;
8
-
9
- private constructor(getter: () => T, setter: (value: T) => void)
10
- {
11
- PreCondition.assertNotUndefinedAndNotNull(getter, "getter");
12
- PreCondition.assertNotUndefinedAndNotNull(setter, "setter");
13
-
14
- this.getter = getter;
15
- this.setter = setter;
16
- }
17
-
18
- public static create<T>(getter: () => T, setter: (value: T) => void): Property<T>;
19
- public static create<T>(options: { getter: () => T, setter: (value: T) => void }): Property<T>;
20
- public static create<T>(initialValue: T): Property<T>;
21
- static create<T>(getterOptionsOrInitialValue: (() => T) | { getter: () => T, setter: (value: T) => void } | T, setter?: (value: T) => void): Property<T>
22
- {
23
- let getter: () => T;
24
- if (isFunction(getterOptionsOrInitialValue))
25
- {
26
- getter = getterOptionsOrInitialValue;
27
- }
28
- else if (isObject(getterOptionsOrInitialValue) &&
29
- hasProperty(getterOptionsOrInitialValue, "getter") &&
30
- hasProperty(getterOptionsOrInitialValue, "setter"))
31
- {
32
- const options: { getter: () => T, setter: (value: T) => void } = getterOptionsOrInitialValue;
33
- getter = options.getter;
34
- setter = options.setter;
35
- }
36
- else
37
- {
38
- let initialValue: T = getterOptionsOrInitialValue;
39
- getter = () => { return initialValue; };
40
- setter = (value: T) => { initialValue = value; };
41
- }
42
- PreCondition.assertNotUndefinedAndNotNull(getter, "getter");
43
- PreCondition.assertNotUndefinedAndNotNull(setter, "setter");
44
-
45
- return new Property<T>(getter, setter);
46
- }
47
-
48
- public getValue(): T
49
- {
50
- return this.getter();
51
- }
52
-
53
- public setValue(value: T): this
54
- {
55
- this.setter(value);
56
- return this;
57
- }
58
-
59
- public toString(): string
60
- {
61
- return `${this.getValue()}`;
62
- }
63
- }
package/sources/queue.ts DELETED
@@ -1,49 +0,0 @@
1
- import { EqualFunctions } from "./equalFunctions";
2
- import { JavascriptIterable } from "./javascript";
3
- import { ListQueue } from "./listQueue";
4
- import { ListStack } from "./listStack";
5
- import { AsyncResult } from "./asyncResult";
6
-
7
- /**
8
- * A data structure that stores values in a first-in-first-out order.
9
- */
10
- export abstract class Queue<T>
11
- {
12
- /**
13
- * Create an instance of the default {@link Queue} implementation.
14
- * @returns A new {@link Queue} object.
15
- */
16
- public static create<T>(): ListQueue<T>
17
- {
18
- return ListQueue.create();
19
- }
20
-
21
- /**
22
- * Get whether there are any values in this {@link Stack}.
23
- */
24
- public abstract any(): AsyncResult<boolean>;
25
-
26
- /**
27
- * Add the provided value onto the end of this {@link Queue}.
28
- * @param value The value to add to the end of this {@link Queue}.
29
- */
30
- public abstract add(value: T): AsyncResult<void>;
31
-
32
- /**
33
- * Add the provided values to the end of this {@link Queue}.
34
- * @param values The values to add to the end of this {@link Queue}.
35
- */
36
- public abstract addAll(values: JavascriptIterable<T>): AsyncResult<void>;
37
-
38
- /**
39
- * Remove the next value off of this {@link Queue}.
40
- */
41
- public abstract remove(): AsyncResult<T>;
42
-
43
- /**
44
- * Get whether this {@link Stack} contains the provided value.
45
- * @param value The value to look for.
46
- * @param equalFunctions The functions to use to compare values.
47
- */
48
- public abstract contains(value: T, equalFunctions?: EqualFunctions): AsyncResult<boolean>;
49
- }
@@ -1,28 +0,0 @@
1
- import { FetchHttpClient } from "./fetchHttpClient";
2
- import { HttpClient } from "./httpClient";
3
- import { HttpServer } from "./httpServer";
4
- import { Network } from "./network";
5
- import { NodeJSHttpServer } from "./nodeJSHttpServer";
6
-
7
- export class RealNetwork extends Network
8
- {
9
- private constructor()
10
- {
11
- super();
12
- }
13
-
14
- public static create(): RealNetwork
15
- {
16
- return new RealNetwork();
17
- }
18
-
19
- public createHttpServer(): HttpServer
20
- {
21
- return NodeJSHttpServer.create();
22
- }
23
-
24
- public createHttpClient(): HttpClient
25
- {
26
- return FetchHttpClient.create();
27
- }
28
- }
@@ -1,259 +0,0 @@
1
- import { PromiseAsyncResult } from "./promiseAsyncResult";
2
- import { DateTime } from "./dateTime";
3
- import { HttpClient } from "./httpClient";
4
- import { HttpIncomingResponse } from "./httpIncomingResponse";
5
- import { HttpOutgoingRequest } from "./httpOutgoingRequest";
6
- import { Iterable } from "./iterable";
7
- import { List } from "./list";
8
- import { PreCondition } from "./preCondition";
9
- import { AsyncResult } from "./asyncResult";
10
-
11
- export interface RecreationDotGovDivisionDayAvailability
12
- {
13
- readonly date: DateTime;
14
-
15
- readonly walkup: boolean;
16
-
17
- readonly reservationsRemaining: number;
18
-
19
- readonly totalSpots: number;
20
- }
21
-
22
- export interface RecreationDotGovDivisionAvailabilityJson
23
- {
24
- readonly bools: { [date: string]: boolean };
25
-
26
- readonly rules: {
27
- readonly name: string;
28
- readonly value: number;
29
- }[];
30
-
31
- readonly quota_type_maps: {
32
- readonly ConstantQuotaUsageDaily?: {
33
- [date: string]: {
34
- readonly is_hidden: boolean;
35
- readonly remaining: number;
36
- readonly season_type: string;
37
- readonly show_walkup: boolean;
38
- readonly total: number;
39
- };
40
- };
41
- readonly QuotaUsageByMemberDaily?: {
42
- [date: string]: {
43
- readonly is_hidden: boolean;
44
- readonly remaining: number;
45
- readonly season_type: string;
46
- readonly show_walkup: boolean;
47
- readonly total: number;
48
- };
49
- };
50
- };
51
- }
52
-
53
- export class RecreationDotGovDivisionAvailability
54
- {
55
- public readonly json: RecreationDotGovDivisionAvailabilityJson;
56
-
57
- public readonly minimumGroupSize?: number;
58
- public readonly maximumGroupSize?: number;
59
- public readonly dayAvailabilities: Iterable<RecreationDotGovDivisionDayAvailability>;
60
-
61
- private constructor(json: RecreationDotGovDivisionAvailabilityJson)
62
- {
63
- PreCondition.assertNotUndefinedAndNotNull(json, "json");
64
-
65
- this.json = json;
66
-
67
- const minGroupSize: string = "MinGroupSize".toLowerCase();
68
- const maxGroupSize: string = "MaxGroupSize".toLowerCase();
69
- for (const rule of json.rules)
70
- {
71
- switch (rule.name.toLowerCase())
72
- {
73
- case minGroupSize:
74
- this.minimumGroupSize = rule.value;
75
- break;
76
-
77
- case maxGroupSize:
78
- this.maximumGroupSize = rule.value;
79
- break;
80
- }
81
- }
82
-
83
- const dayAvailabilities = List.create<RecreationDotGovDivisionDayAvailability>();
84
- const quotaUsageByMemberDaily = json.quota_type_maps?.QuotaUsageByMemberDaily;
85
- if (quotaUsageByMemberDaily)
86
- {
87
- for (const quotaUsage of Object.entries(quotaUsageByMemberDaily))
88
- {
89
- const dateString: string = quotaUsage[0];
90
-
91
- const usageData = quotaUsage[1];
92
-
93
- let walkup: boolean = false;
94
- let reservationsRemaining: number = 0;
95
- const boolsEntry: boolean = json.bools[dateString];
96
- if (boolsEntry)
97
- {
98
- walkup = usageData.show_walkup;
99
- reservationsRemaining = usageData.remaining;
100
- }
101
-
102
- dayAvailabilities.add({
103
- date: DateTime.parse(dateString),
104
- totalSpots: usageData.total,
105
- walkup,
106
- reservationsRemaining,
107
- });
108
- }
109
- }
110
- this.dayAvailabilities = dayAvailabilities;
111
- }
112
-
113
- public static create(json: RecreationDotGovDivisionAvailabilityJson): RecreationDotGovDivisionAvailability
114
- {
115
- return new RecreationDotGovDivisionAvailability(json);
116
- }
117
- }
118
-
119
- interface RecreationDotGovPayloadResponse<T>
120
- {
121
- readonly payload: T;
122
- }
123
-
124
- export interface RecreationDotGovDivisionJson
125
- {
126
- readonly id: string;
127
-
128
- readonly name: string;
129
-
130
- readonly type: string;
131
-
132
- readonly district: string;
133
- }
134
-
135
- export interface RecreationDotGovPermitItineraryJson
136
- {
137
- readonly id: string;
138
-
139
- readonly name: string;
140
-
141
- readonly divisions: { [divisionId: number]: RecreationDotGovDivisionJson };
142
- }
143
-
144
- export class RecreationDotGovError extends Error
145
- {
146
- public constructor(message: string)
147
- {
148
- super(message);
149
- }
150
- }
151
-
152
- export interface RecreationDotGovErrorResponse
153
- {
154
- readonly error: string;
155
- }
156
-
157
- export class RecreationDotGovClient implements HttpClient
158
- {
159
- private readonly httpClient: HttpClient;
160
-
161
- private constructor(httpClient: HttpClient)
162
- {
163
- PreCondition.assertNotUndefinedAndNotNull(httpClient, "httpClient");
164
-
165
- this.httpClient = httpClient;
166
- }
167
-
168
- public static create(httpClient: HttpClient): RecreationDotGovClient
169
- {
170
- return new RecreationDotGovClient(httpClient);
171
- }
172
-
173
- public sendRequest(request: HttpOutgoingRequest): AsyncResult<HttpIncomingResponse>
174
- {
175
- return this.httpClient.sendRequest(request);
176
- }
177
-
178
- public sendGetRequest(url: string): AsyncResult<HttpIncomingResponse>
179
- {
180
- return HttpClient.sendGetRequest(this, url);
181
- }
182
-
183
- public getPermitItinerary(permitItineraryId: string): PromiseAsyncResult<RecreationDotGovPermitItineraryJson>
184
- {
185
- PreCondition.assertNotEmpty(permitItineraryId, "permitItineraryId");
186
-
187
- return PromiseAsyncResult.create(async () =>
188
- {
189
- const response: HttpIncomingResponse = await this.sendGetRequest(`https://www.recreation.gov/api/permitcontent/${permitItineraryId}`);
190
-
191
- const responseBody: string = await response.getBody();
192
-
193
- const statusCode: number = response.getStatusCode();
194
- if (statusCode < 200 || 300 <= statusCode)
195
- {
196
- const responseBodyJson: RecreationDotGovErrorResponse = JSON.parse(responseBody);
197
- const errorMessage: string = responseBodyJson.error;
198
- switch (errorMessage.toLowerCase())
199
- {
200
- case "permit not found":
201
- throw new RecreationDotGovError(`No permit itinerary found for id: ${JSON.stringify(permitItineraryId)}`);
202
-
203
- default:
204
- throw new RecreationDotGovError(`Unrecognized error: ${JSON.stringify(errorMessage)}`);
205
- }
206
- }
207
-
208
- const responseBodyJson: RecreationDotGovPayloadResponse<RecreationDotGovPermitItineraryJson> = JSON.parse(responseBody);
209
- return responseBodyJson.payload;
210
- });
211
- }
212
-
213
- public getDivisionAvailability(permitItineraryId: string, divisionId: string, month: number, year: number, earlyAccessPermitLotteryId?: string): PromiseAsyncResult<RecreationDotGovDivisionAvailability>
214
- {
215
- PreCondition.assertNotEmpty(permitItineraryId, "permitItineraryId");
216
- PreCondition.assertNotEmpty(divisionId, "divisionId");
217
- PreCondition.assertBetween(1, month, 12, "month");
218
-
219
- return PromiseAsyncResult.create(async () =>
220
- {
221
- const url: string = earlyAccessPermitLotteryId
222
- ? `https://www.recreation.gov/api/permititinerary/${permitItineraryId}/division/${divisionId}/eapavailability/month/${earlyAccessPermitLotteryId}?month=${month}&year=${year}`
223
- : `https://www.recreation.gov/api/permititinerary/${permitItineraryId}/division/${divisionId}/availability/month?month=${month}&year=${year}`
224
- const response: HttpIncomingResponse = await this.sendGetRequest(url);
225
-
226
- let responseBody: string = await response.getBody();
227
-
228
- const statusCode: number = response.getStatusCode();
229
- if (statusCode < 200 || 300 <= statusCode)
230
- {
231
- const responseBodyJson: RecreationDotGovErrorResponse = JSON.parse(responseBody) as RecreationDotGovErrorResponse;
232
- const errorMessage: string = responseBodyJson.error;
233
- switch (errorMessage.toLowerCase())
234
- {
235
- case "invalid permit id":
236
- throw new RecreationDotGovError(`No permit itinerary found for id: ${JSON.stringify(permitItineraryId)}`);
237
-
238
- case "request year is missing or invalid":
239
- // Ignore this error and just return an empty availability.
240
- const emptyResponseBody: RecreationDotGovPayloadResponse<RecreationDotGovDivisionAvailabilityJson> = {
241
- payload: {
242
- bools: {},
243
- rules: [],
244
- quota_type_maps: {},
245
- },
246
- };
247
- responseBody = JSON.stringify(emptyResponseBody);
248
- break;
249
-
250
- default:
251
- throw new RecreationDotGovError(`Unrecognized error: ${JSON.stringify(errorMessage)}`);
252
- }
253
- }
254
-
255
- const responseBodyJson: RecreationDotGovPayloadResponse<RecreationDotGovDivisionAvailabilityJson> = JSON.parse(responseBody);
256
- return RecreationDotGovDivisionAvailability.create(responseBodyJson.payload);
257
- });
258
- }
259
- }
@@ -1,42 +0,0 @@
1
- import { JavascriptIterable } from "./javascript";
2
-
3
- /**
4
- * An object that can be used to implement a search algorithm.
5
- */
6
- export abstract class SearchControl<TVisit,TResult>
7
- {
8
- /**
9
- * Add the provided value to the to-visit list.
10
- * @param value The value to add to the to-visit list.
11
- */
12
- public abstract addToVisit(value: TVisit): void;
13
-
14
- /**
15
- * Add the provided values to the to-visit list.
16
- * @param values The values to add to the to-visit list.
17
- */
18
- public abstract addAllToVisit(values: JavascriptIterable<TVisit>): void;
19
-
20
- /**
21
- * Get whether the provided value has already been visited.
22
- * @param value The value to check.
23
- */
24
- public abstract hasVisited(value: TVisit): boolean;
25
-
26
- /**
27
- * Add the provided value to the list of values to be returned.
28
- * @param value The value to add.
29
- */
30
- public abstract addResult(value: TResult): void;
31
-
32
- /**
33
- * Add the provided values to the list of values to be returned.
34
- * @param values The values to add.
35
- */
36
- public abstract addResults(values: JavascriptIterable<TResult>): void;
37
-
38
- /**
39
- * Immediately stop the search.
40
- */
41
- public abstract break(): never;
42
- }