@occultist/occultist 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +144 -0
  3. package/dist/accept.d.ts +41 -0
  4. package/dist/accept.js +110 -0
  5. package/dist/accept.test.d.ts +1 -0
  6. package/dist/accept.test.js +44 -0
  7. package/dist/action.test.d.ts +1 -0
  8. package/dist/action.test.js +1 -0
  9. package/dist/actions/actionSets.d.ts +23 -0
  10. package/dist/actions/actionSets.js +49 -0
  11. package/dist/actions/actions.d.ts +163 -0
  12. package/dist/actions/actions.js +436 -0
  13. package/dist/actions/context.d.ts +78 -0
  14. package/dist/actions/context.js +112 -0
  15. package/dist/actions/meta.d.ts +49 -0
  16. package/dist/actions/meta.js +177 -0
  17. package/dist/actions/path.d.ts +21 -0
  18. package/dist/actions/path.js +83 -0
  19. package/dist/actions/path.test.d.ts +1 -0
  20. package/dist/actions/path.test.js +9 -0
  21. package/dist/actions/spec.d.ts +214 -0
  22. package/dist/actions/spec.js +1 -0
  23. package/dist/actions/types.d.ts +112 -0
  24. package/dist/actions/types.js +2 -0
  25. package/dist/actions/writer.d.ts +27 -0
  26. package/dist/actions/writer.js +140 -0
  27. package/dist/actions/writer.test.d.ts +1 -0
  28. package/dist/actions/writer.test.js +42 -0
  29. package/dist/auth/types.d.ts +14 -0
  30. package/dist/auth/types.js +1 -0
  31. package/dist/cache/cache.d.ts +30 -0
  32. package/dist/cache/cache.js +220 -0
  33. package/dist/cache/etag.d.ts +17 -0
  34. package/dist/cache/etag.js +83 -0
  35. package/dist/cache/etag.test.d.ts +1 -0
  36. package/dist/cache/etag.test.js +91 -0
  37. package/dist/cache/memory.d.ts +12 -0
  38. package/dist/cache/memory.js +36 -0
  39. package/dist/cache/types.d.ts +175 -0
  40. package/dist/cache/types.js +4 -0
  41. package/dist/errors.d.ts +11 -0
  42. package/dist/errors.js +54 -0
  43. package/dist/jsonld.d.ts +43 -0
  44. package/dist/jsonld.js +1 -0
  45. package/dist/makeTypeDefs.d.ts +27 -0
  46. package/dist/makeTypeDefs.js +70 -0
  47. package/dist/merge.d.ts +61 -0
  48. package/dist/merge.js +1 -0
  49. package/dist/mod.d.ts +14 -0
  50. package/dist/mod.js +14 -0
  51. package/dist/processAction.d.ts +15 -0
  52. package/dist/processAction.js +512 -0
  53. package/dist/registry.d.ts +88 -0
  54. package/dist/registry.js +314 -0
  55. package/dist/registry.test.d.ts +1 -0
  56. package/dist/registry.test.js +133 -0
  57. package/dist/request.d.ts +29 -0
  58. package/dist/request.js +118 -0
  59. package/dist/scopes.d.ts +35 -0
  60. package/dist/scopes.js +121 -0
  61. package/dist/scopes.test.d.ts +1 -0
  62. package/dist/scopes.test.js +55 -0
  63. package/dist/transformers/fileTransformer.d.ts +1 -0
  64. package/dist/transformers/fileTransformer.js +8 -0
  65. package/dist/types.d.ts +12 -0
  66. package/dist/types.js +1 -0
  67. package/dist/utils/alwaysArray.d.ts +1 -0
  68. package/dist/utils/alwaysArray.js +9 -0
  69. package/dist/utils/contextBuilder.d.ts +9 -0
  70. package/dist/utils/contextBuilder.js +82 -0
  71. package/dist/utils/getActionContext.d.ts +7 -0
  72. package/dist/utils/getActionContext.js +48 -0
  73. package/dist/utils/getInternalName.d.ts +6 -0
  74. package/dist/utils/getInternalName.js +7 -0
  75. package/dist/utils/getParamLocation.d.ts +2 -0
  76. package/dist/utils/getParamLocation.js +6 -0
  77. package/dist/utils/getPropertyValueSpecifications.d.ts +2 -0
  78. package/dist/utils/getPropertyValueSpecifications.js +49 -0
  79. package/dist/utils/getRequestBodyValues.d.ts +11 -0
  80. package/dist/utils/getRequestBodyValues.js +122 -0
  81. package/dist/utils/getRequestIRIValues.d.ts +14 -0
  82. package/dist/utils/getRequestIRIValues.js +133 -0
  83. package/dist/utils/isBodyInit.d.ts +1 -0
  84. package/dist/utils/isBodyInit.js +21 -0
  85. package/dist/utils/isNil.d.ts +1 -0
  86. package/dist/utils/isNil.js +4 -0
  87. package/dist/utils/isObject.d.ts +6 -0
  88. package/dist/utils/isObject.js +6 -0
  89. package/dist/utils/isPopulatedObject.d.ts +5 -0
  90. package/dist/utils/isPopulatedObject.js +8 -0
  91. package/dist/utils/isPopulatedString.d.ts +1 -0
  92. package/dist/utils/isPopulatedString.js +4 -0
  93. package/dist/utils/joinPaths.d.ts +1 -0
  94. package/dist/utils/joinPaths.js +31 -0
  95. package/dist/utils/makeAppendProblemDetails.d.ts +14 -0
  96. package/dist/utils/makeAppendProblemDetails.js +26 -0
  97. package/dist/utils/makeURLPattern.d.ts +5 -0
  98. package/dist/utils/makeURLPattern.js +12 -0
  99. package/dist/utils/normalizeURL.d.ts +4 -0
  100. package/dist/utils/normalizeURL.js +11 -0
  101. package/dist/utils/parseSearchParams.d.ts +3 -0
  102. package/dist/utils/parseSearchParams.js +24 -0
  103. package/dist/utils/preferredMediaTypes.d.ts +42 -0
  104. package/dist/utils/preferredMediaTypes.js +149 -0
  105. package/dist/utils/urlToIRI.d.ts +1 -0
  106. package/dist/utils/urlToIRI.js +8 -0
  107. package/dist/utils/validateSpecValue.d.ts +1 -0
  108. package/dist/utils/validateSpecValue.js +1 -0
  109. package/dist/validators.d.ts +16 -0
  110. package/dist/validators.js +134 -0
  111. package/lib/accept.test.ts +55 -0
  112. package/lib/accept.ts +147 -0
  113. package/lib/action.test.ts +2 -0
  114. package/lib/actions/actionSets.ts +88 -0
  115. package/lib/actions/actions.ts +795 -0
  116. package/lib/actions/context.ts +170 -0
  117. package/lib/actions/meta.ts +251 -0
  118. package/lib/actions/path.test.ts +15 -0
  119. package/lib/actions/path.ts +99 -0
  120. package/lib/actions/spec.ts +545 -0
  121. package/lib/actions/types.ts +146 -0
  122. package/lib/actions/writer.test.ts +57 -0
  123. package/lib/actions/writer.ts +176 -0
  124. package/lib/auth/types.ts +22 -0
  125. package/lib/cache/cache.ts +291 -0
  126. package/lib/cache/etag.test.ts +122 -0
  127. package/lib/cache/etag.ts +106 -0
  128. package/lib/cache/memory.ts +52 -0
  129. package/lib/cache/types.ts +240 -0
  130. package/lib/errors.ts +66 -0
  131. package/lib/jsonld.ts +67 -0
  132. package/lib/makeTypeDefs.ts +138 -0
  133. package/lib/merge.ts +86 -0
  134. package/lib/mod.ts +14 -0
  135. package/lib/processAction.ts +690 -0
  136. package/lib/registry.test.ts +174 -0
  137. package/lib/registry.ts +455 -0
  138. package/lib/request.ts +153 -0
  139. package/lib/scopes.test.ts +70 -0
  140. package/lib/scopes.ts +178 -0
  141. package/lib/transformers/fileTransformer.ts +10 -0
  142. package/lib/types.ts +13 -0
  143. package/lib/utils/alwaysArray.ts +10 -0
  144. package/lib/utils/contextBuilder.ts +111 -0
  145. package/lib/utils/getActionContext.ts +76 -0
  146. package/lib/utils/getInternalName.ts +15 -0
  147. package/lib/utils/getParamLocation.ts +14 -0
  148. package/lib/utils/getPropertyValueSpecifications.ts +76 -0
  149. package/lib/utils/getRequestBodyValues.ts +155 -0
  150. package/lib/utils/getRequestIRIValues.ts +201 -0
  151. package/lib/utils/isBodyInit.ts +22 -0
  152. package/lib/utils/isNil.ts +4 -0
  153. package/lib/utils/isObject.ts +8 -0
  154. package/lib/utils/isPopulatedObject.ts +9 -0
  155. package/lib/utils/isPopulatedString.ts +4 -0
  156. package/lib/utils/joinPaths.ts +36 -0
  157. package/lib/utils/makeAppendProblemDetails.ts +57 -0
  158. package/lib/utils/makeURLPattern.ts +18 -0
  159. package/lib/utils/normalizeURL.ts +15 -0
  160. package/lib/utils/parseSearchParams.ts +36 -0
  161. package/lib/utils/preferredMediaTypes.ts +220 -0
  162. package/lib/utils/urlToIRI.ts +11 -0
  163. package/lib/utils/validateSpecValue.ts +0 -0
  164. package/lib/validators.ts +186 -0
  165. package/package.json +41 -0
