@occultist/occultist 0.0.7 → 0.0.9

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 (47) hide show
  1. package/dist/actions/actionSets.d.ts +2 -2
  2. package/dist/actions/actions.d.ts +24 -18
  3. package/dist/actions/actions.js +131 -104
  4. package/dist/actions/context.d.ts +12 -6
  5. package/dist/actions/context.js +15 -5
  6. package/dist/actions/core.d.ts +98 -0
  7. package/dist/actions/core.js +386 -0
  8. package/dist/actions/types.d.ts +9 -11
  9. package/dist/cache/cache.d.ts +57 -16
  10. package/dist/cache/cache.js +253 -111
  11. package/dist/cache/file.d.ts +2 -2
  12. package/dist/cache/file.js +3 -3
  13. package/dist/cache/memory.d.ts +13 -4
  14. package/dist/cache/memory.js +9 -5
  15. package/dist/cache/types.d.ts +211 -39
  16. package/dist/cache/types.js +0 -1
  17. package/dist/mod.d.ts +2 -1
  18. package/dist/mod.js +2 -1
  19. package/dist/processAction.d.ts +4 -4
  20. package/dist/processAction.js +0 -1
  21. package/dist/registry.d.ts +112 -0
  22. package/dist/registry.js +174 -14
  23. package/dist/scopes.d.ts +2 -2
  24. package/dist/scopes.js +3 -3
  25. package/dist/types.d.ts +8 -0
  26. package/dist/types.js +1 -0
  27. package/dist/utils/headerObjToHeaders.d.ts +9 -0
  28. package/dist/utils/headerObjToHeaders.js +21 -0
  29. package/dist/utils/makeURLPattern.js +0 -1
  30. package/lib/actions/actionSets.ts +3 -3
  31. package/lib/actions/actions.ts +181 -111
  32. package/lib/actions/context.ts +23 -11
  33. package/lib/actions/core.ts +503 -0
  34. package/lib/actions/types.ts +23 -15
  35. package/lib/cache/cache.ts +347 -137
  36. package/lib/cache/file.ts +4 -4
  37. package/lib/cache/memory.ts +22 -7
  38. package/lib/cache/types.ts +243 -42
  39. package/lib/mod.ts +2 -1
  40. package/lib/processAction.ts +5 -4
  41. package/lib/registry.ts +260 -19
  42. package/lib/scopes.ts +6 -6
  43. package/lib/types.ts +11 -0
  44. package/lib/utils/headerObjToHeaders.ts +25 -0
  45. package/lib/utils/makeURLPattern.ts +0 -1
  46. package/package.json +1 -1
  47. package/lib/actions/meta.ts +0 -336
@@ -1,5 +1,5 @@
1
1
  import { type Accept } from "../accept.ts";
2
- import type { ActionMeta } from "./meta.ts";
2
+ import type { ActionCore } from "./core.ts";
3
3
  import type { ImplementedAction } from "./types.ts";
