@scoutflo/memory 0.0.0-stage → 0.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/package.json +6 -0
- package/dist/core/src/adapter.d.ts +30 -0
- package/dist/core/src/adapter.js +3 -0
- package/dist/core/src/adapter.js.map +1 -0
- package/dist/core/src/conformance/index.d.ts +36 -0
- package/dist/core/src/conformance/index.js +88 -0
- package/dist/core/src/conformance/index.js.map +1 -0
- package/dist/core/src/errors.d.ts +6 -0
- package/dist/core/src/errors.js +16 -0
- package/dist/core/src/errors.js.map +1 -0
- package/dist/core/src/helpers.d.ts +4 -0
- package/dist/core/src/helpers.js +38 -0
- package/dist/core/src/helpers.js.map +1 -0
- package/dist/core/src/index.d.ts +6 -0
- package/dist/core/src/index.js +26 -0
- package/dist/core/src/index.js.map +1 -0
- package/dist/core/src/registry.d.ts +12 -0
- package/dist/core/src/registry.js +36 -0
- package/dist/core/src/registry.js.map +1 -0
- package/dist/src/api.d.ts +2752 -0
- package/dist/src/api.js +108 -0
- package/dist/src/api.js.map +1 -0
- package/dist/src/browse.d.ts +159 -0
- package/dist/src/browse.js +40 -0
- package/dist/src/browse.js.map +1 -0
- package/dist/src/catalog.d.ts +703 -0
- package/dist/src/catalog.js +136 -0
- package/dist/src/catalog.js.map +1 -0
- package/dist/src/errors.d.ts +22 -0
- package/dist/src/errors.js +46 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/identity.d.ts +63 -0
- package/dist/src/identity.js +73 -0
- package/dist/src/identity.js.map +1 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +29 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/limits.d.ts +10 -0
- package/dist/src/limits.js +13 -0
- package/dist/src/limits.js.map +1 -0
- package/dist/src/providers.d.ts +81 -0
- package/dist/src/providers.js +51 -0
- package/dist/src/providers.js.map +1 -0
- package/dist/src/read.d.ts +345 -0
- package/dist/src/read.js +37 -0
- package/dist/src/read.js.map +1 -0
- package/dist/src/sha256.d.ts +2 -0
- package/dist/src/sha256.js +60 -0
- package/dist/src/sha256.js.map +1 -0
- package/dist/test/boundary.test.d.ts +1 -0
- package/dist/test/boundary.test.js +45 -0
- package/dist/test/boundary.test.js.map +1 -0
- package/dist/test/browse-read.test.d.ts +1 -0
- package/dist/test/browse-read.test.js +52 -0
- package/dist/test/browse-read.test.js.map +1 -0
- package/dist/test/catalog-api.test.d.ts +1 -0
- package/dist/test/catalog-api.test.js +148 -0
- package/dist/test/catalog-api.test.js.map +1 -0
- package/dist/test/core-conformance.test.d.ts +1 -0
- package/dist/test/core-conformance.test.js +114 -0
- package/dist/test/core-conformance.test.js.map +1 -0
- package/dist/test/core-helpers.test.d.ts +1 -0
- package/dist/test/core-helpers.test.js +66 -0
- package/dist/test/core-helpers.test.js.map +1 -0
- package/dist/test/core-registry.test.d.ts +1 -0
- package/dist/test/core-registry.test.js +51 -0
- package/dist/test/core-registry.test.js.map +1 -0
- package/dist/test/descriptors.test.d.ts +1 -0
- package/dist/test/descriptors.test.js +57 -0
- package/dist/test/descriptors.test.js.map +1 -0
- package/dist/test/identity.test.d.ts +1 -0
- package/dist/test/identity.test.js +79 -0
- package/dist/test/identity.test.js.map +1 -0
- package/package.json +45 -4
- package/README.md +0 -3
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { BrowsePage, BrowseRequest, ProviderDescriptor, ProviderId, SourceLocator } from '../../src';
|
|
2
|
+
/** Adapters act as `userId`. `ctx.connectionId` must equal `req.connectionId` in browse; adapters reject mismatches with `access_denied`. */
|
|
3
|
+
export interface AdapterContext {
|
|
4
|
+
accountId: string;
|
|
5
|
+
workspaceId: string;
|
|
6
|
+
userId: string;
|
|
7
|
+
connectionId: string;
|
|
8
|
+
}
|
|
9
|
+
export interface SourceIdentity {
|
|
10
|
+
provider: ProviderId;
|
|
11
|
+
objectKind: string;
|
|
12
|
+
sourceNamespace: string;
|
|
13
|
+
siteUrl: string;
|
|
14
|
+
}
|
|
15
|
+
export interface RawSource {
|
|
16
|
+
provider: ProviderId;
|
|
17
|
+
itemId: string;
|
|
18
|
+
locator: SourceLocator;
|
|
19
|
+
title: string;
|
|
20
|
+
url: string;
|
|
21
|
+
revision: string;
|
|
22
|
+
content: string;
|
|
23
|
+
contentFormat: 'confluence_storage' | 'markdown';
|
|
24
|
+
}
|
|
25
|
+
export interface SourceAdapter {
|
|
26
|
+
readonly descriptor: ProviderDescriptor;
|
|
27
|
+
authorize(ctx: AdapterContext): Promise<SourceIdentity>;
|
|
28
|
+
browse(ctx: AdapterContext, req: BrowseRequest): Promise<BrowsePage>;
|
|
29
|
+
read(ctx: AdapterContext, itemId: string): Promise<RawSource>;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../core/src/adapter.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BrowseCoverage, BrowseRequest } from '../../../src';
|
|
2
|
+
import type { AdapterContext, RawSource, SourceAdapter } from '../adapter';
|
|
3
|
+
export interface ConformanceFixtures {
|
|
4
|
+
ctx: AdapterContext;
|
|
5
|
+
/** Valid actor, but a different connection/account the adapter must refuse. */
|
|
6
|
+
foreignCtx: AdapterContext;
|
|
7
|
+
browse: {
|
|
8
|
+
request: BrowseRequest;
|
|
9
|
+
expectedCoverage: BrowseCoverage[];
|
|
10
|
+
};
|
|
11
|
+
readable: {
|
|
12
|
+
itemId: string;
|
|
13
|
+
expectedContentFormat: RawSource['contentFormat'];
|
|
14
|
+
};
|
|
15
|
+
denied?: {
|
|
16
|
+
itemId: string;
|
|
17
|
+
};
|
|
18
|
+
missing?: {
|
|
19
|
+
itemId: string;
|
|
20
|
+
};
|
|
21
|
+
tooLarge?: {
|
|
22
|
+
itemId: string;
|
|
23
|
+
};
|
|
24
|
+
unsupported?: {
|
|
25
|
+
itemId: string;
|
|
26
|
+
};
|
|
27
|
+
/** Actor lacking provider authorization. */
|
|
28
|
+
unauthenticated?: {
|
|
29
|
+
ctx: AdapterContext;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface ConformanceHarness {
|
|
33
|
+
describe(name: string, fn: () => void): void;
|
|
34
|
+
it(name: string, fn: () => void | Promise<void>): void;
|
|
35
|
+
}
|
|
36
|
+
export declare function runAdapterConformance(factory: () => SourceAdapter, f: ConformanceFixtures, h: ConformanceHarness): void;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runAdapterConformance = runAdapterConformance;
|
|
7
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
8
|
+
const src_1 = require("../../../src");
|
|
9
|
+
const helpers_1 = require("../helpers");
|
|
10
|
+
async function rejectsWith(p, code, what) {
|
|
11
|
+
let err;
|
|
12
|
+
try {
|
|
13
|
+
await p;
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
err = e;
|
|
17
|
+
}
|
|
18
|
+
strict_1.default.ok(err !== undefined, `${what}: expected rejection with ${code}, but it resolved`);
|
|
19
|
+
strict_1.default.ok(err instanceof src_1.MemoryContractError, `${what}: expected MemoryContractError, got ${String(err)}`);
|
|
20
|
+
strict_1.default.equal(err.code, code, `${what}: wrong error code`);
|
|
21
|
+
}
|
|
22
|
+
function runAdapterConformance(factory, f, h) {
|
|
23
|
+
const itemCase = (name, fixture, label, fn) => fixture ? h.it(name, () => fn(factory(), fixture.itemId)) : h.it(`${name} [skipped: no ${label} fixture]`, () => { });
|
|
24
|
+
h.describe('adapter conformance', () => {
|
|
25
|
+
h.it('authorize returns identity for its provider', async () => {
|
|
26
|
+
const a = factory();
|
|
27
|
+
const id = await a.authorize(f.ctx);
|
|
28
|
+
strict_1.default.equal(id.provider, a.descriptor.id);
|
|
29
|
+
strict_1.default.ok(id.sourceNamespace.length > 0, 'sourceNamespace must be non-empty');
|
|
30
|
+
});
|
|
31
|
+
h.it('identity round-trip', async () => {
|
|
32
|
+
const a = factory();
|
|
33
|
+
const raw = await a.read(f.ctx, f.readable.itemId);
|
|
34
|
+
strict_1.default.equal(raw.itemId, f.readable.itemId);
|
|
35
|
+
strict_1.default.equal((0, src_1.encodeItemId)(raw.locator), f.readable.itemId);
|
|
36
|
+
strict_1.default.equal(raw.provider, a.descriptor.id);
|
|
37
|
+
strict_1.default.equal(raw.contentFormat, f.readable.expectedContentFormat);
|
|
38
|
+
strict_1.default.ok((0, src_1.sourceKey)(raw.locator).length > 0);
|
|
39
|
+
});
|
|
40
|
+
h.it('actor binding rejects foreign context and mismatched connection', async () => {
|
|
41
|
+
const a = factory();
|
|
42
|
+
await rejectsWith(a.authorize(f.foreignCtx), 'access_denied', 'authorize(foreignCtx)');
|
|
43
|
+
await rejectsWith(a.browse(f.foreignCtx, { ...f.browse.request, connectionId: f.foreignCtx.connectionId }), 'access_denied', 'browse(foreignCtx)');
|
|
44
|
+
await rejectsWith(a.read(f.foreignCtx, f.readable.itemId), 'access_denied', 'read(foreignCtx)');
|
|
45
|
+
await rejectsWith(a.browse(f.ctx, { ...f.browse.request, connectionId: `${f.ctx.connectionId}-other` }), 'access_denied', 'browse(req.connectionId mismatch)');
|
|
46
|
+
});
|
|
47
|
+
itemCase('permission mapping: denied -> access_denied', f.denied, 'denied', (a, id) => rejectsWith(a.read(f.ctx, id), 'access_denied', 'read(denied)'));
|
|
48
|
+
itemCase('permission mapping: missing -> not_found', f.missing, 'missing', (a, id) => rejectsWith(a.read(f.ctx, id), 'not_found', 'read(missing)'));
|
|
49
|
+
if (f.unauthenticated) {
|
|
50
|
+
const ctx = f.unauthenticated.ctx;
|
|
51
|
+
h.it('permission mapping: unauthenticated -> authorization_required', () => rejectsWith(factory().read(ctx, f.readable.itemId), 'authorization_required', 'read(unauthenticated)'));
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
h.it('permission mapping: unauthenticated -> authorization_required [skipped: no unauthenticated fixture]', () => { });
|
|
55
|
+
h.it('pagination is bounded, truthful and non-overlapping', async () => {
|
|
56
|
+
const a = factory();
|
|
57
|
+
const page1 = await a.browse(f.ctx, f.browse.request);
|
|
58
|
+
strict_1.default.ok(page1.items.length <= f.browse.request.limit, 'first page exceeds limit');
|
|
59
|
+
strict_1.default.ok(f.browse.expectedCoverage.includes(page1.coverage), `unexpected coverage ${page1.coverage}`);
|
|
60
|
+
if (page1.nextCursor !== null) {
|
|
61
|
+
const page2 = await a.browse(f.ctx, { ...f.browse.request, cursor: page1.nextCursor });
|
|
62
|
+
const seen = new Set(page1.items.map((i) => i.id));
|
|
63
|
+
for (const i of page2.items)
|
|
64
|
+
strict_1.default.ok(!seen.has(i.id), `item ${i.id} repeated on page 2`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
h.it('revision and content hash are stable across reads', async () => {
|
|
68
|
+
const a = factory();
|
|
69
|
+
const r1 = await a.read(f.ctx, f.readable.itemId);
|
|
70
|
+
const r2 = await a.read(f.ctx, f.readable.itemId);
|
|
71
|
+
strict_1.default.ok(typeof r1.revision === 'string' && r1.revision.length > 0, 'revision must be a non-empty string');
|
|
72
|
+
strict_1.default.equal(r1.revision, r2.revision);
|
|
73
|
+
strict_1.default.equal((0, helpers_1.readWindow)(r1).citation.contentHash, (0, helpers_1.readWindow)(r2).citation.contentHash);
|
|
74
|
+
strict_1.default.equal((0, helpers_1.readWindow)(r1).citation.contentHash, (0, helpers_1.hashContent)(r1.content));
|
|
75
|
+
});
|
|
76
|
+
itemCase('too large -> too_large', f.tooLarge, 'tooLarge', async (a, id) => {
|
|
77
|
+
// Adapters may reject at read(), or return content that readWindow rejects.
|
|
78
|
+
await rejectsWith(a.read(f.ctx, id).then((raw) => (0, helpers_1.readWindow)(raw)), 'too_large', 'read(tooLarge)');
|
|
79
|
+
});
|
|
80
|
+
itemCase('unsupported -> unsupported_type', f.unsupported, 'unsupported', (a, id) => rejectsWith(a.read(f.ctx, id), 'unsupported_type', 'read(unsupported)'));
|
|
81
|
+
h.it('readWindow output parses with the SourceRead schema', async () => {
|
|
82
|
+
const raw = await factory().read(f.ctx, f.readable.itemId);
|
|
83
|
+
const parsed = src_1.SourceRead.safeParse((0, helpers_1.readWindow)(raw));
|
|
84
|
+
strict_1.default.ok(parsed.success, 'readWindow output is not a valid SourceRead');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../core/src/conformance/index.ts"],"names":[],"mappings":";;;;;AAgCA,sDAuEC;AAvGD,gEAAwC;AACxC,sCAAwI;AAExI,wCAAqD;AAqBrD,KAAK,UAAU,WAAW,CAAC,CAAmB,EAAE,IAAqB,EAAE,IAAY;IACjF,IAAI,GAAY,CAAC;IACjB,IAAI,CAAC;QAAC,MAAM,CAAC,CAAC;IAAC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QAAC,GAAG,GAAG,CAAC,CAAC;IAAC,CAAC;IACvC,gBAAM,CAAC,EAAE,CAAC,GAAG,KAAK,SAAS,EAAE,GAAG,IAAI,6BAA6B,IAAI,mBAAmB,CAAC,CAAC;IAC1F,gBAAM,CAAC,EAAE,CAAC,GAAG,YAAY,yBAAmB,EAAE,GAAG,IAAI,uCAAuC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC3G,gBAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,oBAAoB,CAAC,CAAC;AAC5D,CAAC;AAED,SAAgB,qBAAqB,CAAC,OAA4B,EAAE,CAAsB,EAAE,CAAqB;IAC/G,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,OAAuC,EAAE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BAAM,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,6CAA6C,CAAC,CAAC;QAC3E,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MemoryContractError, MemoryErrorBody, MemoryErrorCode } from '../../src';
|
|
2
|
+
export declare class MemoryProviderError extends MemoryContractError {
|
|
3
|
+
readonly retryAfter?: number | undefined;
|
|
4
|
+
constructor(code: MemoryErrorCode, message: string, retryAfter?: number | undefined);
|
|
5
|
+
toBody(): MemoryErrorBody;
|
|
6
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryProviderError = void 0;
|
|
4
|
+
const src_1 = require("../../src");
|
|
5
|
+
class MemoryProviderError extends src_1.MemoryContractError {
|
|
6
|
+
constructor(code, message, retryAfter) {
|
|
7
|
+
super(code, message);
|
|
8
|
+
this.retryAfter = retryAfter;
|
|
9
|
+
this.name = 'MemoryProviderError';
|
|
10
|
+
}
|
|
11
|
+
toBody() {
|
|
12
|
+
return { code: this.code, message: this.message, ...(this.retryAfter ? { retryAfter: this.retryAfter } : {}) };
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.MemoryProviderError = MemoryProviderError;
|
|
16
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../core/src/errors.ts"],"names":[],"mappings":";;;AAAA,mCAAkF;AAElF,MAAa,mBAAoB,SAAQ,yBAAmB;IAC1D,YAAY,IAAqB,EAAE,OAAe,EAAW,UAAmB;QAC9E,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QADsC,eAAU,GAAV,UAAU,CAAS;QAE9E,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;IAED,MAAM;QACJ,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IACjH,CAAC;CACF;AATD,kDASC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hashContent = hashContent;
|
|
4
|
+
exports.readWindow = readWindow;
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
|
+
const src_1 = require("../../src");
|
|
7
|
+
const errors_1 = require("./errors");
|
|
8
|
+
function hashContent(text) {
|
|
9
|
+
return (0, node_crypto_1.createHash)('sha256').update(text, 'utf8').digest('hex');
|
|
10
|
+
}
|
|
11
|
+
function readWindow(raw, offset = 0, now = () => new Date()) {
|
|
12
|
+
const total = raw.content.length;
|
|
13
|
+
if (total > src_1.MAX_SOURCE_CHARACTERS)
|
|
14
|
+
throw new errors_1.MemoryProviderError('too_large', 'Source is too large to read');
|
|
15
|
+
if (!Number.isInteger(offset) || offset < 0 || offset > total)
|
|
16
|
+
throw new errors_1.MemoryProviderError('invalid_request', 'Invalid read offset');
|
|
17
|
+
// Offsets and totalCharacters are UTF-16 code units; a window may split a surrogate pair.
|
|
18
|
+
const end = Math.min(offset + src_1.READ_WINDOW, total);
|
|
19
|
+
const confluence = raw.contentFormat === 'confluence_storage';
|
|
20
|
+
const warnings = [];
|
|
21
|
+
if (/<img\b|<ac:image\b/i.test(raw.content) || (!confluence && raw.content.includes('![')))
|
|
22
|
+
warnings.push('images_not_read');
|
|
23
|
+
if (confluence && /<(?:ri:attachment|ac:structured-macro)/.test(raw.content))
|
|
24
|
+
warnings.push('attachments_or_macros_not_expanded');
|
|
25
|
+
return {
|
|
26
|
+
outcome: 'read',
|
|
27
|
+
title: raw.title,
|
|
28
|
+
content: raw.content.slice(offset, end),
|
|
29
|
+
contentFormat: raw.contentFormat,
|
|
30
|
+
citation: {
|
|
31
|
+
provider: raw.provider, locator: raw.locator, itemId: raw.itemId, title: raw.title, href: raw.url,
|
|
32
|
+
sourceRevision: raw.revision, contentHash: hashContent(raw.content), readAt: now().toISOString(),
|
|
33
|
+
},
|
|
34
|
+
coverage: { offset, end, totalCharacters: total, complete: end >= total, nextOffset: end < total ? end : null },
|
|
35
|
+
warnings,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../core/src/helpers.ts"],"names":[],"mappings":";;AAKA,kCAEC;AAED,gCAsBC;AA/BD,6CAAyC;AACzC,mCAAwF;AAExF,qCAA+C;AAE/C,SAAgB,WAAW,CAAC,IAAY;IACtC,OAAO,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC;AAED,SAAgB,UAAU,CAAC,GAAc,EAAE,MAAM,GAAG,CAAC,EAAE,MAAkB,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;IACvF,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC;IACjC,IAAI,KAAK,GAAG,2BAAqB;QAAE,MAAM,IAAI,4BAAmB,CAAC,WAAW,EAAE,6BAA6B,CAAC,CAAC;IAC7G,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,IAAI,MAAM,GAAG,KAAK;QAAE,MAAM,IAAI,4BAAmB,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,CAAC;IACvI,0FAA0F;IAC1F,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,M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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.MemoryErrorCode = exports.MemoryContractError = void 0;
|
|
18
|
+
var src_1 = require("../../src");
|
|
19
|
+
Object.defineProperty(exports, "MemoryContractError", { enumerable: true, get: function () { return src_1.MemoryContractError; } });
|
|
20
|
+
Object.defineProperty(exports, "MemoryErrorCode", { enumerable: true, get: function () { return src_1.MemoryErrorCode; } });
|
|
21
|
+
__exportStar(require("./errors"), exports);
|
|
22
|
+
__exportStar(require("./adapter"), exports);
|
|
23
|
+
__exportStar(require("./registry"), exports);
|
|
24
|
+
__exportStar(require("./helpers"), exports);
|
|
25
|
+
__exportStar(require("./conformance"), exports);
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../core/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iCAAiE;AAAxD,0GAAA,mBAAmB,OAAA;AAAE,sGAAA,eAAe,OAAA;AAC7C,2CAAyB;AACzB,4CAA0B;AAC1B,6CAA2B;AAC3B,4CAA0B;AAC1B,gDAA8B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ProviderDescriptor, ProviderId } from '../../src';
|
|
2
|
+
import type { SourceAdapter } from './adapter';
|
|
3
|
+
export interface ProviderRegistry {
|
|
4
|
+
forProvider(id: ProviderId): SourceAdapter;
|
|
5
|
+
forConnection(connectionId: string): Promise<SourceAdapter>;
|
|
6
|
+
enabledProviders(): ProviderDescriptor[];
|
|
7
|
+
}
|
|
8
|
+
export declare function createProviderRegistry(adapters: SourceAdapter[], options: {
|
|
9
|
+
enabled: ProviderId[];
|
|
10
|
+
providerOf: (connectionId: string) => Promise<ProviderId>;
|
|
11
|
+
}): ProviderRegistry;
|
|
12
|
+
export declare function parseEnabledProviders(envValue: string | undefined, fallback: ProviderId[]): ProviderId[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createProviderRegistry = createProviderRegistry;
|
|
4
|
+
exports.parseEnabledProviders = parseEnabledProviders;
|
|
5
|
+
const src_1 = require("../../src");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
|
+
function createProviderRegistry(adapters, options) {
|
|
8
|
+
const byId = new Map();
|
|
9
|
+
for (const a of adapters) {
|
|
10
|
+
if (byId.has(a.descriptor.id))
|
|
11
|
+
throw new Error(`Duplicate adapter for provider ${a.descriptor.id}`);
|
|
12
|
+
byId.set(a.descriptor.id, a);
|
|
13
|
+
}
|
|
14
|
+
const forProvider = (id) => {
|
|
15
|
+
const adapter = options.enabled.includes(id) ? byId.get(id) : undefined;
|
|
16
|
+
if (!adapter)
|
|
17
|
+
throw new errors_1.MemoryProviderError('provider_unavailable', `Provider ${id} is unavailable`);
|
|
18
|
+
return adapter;
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
forProvider,
|
|
22
|
+
forConnection: async (connectionId) => forProvider(await options.providerOf(connectionId)),
|
|
23
|
+
enabledProviders: () => options.enabled.filter((id) => byId.has(id)).map((id) => byId.get(id).descriptor),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function parseEnabledProviders(envValue, fallback) {
|
|
27
|
+
const ids = (envValue ?? '').split(',').map((s) => s.trim()).filter(Boolean);
|
|
28
|
+
if (!ids.length)
|
|
29
|
+
return fallback;
|
|
30
|
+
for (const id of ids) {
|
|
31
|
+
if (!Object.prototype.hasOwnProperty.call(src_1.PROVIDERS, id))
|
|
32
|
+
throw new src_1.MemoryContractError('invalid_request', `Unknown provider: ${id}`);
|
|
33
|
+
}
|
|
34
|
+
return ids;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../core/src/registry.ts"],"names":[],"mappings":";;AAUA,wDAmBC;AAED,sDAOC;AAtCD,mCAA2F;AAE3F,qCAA+C;AAQ/C,SAAgB,sBAAsB,CACpC,QAAyB,EACzB,OAA6F;IAE7F,MAAM,IAAI,GAAG,IAAI,GAAG,EAA6B,CAAC;IAClD,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC;QACpG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC/B,CAAC;IACD,MAAM,WAAW,GAAG,CAAC,EAAc,EAAiB,EAAE;QACpD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CA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