@@ -0,0 +1,545 @@
1
+ import type { JSONPrimitive, JSONValue, OrArray, RecursiveDigit, RecursiveIncrement, TypeDef } from "../jsonld.js";
2
+ import {Action} from "./actions.js";
3
+ import type { Context } from './context.js';
4
+
5
+ export type EmptyState = Record<string, unknown>;
6
+ export type EmptySpec = Map<PropertyKey, never>;
7
+ export type ContextState = Record<string, unknown>;
8
+
9
+ export type EntryPoint = {
10
+ contentType?: string;
11
+ encodingType?: string;
12
+ httpMethod?: string;
13
+ urlTemplate: string;
14
+ actionPlatform?: string;
15
+ };
16
+
17
+ export type Target = string | EntryPoint;
18
+
19
+ export type Merge<M1 extends ContextState, M2 extends ContextState> = {
20
+ [K in keyof M1 as K extends keyof M2 ? never : K]: M1[K];
21
+ } & {
22
+ [K in keyof M2]: M2[K];
23
+ };
24
+
25
+ export type ExtensionMap = Record<string, string>;
26
+
27
+ export type FileValue = File | string;
28
+
29
+ export type ParsedIRIValues = Record<string, JSONPrimitive | JSONPrimitive[]>;
30
+
31
+ export type HandlerMetadata = Record<string | symbol, unknown>;
32
+
33
+ export type HandleArgs<
34
+ State extends ContextState = ContextState,
35
+ > = {
36
+ contentType: string | string[];
37
+ metadata?: HandlerMetadata;
38
+ handler: Middleware<State>
39
+ };
40
+
41
+ export type ParameterizedHandleArgs<
42
+ State extends ContextState = ContextState,
43
+ Spec extends ActionSpec<State> = ActionSpec<State>,
44
+ > = {
45
+ contentType: string | string[];
46
+ metadata?: HandlerMetadata;
47
+ handler: ParameterizedMiddleware<State, Spec>
48
+ };
49
+
50
+ export type AnyHandleArgs<
51
+ State extends ContextState = ContextState,
52
+ Spec extends ActionSpec = ActionSpec,
53
+ > =
54
+ | HandleArgs<State>
55
+ | ParameterizedHandleArgs<State, Spec>
56
+ ;
57
+
58
+ export type ParameterizedContext<
59
+ State extends ContextState = ContextState,
60
+ Spec extends ActionSpec<State> = ActionSpec<State>,
61
+ > = Context<State> & {
62
+ params: ParsedIRIValues;
63
+ query: ParsedIRIValues;
64
+ payload: ActionPayload<Spec>;
65
+ action: Action<State>;
66
+ };
67
+
68
+ export type AnyContext<
69
+ State extends ContextState = ContextState,
70
+ Spec extends ActionSpec<State> = ActionSpec<State>,
71
+ > =
72
+ | Context<State>
73
+ | ParameterizedContext<State, Spec>
74
+ ;
75
+
76
+ export type NextFn = () => Promise<void>;
77
+
78
+ export type Middleware<
79
+ State extends ContextState = ContextState,
80
+ > = (ctx: Context<State>, next: NextFn) => void | Promise<void>;
81
+
82
+ export type ParameterizedMiddleware<
83
+ State extends ContextState = ContextState,
84
+ Spec extends ActionSpec<State> = ActionSpec<State>,
85
+ > = (
86
+ ctx: ParameterizedContext<
87
+ State,
88
+ Spec
89
+ >,
90
+ next: NextFn,
91
+ ) => void | Promise<void>;
92
+
93
+ export type AnyMiddleware<
94
+ State extends ContextState = ContextState,
95
+ Spec extends ActionSpec<State> = ActionSpec<State>,
96
+ > =
97
+ | Middleware<State>
98
+ | ParameterizedMiddleware<State, Spec>
99
+ ;
100
+
101
+ export type ValueOption<Value extends JSONValue> = Value;
102
+
103
+ export type TextValueOption<Value extends JSONValue> = {
104
+ text: string;
105
+ value: Value;
106
+ };
107
+
108
+ export type ActionOption<Value extends JSONValue> =
109
+ | ValueOption<Value>
110
+ | TextValueOption<Value>;
111
+
112
+ export type ActionOptionsRetriever<Value extends JSONValue> =
113
+ | (() => OrArray<ActionOption<Value>>)
114
+ | (() => Promise<OrArray<ActionOption<Value>>>);
115
+
116
+ export type ActionOptions<Value extends JSONValue> =
117
+ | OrArray<ActionOption<Value>>
118
+ | ActionOptionsRetriever<Value>;
119
+
120
+ export type ValidatorFn<
121
+ DataType extends JSONValue | FileValue,
122
+ Value extends DataType,
123
+ > = (
124
+ value: DataType,
125
+ ) => value is Value;
126
+
127
+ export type TransformerFn<
128
+ Value extends JSONValue | FileValue | FileValue[],
129
+ // deno-lint-ignore no-explicit-any
130
+ TransformTo extends any,
131
+ State extends ContextState = ContextState,
132
+ > = (value: Value, state: State) => TransformTo | Promise<TransformTo>;
133
+
134
+ export type FileSingleSpec<
135
+ Value extends FileValue = FileValue,
136
+ // deno-lint-ignore no-explicit-any
137
+ TransformTo extends any = any,
138
+ ActionState extends ContextState = ContextState,
139
+ > = {
140
+ dataType: 'file';
141
+ multipleValues?: undefined;
142
+ options?: undefined;
143
+ contentType?: string | string[];
144
+ validator?: ValidatorFn<FileValue, Value>;
145
+ transformer?: TransformerFn<Value, TransformTo, ActionState>;
146
+ };
147
+
148
+ export type FileMultiSpec<
149
+ Value extends FileValue = FileValue,
150
+ // deno-lint-ignore no-explicit-any
151
+ TransformTo extends any = any,
152
+ ActionState extends ContextState = ContextState,
153
+ > = {
154
+ dataType: 'file';
155
+ multipleValues: true;
156
+ options?: undefined;
157
+ contentType?: string | string[];
158
+ validator?: ValidatorFn<FileValue, Value>;
159
+ transformer?: TransformerFn<Value[], TransformTo, ActionState>;
160
+ };
161
+
162
+ export type BooleanSingleSpec<
163
+ Value extends boolean = boolean,
164
+ // deno-lint-ignore no-explicit-any
165
+ TransformTo extends any = any,
166
+ ActionState extends ContextState = ContextState,
167
+ > = {
168
+ dataType: 'boolean';
169
+ options?: ActionOptions<Value>;
170
+ multipleValues?: undefined;
171
+ contentType?: undefined;
172
+ validator?: ValidatorFn<boolean, Value>;
173
+ transformer?: TransformerFn<Value, TransformTo, ActionState>;
174
+ };
175
+
176
+ export type BooleanMultiSpec<
177
+ Value extends boolean = boolean,
178
+ // deno-lint-ignore no-explicit-any
179
+ TransformTo extends any = any,
180
+ ActionState extends ContextState = ContextState,
181
+ > = {
182
+ dataType: 'boolean';
183
+ options?: ActionOptions<Value>;
184
+ multipleValues: true;
185
+ contentType?: undefined;
186
+ validator?: ValidatorFn<boolean, Value>;
187
+ transformer?: TransformerFn<Value[], TransformTo, ActionState>;
188
+ };
189
+
190
+ export type NumberSingleSpec<
191
+ Value extends number = number,
192
+ // deno-lint-ignore no-explicit-any
193
+ TransformTo extends any = any,
194
+ ActionState extends ContextState = ContextState,
195
+ > = {
196
+ dataType: 'number';
197
+ options?: ActionOptions<Value>;
198
+ multipleValues?: undefined;
199
+ contentType?: undefined;
200
+ validator?: ValidatorFn<number, Value>;
201
+ transformer?: TransformerFn<Value, TransformTo, ActionState>;
202
+ };
203
+
204
+ export type NumberMultiSpec<
205
+ Value extends number = number,
206
+ // deno-lint-ignore no-explicit-any
207
+ TransformTo extends any = any,
208
+ ActionState extends ContextState = ContextState,
209
+ > = {
210
+ dataType: 'number';
211
+ options?: ActionOptions<Value>;
212
+ multipleValues: true;
213
+ contentType?: undefined;
214
+ validator?: ValidatorFn<number, Value>;
215
+ transformer?: TransformerFn<Value[], TransformTo, ActionState>;
216
+ };
217
+
218
+ export type StringSingleSpec<
219
+ Value extends string = string,
220
+ TransformTo extends unknown = unknown,
221
+ ActionState extends ContextState = ContextState,
222
+ > = {
223
+ dataType: 'string';
224
+ options?: ActionOptions<Value>;
225
+ multipleValues?: undefined;
226
+ contentType?: undefined;
227
+ validator?: ValidatorFn<string, Value>;
228
+ transformer?: TransformerFn<Value, TransformTo, ActionState>;
229
+ };
230
+
231
+ export type StringMultiSpec<
232
+ Value extends string = string,
233
+ TransformTo extends unknown = unknown,
234
+ ActionState extends ContextState = ContextState,
235
+ > = {
236
+ dataType: 'string';
237
+ options?: ActionOptions<Value>;
238
+ multipleValues: true;
239
+ contentType?: undefined;
240
+ validator?: ValidatorFn<string, Value>;
241
+ transformer?: TransformerFn<Value[], TransformTo, ActionState>;
242
+ };
243
+
244
+ export type JSONValueSingleSpec<
245
+ Value extends JSONValue = JSONValue,
246
+ // deno-lint-ignore no-explicit-any
247
+ TransformTo extends any = any,
248
+ ActionState extends ContextState = ContextState,
249
+ > = {
250
+ dataType?: undefined;
251
+ options?: ActionOptions<Value>;
252
+ multipleValues?: undefined;
253
+ contentType?: undefined;
254
+ validator?: ValidatorFn<JSONValue, Value>;
255
+ transformer?: TransformerFn<Value, TransformTo, ActionState>;
256
+ };
257
+
258
+ export type JSONValueMultiSpec<
259
+ Value extends JSONValue = JSONValue,
260
+ // deno-lint-ignore no-explicit-any
261
+ TransformTo extends any = any,
262
+ ActionState extends ContextState = ContextState,
263
+ > = {
264
+ dataType?: undefined;
265
+ options?: ActionOptions<Value>;
266
+ multipleValues: true;
267
+ contentType?: undefined;
268
+ validator?: ValidatorFn<JSONValue, Value>;
269
+ transformer?: TransformerFn<Value[], TransformTo, ActionState>;
270
+ };
271
+
272
+ export type SpecOptions<
273
+ ActionState extends ContextState = ContextState,
274
+ > =
275
+ // deno-lint-ignore no-explicit-any
276
+ | BooleanSingleSpec<boolean, any, ActionState>
277
+ // deno-lint-ignore no-explicit-any
278
+ | BooleanMultiSpec<boolean, any, ActionState>
279
+ // deno-lint-ignore no-explicit-any
280
+ | NumberSingleSpec<number, any, ActionState>
281
+ // deno-lint-ignore no-explicit-any
282
+ | NumberMultiSpec<number, any, ActionState>
283
+ // deno-lint-ignore no-explicit-any
284
+ | StringSingleSpec<string, any, ActionState>
285
+ // deno-lint-ignore no-explicit-any
286
+ | StringMultiSpec<string, any, ActionState>
287
+ // deno-lint-ignore no-explicit-any
288
+ | JSONValueSingleSpec<JSONValue, any, ActionState>
289
+ // deno-lint-ignore no-explicit-any
290
+ | JSONValueMultiSpec<JSONValue, any, ActionState>
291
+ // deno-lint-ignore no-explicit-any
292
+ | FileSingleSpec<FileValue, any, ActionState>
293
+ // deno-lint-ignore no-explicit-any
294
+ | FileMultiSpec<FileValue, any, ActionState>
295
+ ;
296
+
297
+ export type BaseSpec<
298
+ ActionState extends ContextState = ContextState,
299
+ InternalTerm extends string = string,
300
+ > =
301
+ & {
302
+ valueName?: string;
303
+ internalTerm?: InternalTerm;
304
+ readonlyValue?: boolean;
305
+ defaultValue?: JSONValue;
306
+ valueRequired?: boolean;
307
+ minValue?: JSONPrimitive;
308
+ maxValue?: JSONPrimitive;
309
+ stepValue?: number;
310
+ valuePattern?: string;
311
+ validationMessage?: string;
312
+ parseFailureMessage?: string;
313
+ parseFailureStatus?: number;
314
+ }
315
+ & (
316
+ | { typeDef?: TypeDef; type?: undefined }
317
+ | { type: string; typeDef?: undefined }
318
+ )
319
+ & SpecOptions<ActionState>;
320
+
321
+ export type ValueSpec<ActionState extends ContextState = ContextState> =
322
+ & BaseSpec<ActionState>
323
+ & {
324
+ multipleValues?: false;
325
+ valueMaxLength?: number;
326
+ valueMinLength?: number;
327
+ properties?: undefined;
328
+ };
329
+
330
+ export type ArraySpec<ActionState extends ContextState = ContextState> =
331
+ & BaseSpec<ActionState>
332
+ & {
333
+ multipleValues: true;
334
+ valueMaxLength?: number;
335
+ valueMinLength?: number;
336
+ properties?: undefined;
337
+ };
338
+
339
+ export type ObjectSpec<
340
+ ActionState extends ContextState = ContextState,
341
+ RecursionCount extends RecursiveDigit | 'STOP' = 7,
342
+ > = BaseSpec & {
343
+ multipleValues?: false;
344
+ valueMaxLength?: undefined;
345
+ valueMinLength?: undefined;
346
+ properties: {
347
+ [term: string]: PropertySpec<
348
+ ActionState,
349
+ RecursiveIncrement<RecursionCount>
350
+ >;
351
+ };
352
+ };
353
+
354
+ export type ObjectArraySpec<
355
+ ActionState extends ContextState = ContextState,
356
+ RecursionCount extends RecursiveDigit | 'STOP' = 7,
357
+ > = BaseSpec & {
358
+ multipleValues: true;
359
+ valueMaxLength?: number;
360
+ valueMinLength?: number;
361
+ properties: {
362
+ [term: string]: PropertySpec<
363
+ ActionState,
364
+ RecursiveIncrement<RecursionCount>
365
+ >;
366
+ };
367
+ };
368
+
369
+ /**
370
+ * @todo Support ActionState typing the Transformed func
371
+ */
372
+ export type PropertySpec<
373
+ ActionState extends ContextState = ContextState,
374
+ RecursionCount extends RecursiveDigit | 'STOP' = 7,
375
+ > =
376
+ // RecursionCount extends 'STOP' ? (
377
+ | ValueSpec<ActionState>
378
+ | ArraySpec<ActionState>
379
+ | ObjectSpec
380
+ | ObjectArraySpec; // ) : (
381
+ // | ValueSpec<ActionState>
382
+ // | ArraySpec<ActionState>
383
+ // | ObjectSpec<ActionState>
384
+ // | ObjectArraySpec<ActionState>
385
+ // )
386
+
387
+ export type ActionSpec<ActionState extends ContextState = ContextState> = {
388
+ [term: string]: PropertySpec<ActionState>;
389
+ };
390
+
391
+ export type PropertySpecResult<PropertySpecItem extends PropertySpec> =
392
+ PropertySpecItem extends FileSingleSpec<
393
+ infer Value,
394
+ infer TransformTo,
395
+ infer State
396
+ > ? PropertySpecItem['transformer'] extends TransformerFn<
397
+ Value,
398
+ TransformTo,
399
+ State
400
+ > ? TransformTo
401
+ : PropertySpecItem['validator'] extends ValidatorFn<FileValue, Value> ? Value
402
+ : FileValue
403
+ : PropertySpecItem extends FileMultiSpec<
404
+ infer Value,
405
+ infer TransformTo,
406
+ infer State
407
+ > ? PropertySpecItem['transformer'] extends TransformerFn<
408
+ Value,
409
+ TransformTo,
410
+ State
411
+ > ? TransformTo
412
+ : PropertySpecItem['validator'] extends ValidatorFn<FileValue, Value> ? Value[]
413
+ : FileValue[]
414
+ : PropertySpecItem extends BooleanSingleSpec<
415
+ infer Value,
416
+ infer TransformTo,
417
+ infer State
418
+ > ? PropertySpecItem['transformer'] extends TransformerFn<
419
+ Value,
420
+ TransformTo,
421
+ State
422
+ > ? TransformTo
423
+ : PropertySpecItem['validator'] extends ValidatorFn<boolean, Value>
424
+ ? Value
425
+ : boolean
426
+ : PropertySpecItem extends BooleanMultiSpec<
427
+ infer Value,
428
+ infer TransformTo,
429
+ infer State
430
+ > ? PropertySpecItem['transformer'] extends TransformerFn<
431
+ Value,
432
+ TransformTo,
433
+ State
434
+ > ? TransformTo
435
+ : PropertySpecItem['validator'] extends ValidatorFn<boolean, Value>
436
+ ? Value[]
437
+ : boolean[]
438
+ : PropertySpecItem extends NumberSingleSpec<
439
+ infer Value,
440
+ infer TransformTo,
441
+ infer State
442
+ > ? PropertySpecItem['transformer'] extends TransformerFn<
443
+ Value,
444
+ TransformTo,
445
+ State
446
+ > ? TransformTo
447
+ : PropertySpecItem['validator'] extends ValidatorFn<number, Value> ? Value
448
+ : number
449
+ : PropertySpecItem extends NumberMultiSpec<
450
+ infer Value,
451
+ infer TransformTo,
452
+ infer State
453
+ > ? PropertySpecItem['transformer'] extends TransformerFn<
454
+ Value,
455
+ TransformTo,
456
+ State
457
+ > ? TransformTo
458
+ : PropertySpecItem['validator'] extends ValidatorFn<number, Value>
459
+ ? Value[]
460
+ : number[]
461
+ : PropertySpecItem extends StringSingleSpec<
462
+ infer Value,
463
+ infer TransformTo,
464
+ infer State
465
+ > ? PropertySpecItem['transformer'] extends TransformerFn<
466
+ Value,
467
+ TransformTo,
468
+ State
469
+ > ? TransformTo
470
+ : PropertySpecItem['validator'] extends ValidatorFn<string, Value> ? Value
471
+ : string
472
+ : PropertySpecItem extends StringMultiSpec<
473
+ infer Value,
474
+ infer TransformTo,
475
+ infer State
476
+ > ? PropertySpecItem['transformer'] extends TransformerFn<
477
+ Value,
478
+ TransformTo,
479
+ State
480
+ > ? TransformTo
481
+ : PropertySpecItem['validator'] extends ValidatorFn<
482
+ string,
483
+ Value
484
+ > ? Value[]
485
+ : string[]
486
+ : PropertySpecItem extends JSONValueSingleSpec<
487
+ infer Value,
488
+ infer TransformTo,
489
+ infer _State
490
+ > ? PropertySpecItem['transformer'] extends TransformerFn<
491
+ Value,
492
+ TransformTo
493
+ > ? TransformTo
494
+ : PropertySpecItem['validator'] extends ValidatorFn<
495
+ JSONValue,
496
+ Value
497
+ > ? Value
498
+ : JSONValue
499
+ : PropertySpecItem extends JSONValueMultiSpec<
500
+ infer Value,
501
+ infer TransformTo,
502
+ infer _State
503
+ > ? PropertySpecItem['transformer'] extends TransformerFn<
504
+ Value,
505
+ TransformTo
506
+ > ? TransformTo
507
+ : PropertySpecItem['validator'] extends ValidatorFn<
508
+ JSONValue,
509
+ Value
510
+ > ? Value[]
511
+ : JSONValue[]
512
+ : JSONValue;
513
+
514
+ export type ActionPayload<
515
+ Spec extends ActionSpec<ContextState> = ActionSpec<ContextState>,
516
+ > = {
517
+ [
518
+ Term in keyof Spec as Spec[Term] extends { internalTerm: string }
519
+ ? Spec[Term]['internalTerm']
520
+ : Term
521
+ ]: Spec[Term] extends ObjectArraySpec
522
+ ? Array<ActionPayload<Spec[Term]['properties']>>
523
+ : Spec[Term] extends ObjectSpec ? ActionPayload<Spec[Term]['properties']>
524
+ : PropertySpecResult<Spec[Term]>;
525
+ };
526
+
527
+ export type ResponseInputSpec = {
528
+ '@type': 'https://schema.org/PropertyValueSpecification';
529
+ readonlyValue?: boolean;
530
+ defaultValue?: JSONValue;
531
+ minValue?: JSONPrimitive;
532
+ maxValue?: JSONPrimitive;
533
+ stepValue?: number;
534
+ valueName?: string;
535
+ valuePatern?: string;
536
+ valueRequired?: boolean;
537
+ multipleValues?: boolean;
538
+ valueMaxLength?: number;
539
+ valueMinLength?: number;
540
+ };
541
+
542
+ export type SpecValue = {
543
+ [key: string]: SpecValue | ActionOptions<JSONValue> | ResponseInputSpec;
544
+ }
545
+
@@ -0,0 +1,146 @@
1
+ import type { HTTPWriter } from "./writer.js";
2
+ import type { Registry } from '../registry.js';
3
+ import type { Scope } from "../scopes.js";
4
+ import type { ContextState, ActionSpec } from "./spec.js";
5
+ import type { Context } from "./context.js";
6
+ import type { ServerResponse } from "node:http";
7
+ import type { JSONObject, TypeDef } from "../jsonld.js";
8
+ import type {HandlerDefinition} from "../mod.js";
9
+
10
+ export type HintLink = {
11
+ href: string;
12
+ rel?: string | string[];
13
+ type?: string;
14
+ as?: string;
15
+ preload?: boolean;
16
+ fetchPriority?: 'high' | 'low' | 'auto';
17
+ crossOrigin?: boolean;
18
+ link?: undefined;
19
+ csp?: undefined;
20
+ };
21
+
22
+ export type HintObj = {
23
+ link: HintLink | HintLink[];
24
+ csp?: string;
25
+ href?: undefined;
26
+ rel?: undefined;
27
+ type?: undefined;
28
+ as?: undefined;
29
+ preload?: undefined;
30
+ fetchPriority?: undefined;
31
+ crossOrigin?: undefined;
32
+ };
33
+
34
+ export type HintFn = () => HintObj | HintLink | HintLink[];
35
+
36
+ export type HintArgs =
37
+ | HintLink
38
+ | HintLink[]
39
+ | HintObj
40
+ | HintFn
41
+ ;
42
+
43
+ /**
44
+ * An object of values that can be used to programically query actions
45
+ * by metadata defined on the action.
46
+ */
47
+ export type HandlerMeta = Record<symbol | string, unknown>;
48
+
49
+ /**
50
+ * A fixed value that an endpoint will always return.
51
+ */
52
+ export type HandlerValue = Exclude<BodyInit, ReadableStream>;
53
+
54
+ /**
55
+ * An action handler function that is passed a context object.
56
+ * Responses should be set on the context object.
57
+ */
58
+ export type HandlerFn<
59
+ State extends ContextState = ContextState,
60
+ Spec extends ActionSpec = ActionSpec,
61
+ > = (ctx: Context<State, Spec>) => void | Promise<void>;
62
+
63
+ /**
64
+ * A handler object argument.
65
+ *
66
+ * Occultist extensions can use this handler argument method to provide arguments
67
+ * which are usually defined while defining the action.
68
+ */
69
+ export interface HandlerObj<
70
+ State extends ContextState = ContextState,
71
+ Spec extends ActionSpec = ActionSpec,
72
+ > {
73
+ contentType: string | string[];
74
+ handler: HandlerFn<State, Spec> | HandlerValue;
75
+ meta?: HandlerMeta;
76
+ hints?: HintArgs;
77
+ };
78
+
79
+ /**
80
+ * Handler arguments for an action.
81
+ */
82
+ export type HandlerArgs<
83
+ State extends ContextState = ContextState,
84
+ Spec extends ActionSpec = ActionSpec,
85
+ > =
86
+ | HandlerValue
87
+ | HandlerFn<State, Spec>
88
+ | HandlerObj<State, Spec>
89
+ ;
90
+
91
+ export type HandleRequestArgs = {
92
+ startTime: number;
93
+ contentType?: string;
94
+ language?: string;
95
+ encoding?: string;
96
+ url: string;
97
+ req: Request;
98
+ writer: HTTPWriter;
99
+ };
100
+
101
+ export interface ImplementedAction<
102
+ State extends ContextState = ContextState,
103
+ Spec extends ActionSpec = ActionSpec,
104
+ > {
105
+ readonly public: boolean;
106
+ readonly method: string;
107
+ readonly term?: string;
108
+ readonly type?: string;
109
+ readonly typeDef?: TypeDef;
110
+ readonly name: string;
111
+ readonly pattern: URLPattern;
112
+ readonly template: string;
113
+ readonly spec: Spec;
114
+ readonly registry: Registry;
115
+ readonly scope?: Scope;
116
+ readonly handlers: HandlerDefinition<State, Spec>[];
117
+ readonly contentTypes: string[];
118
+ readonly context: JSONObject;
119
+
120
+ /**
121
+ * @todo
122
+ *
123
+ * Creates a URL compatible with this action.
124
+ */
125
+ url(): string;
126
+
127
+ /**
128
+ * @todo
129
+ *
130
+ * Returns an object which could be serialized to json
131
+ * representing this action.
132
+ */
133
+ jsonld(): Promise<JSONObject | null>;
134
+
135
+ /**
136
+ * Creates a partial objecting containing the `@type` and `@id`
137
+ * properties of this action for JSON-ld serialization.
138
+ */
139
+ jsonldPartial(): { '@type': string, '@id': string } | null;
140
+
141
+ /**
142
+ * Handles a request which has resolved to this action.
143
+ */
144
+ handleRequest(args: HandleRequestArgs): Promise<Response | ServerResponse>;
145
+ }
146
+