4
4
  export type UnsupportedContentTypeMatch = {
5
5
  type: 'unsupported-content-type';
@@ -18,6 +18,6 @@ export type ActionMatchResult = UnsupportedContentTypeMatch | ActionAcceptMatch;
18
18
  */
19
19
  export declare class ActionSet {
20
20
  #private;
21
- constructor(rootIRI: string, method: string, path: string, meta: ActionMeta[]);
21
+ constructor(rootIRI: string, method: string, path: string, meta: ActionCore[]);
22
22
  matches(method: string, path: string, accept: Accept): null | ActionMatchResult;
23
23
  }
@@ -1,10 +1,10 @@
1
- import type { CacheInstanceArgs } from '../cache/types.ts';
1
+ import type { CacheInstanceArgs, CacheOperationResult } from '../cache/types.ts';
2
2
  import type { JSONLDContext, JSONObject, TypeDef } from "../jsonld.ts";
3
3
  import type { Registry } from '../registry.ts';
4
4
  import type { Scope } from "../scopes.ts";
5
- import { type ActionMeta } from "./meta.ts";
5
+ import { MiddlewareRefs, type ActionCore } from "./core.ts";
6
6
  import type { ActionSpec, ContextState } from "./spec.ts";
7
- import type { AuthMiddleware, AuthState, HandleRequestArgs, HandlerFn, HandlerMeta, HandlerObj, HandlerValue, HintArgs, ImplementedAction } from './types.ts';
7
+ import type { AuthMiddleware, AuthState, HandlerFn, HandlerMeta, HandlerObj, HandlerValue, HintArgs, ImplementedAction } from './types.ts';
8
8
  import { type ResponseTypes } from './writer.ts';
9
9
  export type DefineArgs<Term extends string = string, Spec extends ActionSpec = ActionSpec> = {
10
10
  typeDef?: TypeDef<Term>;
@@ -21,7 +21,7 @@ export declare class HandlerDefinition<State extends ContextState = ContextState
21
21
  meta: HandlerMeta;
22
22
  action: ImplementedAction<State, Auth, Spec>;
23
23
  cache: ReadonlyArray<CacheInstanceArgs>;
24
- constructor(name: string, contentType: string, handler: HandlerFn | HandlerValue, meta: HandlerMeta, action: ImplementedAction<State, Auth, Spec>, actionMeta: ActionMeta);
24
+ constructor(name: string, contentType: string, handler: HandlerFn | HandlerValue, meta: HandlerMeta, action: ImplementedAction<State, Auth, Spec>, actionMeta: ActionCore);
25
25
  get [Symbol.toStringTag](): string;
26
26
  }
27
27
  export interface Handleable<State extends ContextState = ContextState, Auth extends AuthState = AuthState, Spec extends ActionSpec = ActionSpec> {
@@ -36,9 +36,9 @@ export interface Handleable<State extends ContextState = ContextState, Auth exte
36
36
  }
37
37
  export declare class FinalizedAction<State extends ContextState = ContextState, Auth extends AuthState = AuthState, Spec extends ActionSpec = ActionSpec> implements Handleable<State, Auth, Spec>, ImplementedAction<State, Auth, Spec> {
38
38
  #private;
39
- constructor(typeDef: TypeDef | undefined, spec: Spec, meta: ActionMeta<State, Auth, Spec>, handlerArgs: HandlerObj<State, Auth, Spec>);
40
- static fromHandlers<State extends ContextState = ContextState, Auth extends AuthState = AuthState, Spec extends ActionSpec = ActionSpec>(typeDef: TypeDef | undefined, spec: Spec, meta: ActionMeta<State, Auth, Spec>, contextType: string | string[], handler: HandlerValue | HandlerFn<State, Auth, Spec>): FinalizedAction<State, Auth, Spec>;
41
- static fromHandlers<State extends ContextState = ContextState, Auth extends AuthState = AuthState, Spec extends ActionSpec = ActionSpec>(typeDef: TypeDef | undefined, spec: Spec, meta: ActionMeta<State, Auth, Spec>, handlerArgs: HandlerObj<State, Auth, Spec>): FinalizedAction<State, Auth, Spec>;
39
+ constructor(typeDef: TypeDef | undefined, spec: Spec, core: ActionCore<State, Auth, Spec>, handlerArgs: HandlerObj<State, Auth, Spec>);
40
+ static fromHandlers<State extends ContextState = ContextState, Auth extends AuthState = AuthState, Spec extends ActionSpec = ActionSpec>(typeDef: TypeDef | undefined, spec: Spec, core: ActionCore<State, Auth, Spec>, contextType: string | string[], handler: HandlerValue | HandlerFn<State, Auth, Spec>): FinalizedAction<State, Auth, Spec>;
41
+ static fromHandlers<State extends ContextState = ContextState, Auth extends AuthState = AuthState, Spec extends ActionSpec = ActionSpec>(typeDef: TypeDef | undefined, spec: Spec, core: ActionCore<State, Auth, Spec>, handlerArgs: HandlerObj<State, Auth, Spec>): FinalizedAction<State, Auth, Spec>;
42
42
  static toJSONLD(action: ImplementedAction, scope: Scope): Promise<JSONObject | null>;
43
43
  get public(): boolean;
44
44
  get method(): string;
@@ -68,15 +68,17 @@ export declare class FinalizedAction<State extends ContextState = ContextState,
68
68
  } | null;
69
69
  handle(contentType: string | string[], handler: HandlerFn<State, Auth, Spec> | HandlerValue): FinalizedAction<State, Auth, Spec>;
70
70
  handle(args: HandlerObj<State, Auth, Spec>): FinalizedAction<State, Auth, Spec>;
71
- handleRequest(args: HandleRequestArgs): Promise<ResponseTypes>;
72
- perform(req: Request): Promise<Response>;
71
+ handleRequest(refs: MiddlewareRefs<State, Auth, Spec>): Promise<ResponseTypes>;
72
+ primeCache(refs: MiddlewareRefs<State, Auth, Spec>): Promise<CacheOperationResult>;
73
+ refreshCache(refs: MiddlewareRefs<State, Auth, Spec>): Promise<CacheOperationResult>;
74
+ invalidateCache(refs: MiddlewareRefs<State, Auth, Spec>): Promise<CacheOperationResult>;
73
75
  }
