@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.
- package/dist/actions/actionSets.d.ts +2 -2
- package/dist/actions/actions.d.ts +24 -18
- package/dist/actions/actions.js +131 -104
- package/dist/actions/context.d.ts +12 -6
- package/dist/actions/context.js +15 -5
- package/dist/actions/core.d.ts +98 -0
- package/dist/actions/core.js +386 -0
- package/dist/actions/types.d.ts +9 -11
- package/dist/cache/cache.d.ts +57 -16
- package/dist/cache/cache.js +253 -111
- package/dist/cache/file.d.ts +2 -2
- package/dist/cache/file.js +3 -3
- package/dist/cache/memory.d.ts +13 -4
- package/dist/cache/memory.js +9 -5
- package/dist/cache/types.d.ts +211 -39
- package/dist/cache/types.js +0 -1
- package/dist/mod.d.ts +2 -1
- package/dist/mod.js +2 -1
- package/dist/processAction.d.ts +4 -4
- package/dist/processAction.js +0 -1
- package/dist/registry.d.ts +112 -0
- package/dist/registry.js +174 -14
- package/dist/scopes.d.ts +2 -2
- package/dist/scopes.js +3 -3
- package/dist/types.d.ts +8 -0
- package/dist/types.js +1 -0
- package/dist/utils/headerObjToHeaders.d.ts +9 -0
- package/dist/utils/headerObjToHeaders.js +21 -0
- package/dist/utils/makeURLPattern.js +0 -1
- package/lib/actions/actionSets.ts +3 -3
- package/lib/actions/actions.ts +181 -111
- package/lib/actions/context.ts +23 -11
- package/lib/actions/core.ts +503 -0
- package/lib/actions/types.ts +23 -15
- package/lib/cache/cache.ts +347 -137
- package/lib/cache/file.ts +4 -4
- package/lib/cache/memory.ts +22 -7
- package/lib/cache/types.ts +243 -42
- package/lib/mod.ts +2 -1
- package/lib/processAction.ts +5 -4
- package/lib/registry.ts +260 -19
- package/lib/scopes.ts +6 -6
- package/lib/types.ts +11 -0
- package/lib/utils/headerObjToHeaders.ts +25 -0
- package/lib/utils/makeURLPattern.ts +0 -1
- package/package.json +1 -1
- package/lib/actions/meta.ts +0 -336
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Accept } from "../accept.ts";
|
|
2
|
-
import type {
|
|
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:
|
|
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
|
|
5
|
+
import { MiddlewareRefs, type ActionCore } from "./core.ts";
|
|
6
6
|
import type { ActionSpec, ContextState } from "./spec.ts";
|
|
7
|
-
import type { AuthMiddleware, AuthState,
|
|
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:
|
|
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,
|
|
40
|
-
static fromHandlers<State extends ContextState = ContextState, Auth extends AuthState = AuthState, Spec extends ActionSpec = ActionSpec>(typeDef: TypeDef | undefined, spec: Spec,
|
|
41
|
-
static fromHandlers<State extends ContextState = ContextState, Auth extends AuthState = AuthState, Spec extends ActionSpec = ActionSpec>(typeDef: TypeDef | undefined, spec: 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(
|
|
72
|
-
|
|
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,
|
|
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(
|
|
120
|
-
|
|
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(
|
|
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(
|
|
157
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
}
|
package/dist/actions/actions.js
CHANGED
|
@@ -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 "./
|
|
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
|
-
#
|
|
39
|
+
#core;
|
|
40
40
|
#typeDef;
|
|
41
41
|
#handlers;
|
|
42
|
-
constructor(typeDef, spec,
|
|
42
|
+
constructor(typeDef, spec, core, handlerArgs) {
|
|
43
43
|
this.#typeDef = typeDef;
|
|
44
44
|
this.#spec = spec ?? {};
|
|
45
|
-
this.#
|
|
46
|
-
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.#
|
|
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.#
|
|
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,
|
|
58
|
+
static fromHandlers(typeDef, spec, core, arg3, arg4) {
|
|
59
59
|
if (Array.isArray(arg3) || typeof arg3 === 'string') {
|
|
60
|
-
return new FinalizedAction(typeDef, spec,
|
|
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,
|
|
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.#
|
|
86
|
+
return this.#core.public;
|
|
87
87
|
}
|
|
88
88
|
get method() {
|
|
89
|
-
return this.#
|
|
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.#
|
|
101
|
+
return this.#core.name;
|
|
102
102
|
}
|
|
103
103
|
get template() {
|
|
104
|
-
return this.#
|
|
104
|
+
return this.#core.uriTemplate;
|
|
105
105
|
}
|
|
106
106
|
get pattern() {
|
|
107
|
-
return this.#
|
|
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.#
|
|
113
|
+
return this.#core.scope;
|
|
114
114
|
}
|
|
115
115
|
get registry() {
|
|
116
|
-
return this.#
|
|
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.#
|
|
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.#
|
|
143
|
+
const scope = this.#core.scope;
|
|
144
144
|
return FinalizedAction.toJSONLD(this, scope);
|
|
145
145
|
}
|
|
146
146
|
jsonldPartial() {
|
|
147
|
-
const scope = this.#
|
|
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.#
|
|
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.#
|
|
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.#
|
|
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(
|
|
187
|
-
const handler = this.#handlers.get(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
#
|
|
213
|
+
#core;
|
|
201
214
|
#typeDef;
|
|
202
|
-
constructor(typeDef, spec,
|
|
215
|
+
constructor(typeDef, spec, core) {
|
|
203
216
|
this.#spec = spec ?? {};
|
|
204
|
-
this.#
|
|
217
|
+
this.#core = core;
|
|
205
218
|
this.#typeDef = typeDef;
|
|
206
|
-
this.#
|
|
219
|
+
this.#core.action = this;
|
|
207
220
|
}
|
|
208
221
|
get public() {
|
|
209
|
-
return this.#
|
|
222
|
+
return this.#core.public;
|
|
210
223
|
}
|
|
211
224
|
get method() {
|
|
212
|
-
return this.#
|
|
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.#
|
|
237
|
+
return this.#core.name;
|
|
225
238
|
}
|
|
226
239
|
get template() {
|
|
227
|
-
return this.#
|
|
240
|
+
return this.#core.uriTemplate;
|
|
228
241
|
}
|
|
229
242
|
get pattern() {
|
|
230
|
-
return this.#
|
|
243
|
+
return this.#core.path.pattern;
|
|
231
244
|
}
|
|
232
245
|
get path() {
|
|
233
|
-
return this.#
|
|
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.#
|
|
252
|
+
return this.#core.scope;
|
|
240
253
|
}
|
|
241
254
|
get registry() {
|
|
242
|
-
return this.#
|
|
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.#
|
|
280
|
+
const scope = this.#core.scope;
|
|
268
281
|
return FinalizedAction.toJSONLD(this, scope);
|
|
269
282
|
}
|
|
270
283
|
jsonldPartial() {
|
|
271
|
-
const scope = this.#
|
|
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.#
|
|
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.#
|
|
290
|
-
this.#
|
|
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.#
|
|
295
|
-
this.#
|
|
307
|
+
else if (this.#core.cacheOccurance === BeforeDefinition) {
|
|
308
|
+
this.#core.cacheOccurance = AfterDefinition;
|
|
296
309
|
}
|
|
297
|
-
this.#
|
|
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.#
|
|
320
|
+
return FinalizedAction.fromHandlers(this.#typeDef, this.#spec, this.#core, arg1, arg2);
|
|
308
321
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
-
|
|
316
|
-
|
|
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
|
-
#
|
|
322
|
-
constructor(
|
|
323
|
-
this.#
|
|
324
|
-
this.#
|
|
341
|
+
#core;
|
|
342
|
+
constructor(core) {
|
|
343
|
+
this.#core = core;
|
|
344
|
+
this.#core.action = this;
|
|
325
345
|
}
|
|
326
346
|
get public() {
|
|
327
|
-
return this.#
|
|
347
|
+
return this.#core.public;
|
|
328
348
|
}
|
|
329
349
|
get method() {
|
|
330
|
-
return this.#
|
|
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.#
|
|
362
|
+
return this.#core.name;
|
|
343
363
|
}
|
|
344
364
|
get template() {
|
|
345
|
-
return this.#
|
|
365
|
+
return this.#core.uriTemplate;
|
|
346
366
|
}
|
|
347
367
|
get pattern() {
|
|
348
|
-
return this.#
|
|
368
|
+
return this.#core.path.pattern;
|
|
349
369
|
}
|
|
350
370
|
get path() {
|
|
351
|
-
return this.#
|
|
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.#
|
|
377
|
+
return this.#core.scope;
|
|
358
378
|
}
|
|
359
379
|
get registry() {
|
|
360
|
-
return this.#
|
|
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.#
|
|
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.#
|
|
417
|
+
return FinalizedAction.fromHandlers(null, this.#spec, this.#core, arg1, arg2);
|
|
398
418
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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
|
-
|
|
406
|
-
|
|
431
|
+
invalidateCache(refs) {
|
|
432
|
+
refs.spec = this.#spec;
|
|
433
|
+
return this.#core.refreshCache(refs);
|
|
407
434
|
}
|
|
408
435
|
}
|
|
409
436
|
export class PreAction {
|
|
410
|
-
#
|
|
411
|
-
constructor(
|
|
412
|
-
this.#
|
|
437
|
+
#core;
|
|
438
|
+
constructor(core) {
|
|
439
|
+
this.#core = core;
|
|
413
440
|
}
|
|
414
441
|
use() {
|
|
415
|
-
return new Action(this.#
|
|
442
|
+
return new Action(this.#core);
|
|
416
443
|
}
|
|
417
444
|
define(args) {
|
|
418
|
-
return new DefinedAction(args.typeDef, args.spec, this.#
|
|
445
|
+
return new DefinedAction(args.typeDef, args.spec, this.#core);
|
|
419
446
|
}
|
|
420
447
|
handle(arg1, arg2) {
|
|
421
|
-
return FinalizedAction.fromHandlers(null, {}, this.#
|
|
448
|
+
return FinalizedAction.fromHandlers(null, {}, this.#core, arg1, arg2);
|
|
422
449
|
}
|
|
423
450
|
}
|
|
424
451
|
export class Endpoint {
|
|
425
|
-
#
|
|
426
|
-
constructor(
|
|
427
|
-
this.#
|
|
452
|
+
#core;
|
|
453
|
+
constructor(core) {
|
|
454
|
+
this.#core = core;
|
|
428
455
|
}
|
|
429
456
|
hint(hints) {
|
|
430
|
-
this.#
|
|
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.#
|
|
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.#
|
|
471
|
+
return new Action(this.#core);
|
|
445
472
|
}
|
|
446
473
|
define(args) {
|
|
447
|
-
return new DefinedAction(args.typeDef, args.spec, this.#
|
|
474
|
+
return new DefinedAction(args.typeDef, args.spec, this.#core);
|
|
448
475
|
}
|
|
449
476
|
handle(arg1, arg2) {
|
|
450
|
-
return FinalizedAction.fromHandlers(undefined, {}, this.#
|
|
477
|
+
return FinalizedAction.fromHandlers(undefined, {}, this.#core, arg1, arg2);
|
|
451
478
|
}
|
|
452
479
|
}
|
|
453
480
|
export class ActionAuth {
|
|
454
|
-
#
|
|
455
|
-
constructor(
|
|
456
|
-
this.#
|
|
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.#
|
|
462
|
-
this.#
|
|
463
|
-
return new Endpoint(this.#
|
|
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.#
|
|
469
|
-
return new Endpoint(this.#
|
|
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
|
|
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
|
-
|
|
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;
|