@occultist/occultist 0.0.4 → 0.0.6
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/accept.js +0 -1
- package/dist/actions/actionSets.d.ts +3 -3
- package/dist/actions/actions.d.ts +69 -48
- package/dist/actions/actions.js +39 -4
- package/dist/actions/context.d.ts +15 -11
- package/dist/actions/context.js +5 -0
- package/dist/actions/meta.d.ts +18 -12
- package/dist/actions/meta.js +114 -38
- package/dist/actions/spec.d.ts +3 -3
- package/dist/actions/types.d.ts +45 -16
- package/dist/actions/writer.d.ts +1 -1
- package/dist/actions/writer.test.js +2 -2
- package/dist/cache/cache.d.ts +3 -3
- package/dist/cache/cache.js +111 -42
- package/dist/cache/etag.test.js +1 -1
- package/dist/cache/file.d.ts +33 -1
- package/dist/cache/file.js +92 -10
- package/dist/cache/memory.d.ts +12 -2
- package/dist/cache/memory.js +63 -1
- package/dist/cache/types.d.ts +51 -22
- package/dist/errors.d.ts +1 -1
- package/dist/jsonld.d.ts +1 -1
- package/dist/makeTypeDefs.d.ts +2 -2
- package/dist/mod.d.ts +17 -15
- package/dist/mod.js +17 -15
- package/dist/processAction.d.ts +2 -2
- package/dist/processAction.js +1 -1
- package/dist/registry.d.ts +74 -8
- package/dist/registry.js +70 -8
- package/dist/registry.test.js +1 -1
- package/dist/scopes.d.ts +8 -8
- package/dist/scopes.js +8 -5
- package/dist/utils/contextBuilder.d.ts +1 -1
- package/dist/utils/getActionContext.d.ts +2 -2
- package/dist/utils/getPropertyValueSpecifications.d.ts +1 -1
- package/dist/utils/getRequestBodyValues.d.ts +3 -3
- package/dist/utils/getRequestIRIValues.d.ts +2 -2
- package/dist/utils/isPopulatedObject.js +1 -1
- package/dist/utils/makeAppendProblemDetails.d.ts +1 -1
- package/dist/utils/makeURLPattern.js +1 -0
- package/dist/utils/parseSearchParams.d.ts +2 -2
- package/dist/validators.d.ts +2 -2
- package/dist/validators.js +2 -2
- package/lib/accept.test.ts +1 -1
- package/lib/accept.ts +0 -2
- package/lib/actions/actionSets.ts +4 -4
- package/lib/actions/actions.ts +159 -99
- package/lib/actions/context.ts +22 -10
- package/lib/actions/meta.ts +140 -55
- package/lib/actions/path.test.ts +1 -1
- package/lib/actions/path.ts +1 -1
- package/lib/actions/spec.ts +3 -3
- package/lib/actions/types.ts +60 -15
- package/lib/actions/writer.test.ts +2 -2
- package/lib/actions/writer.ts +1 -1
- package/lib/cache/cache.ts +138 -52
- package/lib/cache/etag.test.ts +1 -1
- package/lib/cache/file.ts +113 -12
- package/lib/cache/memory.ts +85 -3
- package/lib/cache/types.ts +70 -23
- package/lib/errors.ts +1 -1
- package/lib/jsonld.ts +1 -1
- package/lib/makeTypeDefs.ts +5 -5
- package/lib/mod.ts +17 -15
- package/lib/processAction.ts +14 -14
- package/lib/registry.test.ts +1 -1
- package/lib/registry.ts +96 -19
- package/lib/request.ts +1 -1
- package/lib/scopes.test.ts +2 -2
- package/lib/scopes.ts +14 -11
- package/lib/utils/contextBuilder.ts +3 -3
- package/lib/utils/getActionContext.ts +4 -4
- package/lib/utils/getInternalName.ts +1 -1
- package/lib/utils/getPropertyValueSpecifications.ts +4 -4
- package/lib/utils/getRequestBodyValues.ts +5 -5
- package/lib/utils/getRequestIRIValues.ts +4 -4
- package/lib/utils/isPopulatedObject.ts +1 -1
- package/lib/utils/makeAppendProblemDetails.ts +1 -1
- package/lib/utils/makeURLPattern.ts +1 -0
- package/lib/utils/parseSearchParams.ts +2 -2
- package/lib/validators.ts +5 -5
- package/package.json +4 -2
package/dist/cache/file.d.ts
CHANGED
|
@@ -1,14 +1,46 @@
|
|
|
1
|
-
import type { CacheDetails, CacheHitHandle, CacheMeta, CacheStorage, CacheMissHandle } from './types.
|
|
1
|
+
import type { CacheDetails, CacheHitHandle, CacheMeta, CacheStorage, CacheMissHandle, UpstreamCache } from './types.ts';
|
|
2
|
+
import { Registry } from '../registry.ts';
|
|
3
|
+
import { Cache } from './cache.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Stores cache meta information in a file on the filesystem.
|
|
6
|
+
*
|
|
7
|
+
* This is not robust enough for multi-process use.
|
|
8
|
+
*/
|
|
2
9
|
export declare class FileCacheMeta implements CacheMeta {
|
|
3
10
|
#private;
|
|
4
11
|
constructor(filePath: string);
|
|
5
12
|
get(key: string): Promise<CacheHitHandle | CacheMissHandle>;
|
|
13
|
+
/**
|
|
14
|
+
* Sets a cached value.
|
|
15
|
+
*
|
|
16
|
+
* @param key Unique key for this cached value.
|
|
17
|
+
* @param details Details of the cache to store.
|
|
18
|
+
*/
|
|
6
19
|
set(key: string, details: CacheDetails): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Invalidates a cached value by key.
|
|
22
|
+
*
|
|
23
|
+
* @param key Unique key for this cached value.
|
|
24
|
+
*/
|
|
25
|
+
invalidate(key: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Flushes the entire cache of values.
|
|
28
|
+
*
|
|
29
|
+
* @param key Unique key for this cached value.
|
|
30
|
+
*/
|
|
31
|
+
flush(): Promise<void>;
|
|
7
32
|
}
|
|
8
33
|
export declare class FileSystemCacheStorage implements CacheStorage {
|
|
9
34
|
#private;
|
|
35
|
+
constructor(directory: string);
|
|
10
36
|
hash(key: string): string;
|
|
11
37
|
get(key: string): Promise<Blob>;
|
|
12
38
|
set(key: string, value: Blob): Promise<void>;
|
|
13
39
|
invalidate(key: string): Promise<void>;
|
|
40
|
+
flush(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export declare class FileSystemCache extends Cache {
|
|
43
|
+
#private;
|
|
44
|
+
constructor(registry: Registry, filePath: string, directory: string, upstream?: UpstreamCache);
|
|
45
|
+
flush(): Promise<[void, void]>;
|
|
14
46
|
}
|
package/dist/cache/file.js
CHANGED
|
@@ -1,22 +1,40 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { readFile, writeFile, rm } from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
+
import { watchFile } from 'node:fs';
|
|
5
|
+
import { Cache } from "./cache.js";
|
|
6
|
+
/**
|
|
7
|
+
* Stores cache meta information in a file on the filesystem.
|
|
8
|
+
*
|
|
9
|
+
* This is not robust enough for multi-process use.
|
|
10
|
+
*/
|
|
4
11
|
export class FileCacheMeta {
|
|
5
12
|
#filePath;
|
|
6
|
-
#handle;
|
|
7
13
|
#details = {};
|
|
14
|
+
#watcher;
|
|
15
|
+
#writing = false;
|
|
8
16
|
constructor(filePath) {
|
|
9
17
|
this.#filePath = filePath;
|
|
10
18
|
}
|
|
11
19
|
async #init() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
try {
|
|
21
|
+
const content = await readFile(this.#filePath, 'utf-8');
|
|
22
|
+
this.#details = JSON.parse(content);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
await writeFile(this.#filePath, JSON.stringify(this.#details));
|
|
26
|
+
}
|
|
27
|
+
this.#watcher = watchFile(this.#filePath, async () => {
|
|
28
|
+
if (this.#writing)
|
|
29
|
+
return;
|
|
30
|
+
const content = await readFile(this.#filePath, 'utf-8');
|
|
31
|
+
this.#details = JSON.parse(content);
|
|
32
|
+
});
|
|
33
|
+
this.#watcher.unref();
|
|
15
34
|
}
|
|
16
35
|
async get(key) {
|
|
17
|
-
if (this.#
|
|
18
|
-
this.#init();
|
|
19
|
-
}
|
|
36
|
+
if (this.#watcher == null)
|
|
37
|
+
await this.#init();
|
|
20
38
|
const details = this.#details[key];
|
|
21
39
|
async function set(details) {
|
|
22
40
|
this.#details.set(key, details);
|
|
@@ -33,19 +51,58 @@ export class FileCacheMeta {
|
|
|
33
51
|
set,
|
|
34
52
|
};
|
|
35
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Sets a cached value.
|
|
56
|
+
*
|
|
57
|
+
* @param key Unique key for this cached value.
|
|
58
|
+
* @param details Details of the cache to store.
|
|
59
|
+
*/
|
|
36
60
|
async set(key, details) {
|
|
61
|
+
if (this.#watcher == null)
|
|
62
|
+
await this.#init();
|
|
37
63
|
this.#details[key] = details;
|
|
38
|
-
this.#
|
|
64
|
+
await this.#write();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Invalidates a cached value by key.
|
|
68
|
+
*
|
|
69
|
+
* @param key Unique key for this cached value.
|
|
70
|
+
*/
|
|
71
|
+
async invalidate(key) {
|
|
72
|
+
if (this.#watcher == null)
|
|
73
|
+
await this.#init();
|
|
74
|
+
delete this.#details[key];
|
|
75
|
+
await this.#write();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Flushes the entire cache of values.
|
|
79
|
+
*
|
|
80
|
+
* @param key Unique key for this cached value.
|
|
81
|
+
*/
|
|
82
|
+
async flush() {
|
|
83
|
+
this.#details = {};
|
|
84
|
+
await this.#write();
|
|
85
|
+
}
|
|
86
|
+
async #write() {
|
|
87
|
+
this.#writing = true;
|
|
88
|
+
try {
|
|
89
|
+
await writeFile(this.#filePath, JSON.stringify(this.#details));
|
|
90
|
+
}
|
|
91
|
+
catch { }
|
|
92
|
+
this.#writing = false;
|
|
39
93
|
}
|
|
40
94
|
}
|
|
41
95
|
export class FileSystemCacheStorage {
|
|
42
96
|
#directory;
|
|
43
97
|
#hashes = new Map();
|
|
98
|
+
constructor(directory) {
|
|
99
|
+
this.#directory = directory;
|
|
100
|
+
}
|
|
44
101
|
hash(key) {
|
|
45
102
|
let hash = this.#hashes.get(key);
|
|
46
103
|
if (hash != null)
|
|
47
104
|
return hash;
|
|
48
|
-
hash = createHash('
|
|
105
|
+
hash = createHash('sha256').update(key).digest('hex');
|
|
49
106
|
this.#hashes.set(key, hash);
|
|
50
107
|
return hash;
|
|
51
108
|
}
|
|
@@ -59,4 +116,29 @@ export class FileSystemCacheStorage {
|
|
|
59
116
|
async invalidate(key) {
|
|
60
117
|
await rm(join(this.#directory, this.hash(key)));
|
|
61
118
|
}
|
|
119
|
+
async flush() {
|
|
120
|
+
const promises = [];
|
|
121
|
+
for (const hash of this.#hashes.values()) {
|
|
122
|
+
promises.push(rm(join(this.#directory, hash)));
|
|
123
|
+
}
|
|
124
|
+
this.#hashes = new Map();
|
|
125
|
+
await Promise.all(promises);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export class FileSystemCache extends Cache {
|
|
129
|
+
#fileMeta;
|
|
130
|
+
#fileSystemStorage;
|
|
131
|
+
constructor(registry, filePath, directory, upstream) {
|
|
132
|
+
const meta = new FileCacheMeta(filePath);
|
|
133
|
+
const storage = new FileSystemCacheStorage(directory);
|
|
134
|
+
super(registry, meta, storage, upstream);
|
|
135
|
+
this.#fileMeta = meta;
|
|
136
|
+
this.#fileSystemStorage = storage;
|
|
137
|
+
}
|
|
138
|
+
async flush() {
|
|
139
|
+
return Promise.all([
|
|
140
|
+
this.#fileMeta.flush(),
|
|
141
|
+
this.#fileSystemStorage.flush(),
|
|
142
|
+
]);
|
|
143
|
+
}
|
|
62
144
|
}
|
package/dist/cache/memory.d.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Registry } from '../registry.ts';
|
|
2
|
+
import type { CacheDetails, CacheHitHandle, CacheMeta, CacheStorage, CacheMissHandle, UpstreamCache, LockedCacheMissHandle } from './types.ts';
|
|
3
|
+
import { Cache } from './cache.ts';
|
|
2
4
|
export declare class InMemoryCacheMeta implements CacheMeta {
|
|
3
5
|
#private;
|
|
4
6
|
get(key: string): Promise<CacheHitHandle | CacheMissHandle>;
|
|
5
|
-
set(key: string, details: CacheDetails):
|
|
7
|
+
set(key: string, details: CacheDetails): void;
|
|
8
|
+
getOrLock(key: string): Promise<CacheHitHandle | LockedCacheMissHandle>;
|
|
9
|
+
invalidate(key: string): void;
|
|
10
|
+
flush(): Promise<void>;
|
|
6
11
|
}
|
|
7
12
|
export declare class InMemoryCacheStorage implements CacheStorage {
|
|
8
13
|
#private;
|
|
9
14
|
get(key: string): Blob;
|
|
10
15
|
set(key: string, value: Blob): void;
|
|
11
16
|
invalidate(key: string): void;
|
|
17
|
+
flush(): void;
|
|
18
|
+
}
|
|
19
|
+
export declare class InMemoryCache extends Cache {
|
|
20
|
+
constructor(registry: Registry, upstream?: UpstreamCache);
|
|
21
|
+
flush(): Promise<void>;
|
|
12
22
|
}
|
package/dist/cache/memory.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import { Cache } from "./cache.js";
|
|
1
2
|
export class InMemoryCacheMeta {
|
|
2
3
|
#details = new Map();
|
|
4
|
+
#locks = new Map();
|
|
5
|
+
#flushLock;
|
|
3
6
|
async get(key) {
|
|
7
|
+
if (this.#flushLock) {
|
|
8
|
+
await this.#flushLock;
|
|
9
|
+
}
|
|
4
10
|
const details = this.#details.get(key);
|
|
5
11
|
async function set(details) {
|
|
6
12
|
this.#details.set(key, details);
|
|
@@ -17,9 +23,53 @@ export class InMemoryCacheMeta {
|
|
|
17
23
|
set,
|
|
18
24
|
};
|
|
19
25
|
}
|
|
20
|
-
|
|
26
|
+
set(key, details) {
|
|
21
27
|
this.#details.set(key, details);
|
|
22
28
|
}
|
|
29
|
+
async getOrLock(key) {
|
|
30
|
+
if (this.#flushLock) {
|
|
31
|
+
await this.#flushLock;
|
|
32
|
+
}
|
|
33
|
+
const lock = this.#locks.get(key);
|
|
34
|
+
if (lock != null) {
|
|
35
|
+
await lock;
|
|
36
|
+
}
|
|
37
|
+
const details = this.#details.get(key);
|
|
38
|
+
const { resolve, promise } = Promise.withResolvers();
|
|
39
|
+
this.#locks.set(key, promise);
|
|
40
|
+
function set(details) {
|
|
41
|
+
this.#details.set(key, details);
|
|
42
|
+
}
|
|
43
|
+
const release = () => {
|
|
44
|
+
resolve();
|
|
45
|
+
this.#locks.delete(key);
|
|
46
|
+
};
|
|
47
|
+
if (details == null) {
|
|
48
|
+
return {
|
|
49
|
+
type: 'locked-cache-miss',
|
|
50
|
+
set,
|
|
51
|
+
release,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
...details,
|
|
56
|
+
type: 'cache-hit',
|
|
57
|
+
set,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
invalidate(key) {
|
|
61
|
+
this.#details.delete(key);
|
|
62
|
+
}
|
|
63
|
+
async flush() {
|
|
64
|
+
const { resolve, promise } = Promise.withResolvers();
|
|
65
|
+
this.#flushLock = promise;
|
|
66
|
+
// there could be a race condition here where the values are
|
|
67
|
+
// flused before queued requests can get them.
|
|
68
|
+
await Promise.all(this.#locks.values());
|
|
69
|
+
this.#details = new Map();
|
|
70
|
+
this.#locks = new Map();
|
|
71
|
+
resolve();
|
|
72
|
+
}
|
|
23
73
|
}
|
|
24
74
|
export class InMemoryCacheStorage {
|
|
25
75
|
#cache = new Map();
|
|
@@ -33,4 +83,16 @@ export class InMemoryCacheStorage {
|
|
|
33
83
|
invalidate(key) {
|
|
34
84
|
this.#cache.delete(key);
|
|
35
85
|
}
|
|
86
|
+
flush() {
|
|
87
|
+
this.#cache = new Map();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export class InMemoryCache extends Cache {
|
|
91
|
+
constructor(registry, upstream) {
|
|
92
|
+
super(registry, new InMemoryCacheMeta(), new InMemoryCacheStorage(), upstream);
|
|
93
|
+
}
|
|
94
|
+
async flush() {
|
|
95
|
+
await this.meta.flush();
|
|
96
|
+
this.storage.flush();
|
|
97
|
+
}
|
|
36
98
|
}
|
package/dist/cache/types.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { ImplementedAction } from "../actions/types.
|
|
2
|
-
import { CacheContext } from "../mod.
|
|
1
|
+
import type { AuthState, ImplementedAction } from "../actions/types.ts";
|
|
2
|
+
import type { CacheContext } from "../mod.ts";
|
|
3
3
|
export type CacheStrategyType = 'http' | 'etag' | 'store';
|
|
4
|
+
export type CacheSemantics = 'options' | 'head' | 'get' | 'post' | 'put' | 'delete' | 'query';
|
|
4
5
|
export interface CacheEntryDescriptor {
|
|
5
6
|
contentType: string;
|
|
7
|
+
semantics: CacheSemantics;
|
|
6
8
|
action: ImplementedAction;
|
|
7
9
|
request: Request;
|
|
8
10
|
args: CacheInstanceArgs;
|
|
9
11
|
}
|
|
10
|
-
export type CacheWhenFn = (ctx: CacheContext) => boolean;
|
|
12
|
+
export type CacheWhenFn<Auth extends AuthState = AuthState> = (ctx: CacheContext<Auth>) => boolean;
|
|
11
13
|
export type CacheRuleArgs = {
|
|
12
14
|
/**
|
|
13
15
|
* A version which should increment every when a new release
|
|
@@ -22,6 +24,10 @@ export type CacheRuleArgs = {
|
|
|
22
24
|
vary?: string;
|
|
23
25
|
varyOnAuth?: boolean;
|
|
24
26
|
varyOnCapabilities?: string | string[];
|
|
27
|
+
/**
|
|
28
|
+
* Overrides the semantics of the cache.
|
|
29
|
+
*/
|
|
30
|
+
semantics?: CacheSemantics;
|
|
25
31
|
/**
|
|
26
32
|
* Defaults to false when a querystring is present
|
|
27
33
|
* or the request is authenticated.
|
|
@@ -32,7 +38,7 @@ export type CacheRuleArgs = {
|
|
|
32
38
|
};
|
|
33
39
|
export type CacheControlArgs = {
|
|
34
40
|
private?: boolean;
|
|
35
|
-
|
|
41
|
+
publicWhenAuthenticated?: true;
|
|
36
42
|
noCache?: true;
|
|
37
43
|
noStore?: true;
|
|
38
44
|
mustRevalidate?: true;
|
|
@@ -45,7 +51,6 @@ export type CacheControlArgs = {
|
|
|
45
51
|
etag?: string;
|
|
46
52
|
};
|
|
47
53
|
export type CacheHTTPArgs = {
|
|
48
|
-
strategy: 'http';
|
|
49
54
|
strong?: undefined;
|
|
50
55
|
fromRequest?: undefined;
|
|
51
56
|
} & CacheRuleArgs & CacheControlArgs;
|
|
@@ -54,17 +59,15 @@ export type CacheHTTPInstanceArgs = CacheHTTPArgs & {
|
|
|
54
59
|
cache: CacheBuilder;
|
|
55
60
|
};
|
|
56
61
|
export type CacheETagArgs = {
|
|
57
|
-
strategy: 'etag';
|
|
58
62
|
strong?: boolean;
|
|
59
63
|
fromRequest?: boolean;
|
|
60
64
|
etag?: undefined;
|
|
61
65
|
} & CacheRuleArgs & Omit<CacheControlArgs, 'etag'>;
|
|
62
66
|
export type CacheETagInstanceArgs = CacheETagArgs & {
|
|
63
|
-
|
|
67
|
+
strategy: 'etag';
|
|
64
68
|
cache: CacheBuilder;
|
|
65
69
|
};
|
|
66
70
|
export type CacheStoreArgs = {
|
|
67
|
-
strategy: 'store';
|
|
68
71
|
strong?: boolean;
|
|
69
72
|
fromRequest?: boolean;
|
|
70
73
|
etag?: undefined;
|
|
@@ -81,7 +84,7 @@ export type CacheDetails = {
|
|
|
81
84
|
hasContent: boolean;
|
|
82
85
|
authKey: string;
|
|
83
86
|
etag: string;
|
|
84
|
-
headers:
|
|
87
|
+
headers: Record<string, string | string[]>;
|
|
85
88
|
contentType: string;
|
|
86
89
|
contentLength?: number;
|
|
87
90
|
contentEncoding?: string;
|
|
@@ -90,16 +93,16 @@ export type CacheDetails = {
|
|
|
90
93
|
};
|
|
91
94
|
export type CacheHitHandle = CacheDetails & {
|
|
92
95
|
type: 'cache-hit';
|
|
93
|
-
set(details: CacheDetails): Promise<void>;
|
|
96
|
+
set(details: CacheDetails): void | Promise<void>;
|
|
94
97
|
};
|
|
95
98
|
export type CacheMissHandle = {
|
|
96
99
|
type: 'cache-miss';
|
|
97
|
-
set(details: CacheDetails): Promise<void>;
|
|
100
|
+
set(details: CacheDetails): void | Promise<void>;
|
|
98
101
|
};
|
|
99
102
|
export type LockedCacheMissHandle = {
|
|
100
103
|
type: 'locked-cache-miss';
|
|
101
|
-
set(details: CacheDetails): Promise<void>;
|
|
102
|
-
release(): Promise<void>;
|
|
104
|
+
set(details: CacheDetails): void | Promise<void>;
|
|
105
|
+
release(): void | Promise<void>;
|
|
103
106
|
};
|
|
104
107
|
/**
|
|
105
108
|
* The cache meta knows how to query a storage for current freshness
|
|
@@ -114,26 +117,45 @@ export interface CacheMeta {
|
|
|
114
117
|
/**
|
|
115
118
|
* Sets the cache details for a representation.
|
|
116
119
|
*
|
|
117
|
-
* @param key
|
|
118
|
-
* @param details
|
|
120
|
+
* @param key Unique key for this cached value.
|
|
121
|
+
* @param details Details of the cache to store.
|
|
119
122
|
*/
|
|
120
123
|
set(key: string, details: CacheDetails): void | Promise<void>;
|
|
121
124
|
/**
|
|
122
125
|
* Retrieves the cache details of a representation.
|
|
123
126
|
*
|
|
124
|
-
* @param key
|
|
127
|
+
* @param key Unique key for this cached value.
|
|
125
128
|
*/
|
|
126
129
|
get(key: string): CacheHitHandle | CacheMissHandle | Promise<CacheHitHandle | CacheMissHandle>;
|
|
127
130
|
/**
|
|
128
131
|
* Retrieves the cache details of a representation and takes a lock
|
|
129
|
-
* for update if the representation is not current.
|
|
132
|
+
* for update if the representation is not current. All concurrent requests
|
|
133
|
+
* targeting the same cached value will wait for the cache to be populated
|
|
134
|
+
* and respond from cache. This can occur across processes if the locking
|
|
135
|
+
* mechanism allows for it.
|
|
136
|
+
*
|
|
137
|
+
* This is an experimental API and its benifits are untested. APIs that
|
|
138
|
+
* have a high failure rate could see degredation in services as requests
|
|
139
|
+
* will queue to take the lock, but fail to set a new cache value causing
|
|
140
|
+
* the queued requests to continue locking.
|
|
130
141
|
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
142
|
+
* However, this could help protect downstream services from thundering herd
|
|
143
|
+
* like scenarios as only one requester will build the representation that all
|
|
144
|
+
* requesters use.
|
|
133
145
|
*
|
|
134
|
-
* @param key
|
|
146
|
+
* @param key Unique key for this cached value.
|
|
135
147
|
*/
|
|
136
148
|
getOrLock?(key: string): Promise<CacheHitHandle | LockedCacheMissHandle>;
|
|
149
|
+
/**
|
|
150
|
+
* Invalidates a cached value by key.
|
|
151
|
+
*
|
|
152
|
+
* @param key Unique key for this cached value.
|
|
153
|
+
*/
|
|
154
|
+
invalidate(key: string): void | Promise<void>;
|
|
155
|
+
/**
|
|
156
|
+
* Flushes the entire cache of values.
|
|
157
|
+
*/
|
|
158
|
+
flush(): void | Promise<void>;
|
|
137
159
|
}
|
|
138
160
|
export interface UpstreamCache {
|
|
139
161
|
/**
|
|
@@ -159,9 +181,13 @@ export interface CacheStorage {
|
|
|
159
181
|
*/
|
|
160
182
|
set(key: string, data: Blob): void | Promise<void>;
|
|
161
183
|
/**
|
|
162
|
-
*
|
|
184
|
+
* Deletes a cache entry.
|
|
163
185
|
*/
|
|
164
186
|
invalidate(key: string): void | Promise<void>;
|
|
187
|
+
/**
|
|
188
|
+
* Flushes the entire cache of values.
|
|
189
|
+
*/
|
|
190
|
+
flush(): void | Promise<void>;
|
|
165
191
|
}
|
|
166
192
|
export interface CacheBuilder {
|
|
167
193
|
meta: CacheMeta;
|
|
@@ -170,6 +196,9 @@ export interface CacheBuilder {
|
|
|
170
196
|
http(args?: CacheHTTPArgs): CacheInstanceArgs;
|
|
171
197
|
etag(args?: CacheETagArgs): CacheInstanceArgs;
|
|
172
198
|
store(args?: CacheStoreArgs): CacheInstanceArgs;
|
|
173
|
-
|
|
199
|
+
/**
|
|
200
|
+
* Removes an item from the cache.
|
|
201
|
+
*/
|
|
202
|
+
invalidate(key: string, url: string): void | Promise<void>;
|
|
174
203
|
push?(request: Request): Promise<void>;
|
|
175
204
|
}
|
package/dist/errors.d.ts
CHANGED
package/dist/jsonld.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ShallowMerge } from "./merge.
|
|
1
|
+
import type { ShallowMerge } from "./merge.ts";
|
|
2
2
|
export type RecursiveDigit = 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
3
3
|
export type RecursiveNextDigit = [1, 2, 3, 4, 5, 6, 7, 'STOP'];
|
|
4
4
|
export type RecursiveIncrement<T> = T extends RecursiveDigit ? RecursiveNextDigit[T] : 'STOP';
|
package/dist/makeTypeDefs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ContextDefinitionContainer, TypeDef } from "./jsonld.
|
|
2
|
-
import type { Context } from "./actions/context.
|
|
1
|
+
import type { ContextDefinitionContainer, TypeDef } from "./jsonld.ts";
|
|
2
|
+
import type { Context } from "./actions/context.ts";
|
|
3
3
|
export type MakeTypeDefArgsFromType<Term extends string, Type extends string> = {
|
|
4
4
|
term: Term;
|
|
5
5
|
type: Type;
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
export * from './cache/types.
|
|
2
|
-
export * from './cache/cache.
|
|
3
|
-
export * from './cache/memory.
|
|
4
|
-
export * from './cache/file.
|
|
5
|
-
export * from './actions/types.
|
|
6
|
-
export * from './actions/meta.
|
|
7
|
-
export * from './actions/spec.
|
|
8
|
-
export * from './actions/context.
|
|
9
|
-
export * from './actions/path.
|
|
10
|
-
export * from './actions/actions.
|
|
11
|
-
export * from './actions/actionSets.
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
1
|
+
export * from './cache/types.ts';
|
|
2
|
+
export * from './cache/cache.ts';
|
|
3
|
+
export * from './cache/memory.ts';
|
|
4
|
+
export * from './cache/file.ts';
|
|
5
|
+
export * from './actions/types.ts';
|
|
6
|
+
export * from './actions/meta.ts';
|
|
7
|
+
export * from './actions/spec.ts';
|
|
8
|
+
export * from './actions/context.ts';
|
|
9
|
+
export * from './actions/path.ts';
|
|
10
|
+
export * from './actions/actions.ts';
|
|
11
|
+
export * from './actions/actionSets.ts';
|
|
12
|
+
export * from './request.ts';
|
|
13
|
+
export * from './actions/writer.ts';
|
|
14
|
+
export * from './registry.ts';
|
|
15
|
+
export * from './makeTypeDefs.ts';
|
|
16
|
+
export * from './utils/joinPaths.ts';
|
|
17
|
+
export * from './utils/contextBuilder.ts';
|
package/dist/mod.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
1
|
+
export * from "./cache/types.js";
|
|
2
|
+
export * from "./cache/cache.js";
|
|
3
|
+
export * from "./cache/memory.js";
|
|
4
|
+
export * from "./cache/file.js";
|
|
5
|
+
export * from "./actions/types.js";
|
|
6
|
+
export * from "./actions/meta.js";
|
|
7
|
+
export * from "./actions/spec.js";
|
|
8
|
+
export * from "./actions/context.js";
|
|
9
|
+
export * from "./actions/path.js";
|
|
10
|
+
export * from "./actions/actions.js";
|
|
11
|
+
export * from "./actions/actionSets.js";
|
|
12
|
+
export * from "./request.js";
|
|
13
|
+
export * from "./actions/writer.js";
|
|
14
|
+
export * from "./registry.js";
|
|
15
|
+
export * from "./makeTypeDefs.js";
|
|
16
|
+
export * from "./utils/joinPaths.js";
|
|
17
|
+
export * from "./utils/contextBuilder.js";
|
package/dist/processAction.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ImplementedAction } from "./actions/types.
|
|
2
|
-
import type { ActionPayload, ActionSpec, ContextState, ParsedIRIValues } from "./actions/spec.
|
|
1
|
+
import type { ImplementedAction } from "./actions/types.ts";
|
|
2
|
+
import type { ActionPayload, ActionSpec, ContextState, ParsedIRIValues } from "./actions/spec.ts";
|
|
3
3
|
export type ProcessActionArgs<State extends ContextState = ContextState, Spec extends ActionSpec<ContextState> = ActionSpec<ContextState>> = {
|
|
4
4
|
iri: string;
|
|
5
5
|
req: Request;
|
package/dist/processAction.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonPointer } from
|
|
1
|
+
import { JsonPointer } from "json-ptr";
|
|
2
2
|
import { getInternalName } from "./utils/getInternalName.js";
|
|
3
3
|
import { getRequestBodyValues } from "./utils/getRequestBodyValues.js";
|
|
4
4
|
import { getRequestIRIValues } from "./utils/getRequestIRIValues.js";
|