74
76
  export interface Applicable<ActionType> {
75
77
  use(): ActionType;
76
78
  }
77
79
  export declare class DefinedAction<State extends ContextState = ContextState, Auth extends AuthState = AuthState, Term extends string = string, Spec extends ActionSpec = ActionSpec> implements Applicable<DefinedAction<State, Auth, Term, Spec>>, Handleable<State, Auth, Spec>, ImplementedAction<State, Auth, Spec> {
78
80
  #private;
79
- constructor(typeDef: TypeDef | undefined, spec: Spec, meta: ActionMeta<State, Auth, Spec>);
81
+ constructor(typeDef: TypeDef | undefined, spec: Spec, core: ActionCore<State, Auth, Spec>);
80
82
  get public(): boolean;
81
83
  get method(): string;
82
84
  get term(): string | undefined;
@@ -116,12 +118,14 @@ export declare class DefinedAction<State extends ContextState = ContextState, Au
116
118
  use(): DefinedAction<State, Auth, Term, Spec>;
117
119
  handle(contentType: string | string[], handler: HandlerValue | HandlerFn<State, Auth, Spec>): FinalizedAction<State, Auth, Spec>;
118
120
  handle(args: HandlerObj<State, Auth, Spec>): FinalizedAction<State, Auth, Spec>;
119
- handleRequest(args: HandleRequestArgs): Promise<ResponseTypes>;
120
- perform(req: Request): Promise<Response>;
121
+ handleRequest(refs: MiddlewareRefs<State, Auth, Spec>): Promise<ResponseTypes>;
122
+ primeCache(refs: MiddlewareRefs<State, Auth, Spec>): Promise<CacheOperationResult>;
123
+ refreshCache(refs: MiddlewareRefs<State, Auth, Spec>): Promise<CacheOperationResult>;
124
+ invalidateCache(refs: MiddlewareRefs<State, Auth, Spec>): Promise<CacheOperationResult>;
121
125
  }
122
126
  export declare class Action<State extends ContextState = ContextState, Auth extends AuthState = AuthState> implements Applicable<Action>, Handleable<State>, ImplementedAction<State> {
123
127
  #private;
124
- constructor(meta: ActionMeta<State>);
128
+ constructor(core: ActionCore<State>);
125
129
  get public(): boolean;
126
130
  get method(): string;
127
131
  get term(): string | undefined;
@@ -153,12 +157,14 @@ export declare class Action<State extends ContextState = ContextState, Auth exte
153
157
  define<Auth extends AuthState = AuthState, Term extends string = string, Spec extends ActionSpec = ActionSpec>(args: DefineArgs<Term, Spec>): DefinedAction<State, Auth, Term, Spec>;
154
158
  handle(contentType: string | string[], handler: HandlerValue | HandlerFn<State>): FinalizedAction<State>;
155
159
  handle(args: HandlerObj<State>): FinalizedAction<State>;
156
- handleRequest(args: HandleRequestArgs): Promise<ResponseTypes>;
157
- perform(req: Request): Promise<Response>;
160
+ handleRequest(refs: MiddlewareRefs<State, Auth, ActionSpec>): Promise<ResponseTypes>;
161
+ primeCache(refs: MiddlewareRefs<State, Auth, ActionSpec>): Promise<CacheOperationResult>;
162
+ refreshCache(refs: MiddlewareRefs<State, Auth, ActionSpec>): Promise<CacheOperationResult>;
163
+ invalidateCache(refs: MiddlewareRefs<State, Auth, ActionSpec>): Promise<CacheOperationResult>;
158
164
  }
159
165
  export declare class PreAction<State extends ContextState = ContextState, Auth extends AuthState = AuthState> implements Applicable<Action>, Handleable<State, Auth> {
160
166
  #private;
161
- constructor(meta: ActionMeta<State, Auth>);
167
+ constructor(core: ActionCore<State, Auth>);
162
168
  use(): Action<State, AuthState>;
163
169
  define<Term extends string = string, Spec extends ActionSpec = ActionSpec>(args: DefineArgs<Term, Spec>): DefinedAction<State, Auth, Term, Spec>;
164
170
  handle(contentType: string | string[], handler: HandlerValue | HandlerFn<State, Auth>): FinalizedAction<State, Auth>;
@@ -166,7 +172,7 @@ export declare class PreAction<State extends ContextState = ContextState, Auth e
166
172
  }
