@owlmeans/test-auth 0.1.18-rc.1 → 0.1.18-rc.11
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/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/testing-auth-unit/SKILL.md +11 -2
- package/build/envelope.d.ts.map +1 -1
- package/build/envelope.js.map +1 -1
- package/build/guard.d.ts.map +1 -1
- package/build/guard.js.map +1 -1
- package/build/keys.d.ts.map +1 -1
- package/build/trusted.d.ts +4 -0
- package/build/trusted.d.ts.map +1 -1
- package/build/trusted.js +27 -10
- package/build/trusted.js.map +1 -1
- package/package.json +10 -10
- package/src/trusted.ts +38 -15
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/test-auth",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.18-rc.11",
|
|
5
|
+
"generatedAt": "2026-09-01T16:28:56.982Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -25,12 +25,12 @@ For background on the protocol you're mocking, read the `auth-protocol` skill.
|
|
|
25
25
|
## `tests/context.ts` pattern
|
|
26
26
|
|
|
27
27
|
```ts
|
|
28
|
-
import { AppType,
|
|
28
|
+
import { AppType, makeBasicContext } from '@owlmeans/context'
|
|
29
29
|
import { makeMemoryTrustedResource, withAuth, USER } from '@owlmeans/test-auth'
|
|
30
30
|
|
|
31
31
|
export const makeTestCtx = () => {
|
|
32
32
|
const ctx = makeBasicContext({
|
|
33
|
-
ready: false, service: '<pkg>-tests',
|
|
33
|
+
ready: false, service: '<pkg>-tests', type: AppType.Backend, services: {},
|
|
34
34
|
})
|
|
35
35
|
ctx.registerResource(makeMemoryTrustedResource([
|
|
36
36
|
{ id: 'svc', name: 'svc', credential: '<fixture-pubkey>' },
|
|
@@ -40,6 +40,15 @@ export const makeTestCtx = () => {
|
|
|
40
40
|
}
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
One factory, one context: the trusted resource and the mock guard are registered inside it, in the
|
|
44
|
+
order a real app's `makeContext` would.
|
|
45
|
+
|
|
46
|
+
`makeMemoryTrustedResource` implements only `load`, `save` and `create` — enough for the `trust()`
|
|
47
|
+
boundary and for seeding from a spec; every other resource method throws. A read takes an id or a
|
|
48
|
+
single-field criteria over `id` or `name`, and anything wider is refused with
|
|
49
|
+
`UnsupportedArgumentError` rather than scanned: a query the mock cannot answer exactly is a test
|
|
50
|
+
reaching past its seam, and the honest fix is integration coverage.
|
|
51
|
+
|
|
43
52
|
The trusted resource, mock guard, and any fixture keys are the **only** mocks allowed. Everything else (the service under test, sibling packages it depends on) is the real thing.
|
|
44
53
|
|
|
45
54
|
## Spec shape
|
package/build/envelope.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAqB,MAAM,0BAA0B,CAAA;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAK1C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAU,CAAC,SAAS,EAAE,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAqB,MAAM,0BAA0B,CAAA;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAK1C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAU,CAAC,SAAS,EAAE,GAAG,MAAM,EAC1D,KAAK,CAAC,EACN,MAAM,MAAM,EACZ,OAAM,YAAiC,EACvC,KAAI,YAAsD,KACzD,OAAO,CAAC,MAAM,CAKhB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,GACrB,MAAM,IAAI,EACV,KAAK,YAAY,KAChB,OAAO,CAAC,MAAM,CAQhB,CAAA"}
|
package/build/envelope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAE1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAE9C,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,WAAW,EAAE,CAAA;AAE5E;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EACnC,GAAM,EACN,IAAY,EACZ,
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAE1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAE9C,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,WAAW,EAAE,CAAA;AAE5E;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EACnC,GAAM,EACN,IAAY,EACZ,OAAqB,YAAY,CAAC,KAAK,EACvC,KAAmB,kBAAkB,CAAC,mBAAmB,CAAC,EACzC,EAAE;IACnB,MAAM,QAAQ,GAAG,iBAAiB,CAAI,IAAI,CAAC,CAAA;IAC3C,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAClB,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;IAC5C,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAC7B,IAAU,EACV,EAAiB,EACA,EAAE;IACnB,MAAM,OAAO,GAAG,MAAM,gBAAgB,CACpC,IAA0C,EAC1C,iBAAiB,CAAC,iBAAiB,EACnC,YAAY,CAAC,KAAK,EAClB,EAAE,CACH,CAAA;IACD,OAAO,GAAG,kBAAkB,IAAI,OAAO,EAAE,CAAA;AAC3C,CAAC,CAAA"}
|
package/build/guard.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAElE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAE3F,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,iEAAiE;IACjE,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,iGAAiG;IACjG,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,CAAC,OAAO,CAAC,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5F,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAElE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAE3F,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,iEAAiE;IACjE,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,iGAAiG;IACjG,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,CAAC,OAAO,CAAC,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC5F,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,GAAI,OAAM,gBAAqB,KAAG,YAsB3D,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,EACvE,SAAS,CAAC,EACV,MAAM,IAAI,EACV,QAAO,MAAsB,KAC5B,CAGF,CAAA"}
|
package/build/guard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAcrD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAA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../src/keys.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAMxD;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAMxD;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,KAAG,YAMlD,CAAA"}
|
package/build/trusted.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ import type { Resource } from '@owlmeans/resource';
|
|
|
9
9
|
* `trust()` boundary plus straightforward seeding from tests. Other
|
|
10
10
|
* operations throw, so tests that need them have to be honest about
|
|
11
11
|
* adding integration coverage instead of leaning on the mock.
|
|
12
|
+
*
|
|
13
|
+
* A read takes an id or a single-field criteria over `id` or `name`. Anything
|
|
14
|
+
* wider is refused rather than scanned: the mock holds a handful of fixtures
|
|
15
|
+
* and a query it cannot answer exactly is a test reaching past its seam.
|
|
12
16
|
*/
|
|
13
17
|
export declare const makeMemoryTrustedResource: (records?: TrustedRecord[], alias?: string) => Resource<TrustedRecord>;
|
|
14
18
|
//# sourceMappingURL=trusted.d.ts.map
|
package/build/trusted.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trusted.d.ts","sourceRoot":"","sources":["../src/trusted.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"trusted.d.ts","sourceRoot":"","sources":["../src/trusted.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,KAAK,EAA0B,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAe1E;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yBAAyB,GACpC,UAAS,aAAa,EAAO,EAC7B,QAAO,MAA8B,KACpC,QAAQ,CAAC,aAAa,CAqExB,CAAA"}
|
package/build/trusted.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { appendContextual } from '@owlmeans/context';
|
|
2
|
+
import { UnsupportedArgumentError } from '@owlmeans/resource';
|
|
2
3
|
const TRUSTED_DEFAULT_ALIAS = 'TRUSTED';
|
|
4
|
+
/** The fields a `trust()` lookup keys on — the only index this map has. */
|
|
5
|
+
const SUPPORTED_FIELDS = ['id', 'name'];
|
|
3
6
|
const notImplemented = (op) => {
|
|
4
7
|
throw new Error(`@owlmeans/test-auth: in-memory TRUSTED resource does not implement ${op}()`);
|
|
5
8
|
};
|
|
@@ -13,6 +16,10 @@ const getter = (record, field) => record[field];
|
|
|
13
16
|
* `trust()` boundary plus straightforward seeding from tests. Other
|
|
14
17
|
* operations throw, so tests that need them have to be honest about
|
|
15
18
|
* adding integration coverage instead of leaning on the mock.
|
|
19
|
+
*
|
|
20
|
+
* A read takes an id or a single-field criteria over `id` or `name`. Anything
|
|
21
|
+
* wider is refused rather than scanned: the mock holds a handful of fixtures
|
|
22
|
+
* and a query it cannot answer exactly is a test reaching past its seam.
|
|
16
23
|
*/
|
|
17
24
|
export const makeMemoryTrustedResource = (records = [], alias = TRUSTED_DEFAULT_ALIAS) => {
|
|
18
25
|
const store = new Map();
|
|
@@ -29,16 +36,24 @@ export const makeMemoryTrustedResource = (records = [], alias = TRUSTED_DEFAULT_
|
|
|
29
36
|
}
|
|
30
37
|
return null;
|
|
31
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* @throws {UnsupportedArgumentError} on criteria naming anything but one supported field.
|
|
41
|
+
*/
|
|
42
|
+
const first = (idOrWhere) => {
|
|
43
|
+
if (typeof idOrWhere === 'string') {
|
|
44
|
+
return store.get(idOrWhere) ?? null;
|
|
45
|
+
}
|
|
46
|
+
const entries = Object.entries(idOrWhere).filter(([, value]) => value !== undefined);
|
|
47
|
+
const [entry, ...rest] = entries;
|
|
48
|
+
if (entry == null || rest.length > 0
|
|
49
|
+
|| !SUPPORTED_FIELDS.includes(entry[0]) || typeof entry[1] !== 'string') {
|
|
50
|
+
throw new UnsupportedArgumentError('test-auth:trusted:where');
|
|
51
|
+
}
|
|
52
|
+
const [field, value] = entry;
|
|
53
|
+
return field === 'id' ? store.get(value) ?? null : findByField(value, field);
|
|
54
|
+
};
|
|
32
55
|
const resource = {
|
|
33
|
-
load: async (
|
|
34
|
-
const fieldName = typeof field === 'string'
|
|
35
|
-
? field
|
|
36
|
-
: field?.field;
|
|
37
|
-
if (fieldName != null && fieldName !== 'id') {
|
|
38
|
-
return findByField(id, fieldName) ?? null;
|
|
39
|
-
}
|
|
40
|
-
return store.get(id) ?? null;
|
|
41
|
-
},
|
|
56
|
+
load: async (idOrWhere, _opts) => first(idOrWhere),
|
|
42
57
|
save: async (record) => {
|
|
43
58
|
if (record.id == null) {
|
|
44
59
|
throw new Error('@owlmeans/test-auth: cannot save TRUSTED record without id');
|
|
@@ -58,9 +73,11 @@ export const makeMemoryTrustedResource = (records = [], alias = TRUSTED_DEFAULT_
|
|
|
58
73
|
},
|
|
59
74
|
get: () => notImplemented('get'),
|
|
60
75
|
list: () => notImplemented('list'),
|
|
76
|
+
count: () => notImplemented('count'),
|
|
61
77
|
update: () => notImplemented('update'),
|
|
62
78
|
delete: () => notImplemented('delete'),
|
|
63
|
-
|
|
79
|
+
take: () => notImplemented('take'),
|
|
80
|
+
purge: () => notImplemented('purge'),
|
|
64
81
|
};
|
|
65
82
|
return appendContextual(alias, resource);
|
|
66
83
|
};
|
package/build/trusted.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trusted.js","sourceRoot":"","sources":["../src/trusted.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"trusted.js","sourceRoot":"","sources":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
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@owlmeans/auth": "^0.1.18-rc.
|
|
25
|
-
"@owlmeans/auth-common": "^0.1.18-rc.
|
|
26
|
-
"@owlmeans/basic-envelope": "^0.1.18-rc.
|
|
27
|
-
"@owlmeans/basic-keys": "^0.1.18-rc.
|
|
28
|
-
"@owlmeans/context": "^0.1.18-rc.
|
|
29
|
-
"@owlmeans/entrypoint": "^0.1.18-rc.
|
|
30
|
-
"@owlmeans/resource": "^0.1.18-rc.
|
|
31
|
-
"@owlmeans/test": "^0.1.18-rc.
|
|
24
|
+
"@owlmeans/auth": "^0.1.18-rc.8",
|
|
25
|
+
"@owlmeans/auth-common": "^0.1.18-rc.11",
|
|
26
|
+
"@owlmeans/basic-envelope": "^0.1.18-rc.10",
|
|
27
|
+
"@owlmeans/basic-keys": "^0.1.18-rc.10",
|
|
28
|
+
"@owlmeans/context": "^0.1.18-rc.7",
|
|
29
|
+
"@owlmeans/entrypoint": "^0.1.18-rc.9",
|
|
30
|
+
"@owlmeans/resource": "^0.1.18-rc.8",
|
|
31
|
+
"@owlmeans/test": "^0.1.18-rc.7"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@owlmeans/dep-config": "workspace:*",
|
|
35
|
-
"@types/bun": "^1.
|
|
35
|
+
"@types/bun": "^1.4.0",
|
|
36
36
|
"nodemon": "^3.1.14",
|
|
37
37
|
"typescript": "^7.0.2"
|
|
38
38
|
},
|
package/src/trusted.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { appendContextual } from '@owlmeans/context'
|
|
2
2
|
import type { TrustedRecord } from '@owlmeans/auth-common'
|
|
3
|
-
import type { Resource } from '@owlmeans/resource'
|
|
3
|
+
import type { Criteria, FirstOptions, Resource } from '@owlmeans/resource'
|
|
4
|
+
import { UnsupportedArgumentError } from '@owlmeans/resource'
|
|
4
5
|
|
|
5
6
|
const TRUSTED_DEFAULT_ALIAS = 'TRUSTED'
|
|
6
7
|
|
|
8
|
+
/** The fields a `trust()` lookup keys on — the only index this map has. */
|
|
9
|
+
const SUPPORTED_FIELDS = ['id', 'name']
|
|
10
|
+
|
|
7
11
|
const notImplemented = (op: string): never => {
|
|
8
12
|
throw new Error(`@owlmeans/test-auth: in-memory TRUSTED resource does not implement ${op}()`)
|
|
9
13
|
}
|
|
@@ -20,6 +24,10 @@ const getter = (record: TrustedRecord, field: string): unknown =>
|
|
|
20
24
|
* `trust()` boundary plus straightforward seeding from tests. Other
|
|
21
25
|
* operations throw, so tests that need them have to be honest about
|
|
22
26
|
* adding integration coverage instead of leaning on the mock.
|
|
27
|
+
*
|
|
28
|
+
* A read takes an id or a single-field criteria over `id` or `name`. Anything
|
|
29
|
+
* wider is refused rather than scanned: the mock holds a handful of fixtures
|
|
30
|
+
* and a query it cannot answer exactly is a test reaching past its seam.
|
|
23
31
|
*/
|
|
24
32
|
export const makeMemoryTrustedResource = (
|
|
25
33
|
records: TrustedRecord[] = [],
|
|
@@ -40,26 +48,39 @@ export const makeMemoryTrustedResource = (
|
|
|
40
48
|
return null
|
|
41
49
|
}
|
|
42
50
|
|
|
51
|
+
/**
|
|
52
|
+
* @throws {UnsupportedArgumentError} on criteria naming anything but one supported field.
|
|
53
|
+
*/
|
|
54
|
+
const first = (idOrWhere: string | Criteria<TrustedRecord>): TrustedRecord | null => {
|
|
55
|
+
if (typeof idOrWhere === 'string') {
|
|
56
|
+
return store.get(idOrWhere) ?? null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const entries = Object.entries(idOrWhere).filter(([, value]) => value !== undefined)
|
|
60
|
+
const [entry, ...rest] = entries
|
|
61
|
+
if (entry == null || rest.length > 0
|
|
62
|
+
|| !SUPPORTED_FIELDS.includes(entry[0]) || typeof entry[1] !== 'string') {
|
|
63
|
+
throw new UnsupportedArgumentError('test-auth:trusted:where')
|
|
64
|
+
}
|
|
65
|
+
const [field, value] = entry as [string, string]
|
|
66
|
+
|
|
67
|
+
return field === 'id' ? store.get(value) ?? null : findByField(value, field)
|
|
68
|
+
}
|
|
69
|
+
|
|
43
70
|
const resource: Partial<Resource<TrustedRecord>> = {
|
|
44
|
-
load: async
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
: (field as { field?: string } | undefined)?.field
|
|
48
|
-
if (fieldName != null && fieldName !== 'id') {
|
|
49
|
-
return (findByField(id, fieldName) as Type | null) ?? null
|
|
50
|
-
}
|
|
51
|
-
return (store.get(id) as Type | undefined) ?? null
|
|
52
|
-
},
|
|
71
|
+
load: async (
|
|
72
|
+
idOrWhere: string | Criteria<TrustedRecord>, _opts?: FirstOptions<TrustedRecord>
|
|
73
|
+
): Promise<TrustedRecord | null> => first(idOrWhere),
|
|
53
74
|
|
|
54
|
-
save: async
|
|
75
|
+
save: async (record: Partial<TrustedRecord>) => {
|
|
55
76
|
if (record.id == null) {
|
|
56
77
|
throw new Error('@owlmeans/test-auth: cannot save TRUSTED record without id')
|
|
57
78
|
}
|
|
58
79
|
store.set(record.id, record as TrustedRecord)
|
|
59
|
-
return record as
|
|
80
|
+
return record as TrustedRecord
|
|
60
81
|
},
|
|
61
82
|
|
|
62
|
-
create: async
|
|
83
|
+
create: async (record: Partial<TrustedRecord>) => {
|
|
63
84
|
if (record.id == null) {
|
|
64
85
|
throw new Error('@owlmeans/test-auth: cannot create TRUSTED record without id')
|
|
65
86
|
}
|
|
@@ -67,14 +88,16 @@ export const makeMemoryTrustedResource = (
|
|
|
67
88
|
throw new Error(`@owlmeans/test-auth: TRUSTED record ${record.id} already exists`)
|
|
68
89
|
}
|
|
69
90
|
store.set(record.id, record as TrustedRecord)
|
|
70
|
-
return record as
|
|
91
|
+
return record as TrustedRecord
|
|
71
92
|
},
|
|
72
93
|
|
|
73
94
|
get: () => notImplemented('get'),
|
|
74
95
|
list: () => notImplemented('list'),
|
|
96
|
+
count: () => notImplemented('count'),
|
|
75
97
|
update: () => notImplemented('update'),
|
|
76
98
|
delete: () => notImplemented('delete'),
|
|
77
|
-
|
|
99
|
+
take: () => notImplemented('take'),
|
|
100
|
+
purge: () => notImplemented('purge'),
|
|
78
101
|
}
|
|
79
102
|
|
|
80
103
|
return appendContextual<Resource<TrustedRecord>>(alias, resource)
|