167
173
  export declare class Endpoint<State extends ContextState = ContextState, Auth extends AuthState = AuthState> implements Applicable<Action>, Handleable<State, Auth> {
168
174
  #private;
169
- constructor(meta: ActionMeta<State, Auth>);
175
+ constructor(core: ActionCore<State, Auth>);
170
176
  hint(hints: HintArgs): Endpoint<State, Auth>;
171
177
  compress(): Endpoint<State, Auth>;
172
178
  cache(args: CacheInstanceArgs): Endpoint<State, Auth>;
@@ -178,7 +184,7 @@ export declare class Endpoint<State extends ContextState = ContextState, Auth ex
178
184
  }
179
185
  export declare class ActionAuth<State extends ContextState = ContextState> {
180
186
  #private;
181
- constructor(meta: ActionMeta<State>);
187
+ constructor(core: ActionCore<State>);
182
188
  public<Auth extends AuthState = AuthState>(authMiddleware?: AuthMiddleware<Auth>): Endpoint<State, Auth>;
183
189
  private<Auth extends AuthState = AuthState>(authMiddleware: AuthMiddleware<Auth>): Endpoint<State, Auth>;
184
190
  }
@@ -2,7 +2,7 @@ import { getActionContext } from "../utils/getActionContext.js";
2
2
  import { getPropertyValueSpecifications } from "../utils/getPropertyValueSpecifications.js";
3
3
  import { isPopulatedObject } from "../utils/isPopulatedObject.js";
4
4
  import { joinPaths } from "../utils/joinPaths.js";
5
- import { AfterDefinition, BeforeDefinition } from "./meta.js";
5
+ import { AfterDefinition, BeforeDefinition } from "./core.js";
6
6
  function isHandlerObj(handler) {
7
7
  return isPopulatedObject(handler);
8
8
  }
@@ -36,33 +36,33 @@ export class HandlerDefinition {
36
36
  }
37
37
  export class FinalizedAction {
38
38
  #spec;
39
- #meta;
39
+ #core;
40
40
  #typeDef;
41
41
  #handlers;
42
- constructor(typeDef, spec, meta, handlerArgs) {
42
+ constructor(typeDef, spec, core, handlerArgs) {
43
43
  this.#typeDef = typeDef;
44
44
  this.#spec = spec ?? {};
45
- this.#meta = meta;
46
- this.#meta.action = this;
45
+ this.#core = core;
46
+ this.#core.action = this;
47
47
  const handlers = new Map();
48
48
  if (typeof handlerArgs.contentType === 'string') {
49
- handlers.set(handlerArgs.contentType, new HandlerDefinition(this.name, handlerArgs.contentType, handlerArgs.handler, handlerArgs.meta, this, this.#meta));
49
+ handlers.set(handlerArgs.contentType, new HandlerDefinition(this.name, handlerArgs.contentType, handlerArgs.handler, handlerArgs.meta, this, this.#core));
50
50
  }
51
51
  else if (isPopulatedObject(handlerArgs)) {
52
52
  for (let i = 0; i < handlerArgs.contentType.length; i++) {
53
- handlers.set(handlerArgs.contentType[i], new HandlerDefinition(this.name, handlerArgs.contentType[i], handlerArgs.handler, handlerArgs.meta, this, this.#meta));
53
+ handlers.set(handlerArgs.contentType[i], new HandlerDefinition(this.name, handlerArgs.contentType[i], handlerArgs.handler, handlerArgs.meta, this, this.#core));
54
54
  }
55
55
  }
56
56
  this.#handlers = handlers;
57
57
  }
58
- static fromHandlers(typeDef, spec, meta, arg3, arg4) {
58
+ static fromHandlers(typeDef, spec, core, arg3, arg4) {
59
59
  if (Array.isArray(arg3) || typeof arg3 === 'string') {
60
- return new FinalizedAction(typeDef, spec, meta, {
60
+ return new FinalizedAction(typeDef, spec, core, {
61
61
  contentType: arg3,
62
62
  handler: arg4,
63
63
  });
64
64
  }
65
- return new FinalizedAction(typeDef, spec, meta, arg3);
65
+ return new FinalizedAction(typeDef, spec, core, arg3);
66
66
  }
67
67
  static async toJSONLD(action, scope) {
68
68
  if (scope == null || action.typeDef == null) {
@@ -83,10 +83,10 @@ export class FinalizedAction {
83
83
  };
84
84
  }
85
85
  get public() {
86
- return this.#meta.public;
86
+ return this.#core.public;
87
87
  }
88
88
  get method() {
89
- return this.#meta.method;
89
+ return this.#core.method;
90
90
  }
91
91
  get term() {
92
92
  return this.#typeDef?.term;
@@ -98,22 +98,22 @@ export class FinalizedAction {
98
98
  return this.#typeDef;
99
99
  }
100
100
  get name() {
101
- return this.#meta.name;
101
+ return this.#core.name;
102
102
  }
103
103
  get template() {
104
- return this.#meta.uriTemplate;
104
+ return this.#core.uriTemplate;
105
105
  }
106
106
  get pattern() {
107
- return this.#meta.path.pattern;
107
+ return this.#core.path.pattern;
108
108
  }
109
109
  get spec() {
110
110
  return this.#spec;
111
111
  }
112
112
  get scope() {
113
- return this.#meta.scope;
113
+ return this.#core.scope;
114
114
  }
115
115
  get registry() {
116
- return this.#meta.registry;
116
+ return this.#core.registry;
117
117
  }
118
118
  get handlers() {
119
119
  return Array.from(this.#handlers.values());
@@ -129,7 +129,7 @@ export class FinalizedAction {
129
129
  });
130
130
  }
131
131
  url() {
132
- return joinPaths(this.#meta.registry.rootIRI, this.#meta.path.normalized);
132
+ return joinPaths(this.#core.registry.rootIRI, this.#core.path.normalized);
133
133
  }
134
134
  /**
135
135
  * Retrives the handler configured for the given content type.
@@ -140,18 +140,18 @@ export class FinalizedAction {
140
140
  return this.#handlers.get(contentType);
141
141
  }
142
142
  jsonld() {
143
- const scope = this.#meta.scope;
143
+ const scope = this.#core.scope;
144
144
  return FinalizedAction.toJSONLD(this, scope);
145
145
  }
146
146
  jsonldPartial() {
147
- const scope = this.#meta.scope;
147
+ const scope = this.#core.scope;
148
148
  const typeDef = this.#typeDef;
149
149
  if (scope == null || typeDef == null) {
150
150
  return null;
151
151
  }
152
152
  return {
153
153
  '@type': typeDef.type,
154
- '@id': joinPaths(scope.url(), this.#meta.name),
154
+ '@id': joinPaths(scope.url(), this.#core.name),
155
155
  };
156
156
  }
157
157
  handle(arg1, arg2) {
@@ -174,42 +174,55 @@ export class FinalizedAction {
174
174
  meta = Object.create(null);
175
175
  }
176
176
  if (!Array.isArray(contentType)) {
177
- this.#handlers.set(contentType, new HandlerDefinition(this.#meta.name, contentType, handler, meta, this, this.#meta));
177
+ this.#handlers.set(contentType, new HandlerDefinition(this.#core.name, contentType, handler, meta, this, this.#core));
178
178
  }
179
179
  else {
180
180
  for (let i = 0; i < contentType.length; i++) {
181
- this.#handlers.set(contentType[i], new HandlerDefinition(this.#meta.name, contentType[i], handler, meta, this, this.#meta));
181
+ this.#handlers.set(contentType[i], new HandlerDefinition(this.#core.name, contentType[i], handler, meta, this, this.#core));
182
182
  }
183
183
  }
184
184
  return this;
185
185
  }
186
- handleRequest(args) {
187
- const handler = this.#handlers.get(args.contentType);
188
- return this.#meta.handleRequest({
189
- ...args,
190
- spec: this.#spec,
191
- handler,
192
- });
193
- }
194
- perform(req) {
195
- return this.#meta.perform(req);
186
+ handleRequest(refs) {
187
+ const handler = this.#handlers.get(refs.contentType);
188
+ refs.spec = this.#spec;
189
+ refs.handler = handler;
190
+ return this.#core.handleRequest(refs);
191
+ }
192
+ primeCache(refs) {
193
+ const handler = this.#handlers.get(refs.contentType);
194
+ refs.spec = this.#spec;
195
+ refs.handler = handler;
196
+ return this.#core.primeCache(refs);
197
+ }
198
+ refreshCache(refs) {
199
+ const handler = this.#handlers.get(refs.contentType);
200
+ refs.spec = this.#spec;
201
+ refs.handler = handler;
202
+ return this.#core.refreshCache(refs);
203
+ }
204
+ invalidateCache(refs) {
205
+ const handler = this.#handlers.get(refs.contentType);
206
+ refs.spec = this.#spec;
207
+ refs.handler = handler;
208
+ return this.#core.invalidateCache(refs);
196
209
  }
197
210
  }
198
211
  export class DefinedAction {
199
212
  #spec;
200
- #meta;
213
+ #core;
201
214
  #typeDef;
202
- constructor(typeDef, spec, meta) {
215
+ constructor(typeDef, spec, core) {
203
216
  this.#spec = spec ?? {};
204
- this.#meta = meta;
217
+ this.#core = core;
205
218
  this.#typeDef = typeDef;
206
- this.#meta.action = this;
219
+ this.#core.action = this;
207
220
  }
208
221
  get public() {
209
- return this.#meta.public;
222
+ return this.#core.public;
210
223
  }
211
224
  get method() {
212
- return this.#meta.method;
225
+ return this.#core.method;
213
226
  }
214
227
  get term() {
215
228
  return this.#typeDef?.term;
@@ -221,25 +234,25 @@ export class DefinedAction {
221
234
  return this.#typeDef;
222
235
  }
223
236
  get name() {
224
- return this.#meta.name;
237
+ return this.#core.name;
225
238
  }
226
239
  get template() {
227
- return this.#meta.uriTemplate;
240
+ return this.#core.uriTemplate;
228
241
  }
229
242
  get pattern() {
230
- return this.#meta.path.pattern;
243
+ return this.#core.path.pattern;
231
244
  }
232
245
  get path() {
233
- return this.#meta.path.normalized;
246
+ return this.#core.path.normalized;
234
247
  }
235
248
  get spec() {
236
249
  return this.#spec;
237
250
  }
238
251
  get scope() {
239
- return this.#meta.scope;
252
+ return this.#core.scope;
240
253
  }
241
254
  get registry() {
242
- return this.#meta.registry;
255
+ return this.#core.registry;
243
256
  }
244
257
  get handlers() {
245
258
  return [];
@@ -264,18 +277,18 @@ export class DefinedAction {
264
277
  });
265
278
  }
266
279
  jsonld() {
267
- const scope = this.#meta.scope;
280
+ const scope = this.#core.scope;
268
281
  return FinalizedAction.toJSONLD(this, scope);
269
282
  }
270
283
  jsonldPartial() {
271
- const scope = this.#meta.scope;
284
+ const scope = this.#core.scope;
272
285
  const typeDef = this.#typeDef;
273
286
  if (scope == null || typeDef == null) {
274
287
  return null;
275
288
  }
276
289
  return {
277
290
  '@type': typeDef.type,
278
- '@id': joinPaths(scope.url(), this.#meta.name),
291
+ '@id': joinPaths(scope.url(), this.#core.name),
279
292
  };
280
293
  }
281
294
  /**
@@ -286,15 +299,15 @@ export class DefinedAction {
286
299
  * auth sensitive checks to be run which might reject the request.
287
300
  */
288
301
  cache(args) {
289
- if (this.#meta.cache.length !== 0 &&
290
- this.#meta.cacheOccurance === BeforeDefinition) {
302
+ if (this.#core.cache.length !== 0 &&
303
+ this.#core.cacheOccurance === BeforeDefinition) {
291
304
  throw new Error('Action cache may be defined either before or after ' +
292
305
  'the definition method is called, but not both.');
293
306
  }
294
- else if (this.#meta.cacheOccurance === BeforeDefinition) {
295
- this.#meta.cacheOccurance = AfterDefinition;
307
+ else if (this.#core.cacheOccurance === BeforeDefinition) {
308
+ this.#core.cacheOccurance = AfterDefinition;
296
309
  }
297
- this.#meta.cache.push(args);
310
+ this.#core.cache.push(args);
298
311
  return this;
299
312
  }
300
313
  meta() {
@@ -304,30 +317,37 @@ export class DefinedAction {
304
317
  return this;
305
318
  }
306
319
  handle(arg1, arg2) {
307
- return FinalizedAction.fromHandlers(this.#typeDef, this.#spec, this.#meta, arg1, arg2);
320
+ return FinalizedAction.fromHandlers(this.#typeDef, this.#spec, this.#core, arg1, arg2);
308
321
  }
309
- async handleRequest(args) {
310
- return this.#meta.handleRequest({
311
- ...args,
312
- spec: this.#spec,
313
- });
322
+ handleRequest(refs) {
323
+ refs.spec = this.#spec;
324
+ return this.#core.handleRequest(refs);
325
+ }
326
+ primeCache(refs) {
327
+ refs.spec = this.#spec;
328
+ return this.#core.primeCache(refs);
314
329
  }
315
- perform(req) {
316
- return this.#meta.perform(req);
330
+ refreshCache(refs) {
331
+ refs.spec = this.#spec;
332
+ return this.#core.refreshCache(refs);
333
+ }
334
+ invalidateCache(refs) {
335
+ refs.spec = this.#spec;
336
+ return this.#core.invalidateCache(refs);
317
337
  }
318
338
  }
319
339
  export class Action {
320
340
  #spec = {};
321
- #meta;
322
- constructor(meta) {
323
- this.#meta = meta;
324
- this.#meta.action = this;
341
+ #core;
342
+ constructor(core) {
343
+ this.#core = core;
344
+ this.#core.action = this;
325
345
  }
326
346
  get public() {
327
- return this.#meta.public;
347
+ return this.#core.public;
328
348
  }
329
349
  get method() {
330
- return this.#meta.method;
350
+ return this.#core.method;
331
351
  }
332
352
  get term() {
333
353
  return undefined;
@@ -339,25 +359,25 @@ export class Action {
339
359
  return undefined;
340
360
  }
341
361
  get name() {
342
- return this.#meta.name;
362
+ return this.#core.name;
343
363
  }
344
364
  get template() {
345
- return this.#meta.uriTemplate;
365
+ return this.#core.uriTemplate;
346
366
  }
347
367
  get pattern() {
348
- return this.#meta.path.pattern;
368
+ return this.#core.path.pattern;
349
369
  }
350
370
  get path() {
351
- return this.#meta.path.normalized;
371
+ return this.#core.path.normalized;
352
372
  }
353
373
  get spec() {
354
374
  return this.#spec;
355
375
  }
356
376
  get scope() {
357
- return this.#meta.scope;
377
+ return this.#core.scope;
358
378
  }
359
379
  get registry() {
360
- return this.#meta.registry;
380
+ return this.#core.registry;
361
381
  }
362
382
  get handlers() {
363
383
  return [];
@@ -391,81 +411,88 @@ export class Action {
391
411
  return this;
392
412
  }
393
413
  define(args) {
394
- return new DefinedAction(args.typeDef, args.spec ?? {}, this.#meta);
414
+ return new DefinedAction(args.typeDef, args.spec ?? {}, this.#core);
395
415
  }
396
416
  handle(arg1, arg2) {
397
- return FinalizedAction.fromHandlers(null, this.#spec, this.#meta, arg1, arg2);
417
+ return FinalizedAction.fromHandlers(null, this.#spec, this.#core, arg1, arg2);
398
418
  }
399
- async handleRequest(args) {
400
- return this.#meta.handleRequest({
401
- ...args,
402
- spec: this.#spec,
403
- });
419
+ handleRequest(refs) {
420
+ refs.spec = this.#spec;
421
+ return this.#core.handleRequest(refs);
422
+ }
423
+ primeCache(refs) {
424
+ refs.spec = this.#spec;
425
+ return this.#core.primeCache(refs);
426
+ }
427
+ refreshCache(refs) {
428
+ refs.spec = this.#spec;
429
+ return this.#core.refreshCache(refs);
404
430
  }
405
- perform(req) {
406
- return this.#meta.perform(req);
431
+ invalidateCache(refs) {
432
+ refs.spec = this.#spec;
433
+ return this.#core.refreshCache(refs);
407
434
  }
408
435
  }
409
436
  export class PreAction {
410
- #meta;
411
- constructor(meta) {
412
- this.#meta = meta;
437
+ #core;
438
+ constructor(core) {
439
+ this.#core = core;
413
440
  }
414
441
  use() {
415
- return new Action(this.#meta);
442
+ return new Action(this.#core);
416
443
  }
417
444
  define(args) {
418
- return new DefinedAction(args.typeDef, args.spec, this.#meta);
445
+ return new DefinedAction(args.typeDef, args.spec, this.#core);
419
446
  }
420
447
  handle(arg1, arg2) {
421
- return FinalizedAction.fromHandlers(null, {}, this.#meta, arg1, arg2);
448
+ return FinalizedAction.fromHandlers(null, {}, this.#core, arg1, arg2);
422
449
  }
423
450
  }
424
451
  export class Endpoint {
425
- #meta;
426
- constructor(meta) {
427
- this.#meta = meta;
452
+ #core;
453
+ constructor(core) {
454
+ this.#core = core;
428
455
  }
429
456
  hint(hints) {
430
- this.#meta.hints.push(hints);
457
+ this.#core.hints.push(hints);
431
458
  return this;
432
459
  }
433
460
  compress() {
434
461
  return this;
435
462
  }
436
463
  cache(args) {
437
- this.#meta.cache.push(args);
464
+ this.#core.cache.push(args);
438
465
  return this;
439
466
  }
440
467
  etag() {
441
468
  return this;
442
469
  }
443
470
  use() {
444
- return new Action(this.#meta);
471
+ return new Action(this.#core);
445
472
  }
446
473
  define(args) {
447
- return new DefinedAction(args.typeDef, args.spec, this.#meta);
474
+ return new DefinedAction(args.typeDef, args.spec, this.#core);
448
475
  }
449
476
  handle(arg1, arg2) {
450
- return FinalizedAction.fromHandlers(undefined, {}, this.#meta, arg1, arg2);
477
+ return FinalizedAction.fromHandlers(undefined, {}, this.#core, arg1, arg2);
451
478
  }
452
479
  }
453
480
  export class ActionAuth {
454
- #meta;
455
- constructor(meta) {
456
- this.#meta = meta;
481
+ #core;
482
+ constructor(core) {
483
+ this.#core = core;
457
484
  }
458
485
  public(authMiddleware) {
459
486
  if (authMiddleware != null && typeof authMiddleware !== 'function')
460
487
  throw new Error('Public action given invalid auth middleware');
461
- this.#meta.public = true;
462
- this.#meta.auth = authMiddleware;
463
- return new Endpoint(this.#meta);
488
+ this.#core.public = true;
489
+ this.#core.auth = authMiddleware;
490
+ return new Endpoint(this.#core);
464
491
  }
465
492
  private(authMiddleware) {
466
493
  if (typeof authMiddleware !== 'function')
467
494
  throw new Error('Private action given invalid auth middleware');
468
- this.#meta.auth = authMiddleware;
469
- return new Endpoint(this.#meta);
495
+ this.#core.auth = authMiddleware;
496
+ return new Endpoint(this.#core);
470
497
  }
471
498
  }
@@ -1,18 +1,19 @@
1
- import type { HandlerDefinition } from "../mod.ts";
1
+ import type { CacheOperation, HandlerDefinition } from "../mod.ts";
2
2
  import type { Registry } from "../registry.ts";
3
3
  import type { ActionPayload, ActionSpec, ContextState, ParsedIRIValues } from "./spec.ts";
4
4
  import type { AuthState, ImplementedAction } from "./types.ts";
5
5
  import type { ResponseBody } from "./writer.ts";
6
6
  export type CacheContextArgs<Auth extends AuthState = AuthState> = {
7
7
  req: Request;
8
- url: string;
9
8
  contentType: string;
10
9
  public: boolean;
11
10
  authKey?: string;
12
11
  auth: Auth;
12
+ cacheOperation?: CacheOperation;
13
13
  handler: HandlerDefinition;
14
14
  params: ParsedIRIValues;
15
15
  query: ParsedIRIValues;
16
+ headers: Headers;
16
17
  };
17
18
  /**
18
19
  * Request context object.
@@ -24,8 +25,10 @@ export declare class CacheContext<Auth extends AuthState = AuthState> {
24
25
  url: string;
25
26
  contentType: string;
26
27
  public: boolean;
27
- authKey?: string;
28
+ authKey: string | null;
28
29
  auth: Auth;
30
+ cacheRun: boolean;
31
+ cacheOperation: CacheOperation | null;
29
32
  action: ImplementedAction;
30
33
  registry: Registry;
31
34
  params: ParsedIRIValues;
@@ -44,15 +47,16 @@ export declare class CacheContext<Auth extends AuthState = AuthState> {
44
47
  }
45
48
  export type ContextArgs<State extends ContextState = ContextState, Auth extends AuthState = AuthState, Spec extends ActionSpec = ActionSpec> = {
46
49
  req: Request;
47
- url: string;
48
50
  contentType: string;
49
51
  public: boolean;
50
52
  authKey?: string;
51
53
  auth: Auth;
52
- handler: HandlerDefinition<State, Spec>;
54
+ cacheOperation: CacheOperation | null;
55
+ handler: HandlerDefinition<State, Auth, Spec>;
53
56
  params: ParsedIRIValues;
54
57
  query: ParsedIRIValues;
55
58
  payload: ActionPayload<Spec>;
59
+ headers: Headers;
56
60
  };
57
61
  /**
58
62
  * Request context object.
@@ -66,8 +70,10 @@ export declare class Context<State extends ContextState = ContextState, Auth ext
66
70
  public: boolean;
67
71
  authKey?: string;
68
72
  auth: Auth;
73
+ cacheRun: boolean;
74
+ cacheOperation: CacheOperation | null;
69
75
  state: State;
70
- action: ImplementedAction<State, Spec>;
76
+ action: ImplementedAction<State, Auth, Spec>;
71
77
  registry: Registry;
72
78
  params: ParsedIRIValues;
73
79
  query: ParsedIRIValues;