@jini-ai/capability-providers 0.1.0
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/LICENSE +201 -0
- package/dist/auth.d.ts +70 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +181 -0
- package/dist/auth.js.map +1 -0
- package/dist/db.d.ts +75 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +83 -0
- package/dist/db.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/payments.d.ts +98 -0
- package/dist/payments.d.ts.map +1 -0
- package/dist/payments.js +180 -0
- package/dist/payments.js.map +1 -0
- package/dist/realtime.d.ts +86 -0
- package/dist/realtime.d.ts.map +1 -0
- package/dist/realtime.js +147 -0
- package/dist/realtime.js.map +1 -0
- package/dist/storage.d.ts +70 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +61 -0
- package/dist/storage.js.map +1 -0
- package/dist/tokens.d.ts +11 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +18 -0
- package/dist/tokens.js.map +1 -0
- package/dist/unsafe-reference/auth.d.ts +22 -0
- package/dist/unsafe-reference/auth.d.ts.map +1 -0
- package/dist/unsafe-reference/auth.js +56 -0
- package/dist/unsafe-reference/auth.js.map +1 -0
- package/dist/unsafe-reference/db.d.ts +16 -0
- package/dist/unsafe-reference/db.d.ts.map +1 -0
- package/dist/unsafe-reference/db.js +49 -0
- package/dist/unsafe-reference/db.js.map +1 -0
- package/dist/unsafe-reference/index.d.ts +49 -0
- package/dist/unsafe-reference/index.d.ts.map +1 -0
- package/dist/unsafe-reference/index.js +49 -0
- package/dist/unsafe-reference/index.js.map +1 -0
- package/dist/unsafe-reference/payments.d.ts +17 -0
- package/dist/unsafe-reference/payments.d.ts.map +1 -0
- package/dist/unsafe-reference/payments.js +38 -0
- package/dist/unsafe-reference/payments.js.map +1 -0
- package/dist/unsafe-reference/realtime.d.ts +17 -0
- package/dist/unsafe-reference/realtime.d.ts.map +1 -0
- package/dist/unsafe-reference/realtime.js +34 -0
- package/dist/unsafe-reference/realtime.js.map +1 -0
- package/dist/unsafe-reference/storage.d.ts +16 -0
- package/dist/unsafe-reference/storage.d.ts.map +1 -0
- package/dist/unsafe-reference/storage.js +30 -0
- package/dist/unsafe-reference/storage.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `StorageProvider` — a swappable blob-storage port (file uploads, generated
|
|
3
|
+
* assets). Speculative port-design exploration (see `source-map.md`) — no OD
|
|
4
|
+
* source; the shape is the object-storage capability Zana's `app-chassis`
|
|
5
|
+
* (`packages/storage`) and Tovu-Runner's ports layer both name explicitly.
|
|
6
|
+
*
|
|
7
|
+
* This file defines the port's stable interface/type surface, plus one real,
|
|
8
|
+
* production-quality adapter (`BlobStorageProvider`, added 2026-07-21 — see
|
|
9
|
+
* `source-map.md`'s dated section). The in-memory reference implementation
|
|
10
|
+
* (`createInMemoryStorageProvider`) is a separate, non-production stub that
|
|
11
|
+
* lives under `src/unsafe-reference/`, exported only from the separate
|
|
12
|
+
* `@jini-ai/capability-providers/unsafe-reference` entry point — see that
|
|
13
|
+
* directory's `index.ts` header for the full warning.
|
|
14
|
+
*/
|
|
15
|
+
import type { BlobStorage } from '@jini-ai/platform';
|
|
16
|
+
export interface StorageObjectMeta {
|
|
17
|
+
readonly key: string;
|
|
18
|
+
readonly size: number;
|
|
19
|
+
readonly contentType?: string;
|
|
20
|
+
readonly updatedAt: number;
|
|
21
|
+
}
|
|
22
|
+
export interface StoragePutOptions {
|
|
23
|
+
readonly contentType?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface StorageProvider {
|
|
26
|
+
/** Writes `data` at `key`, overwriting any existing object. */
|
|
27
|
+
put(key: string, data: Uint8Array, options?: StoragePutOptions): Promise<StorageObjectMeta>;
|
|
28
|
+
/** Reads the object at `key`, or `null` if it doesn't exist. */
|
|
29
|
+
get(key: string): Promise<Uint8Array | null>;
|
|
30
|
+
/** Deletes the object at `key`. A no-op if it doesn't exist. */
|
|
31
|
+
delete(key: string): Promise<void>;
|
|
32
|
+
/** Lists objects whose key starts with `prefix` (all objects when `prefix` is omitted), sorted by key. */
|
|
33
|
+
list(prefix?: string): Promise<StorageObjectMeta[]>;
|
|
34
|
+
}
|
|
35
|
+
export interface BlobStorageProviderOptions {
|
|
36
|
+
/**
|
|
37
|
+
* The `BlobStorage` namespace this provider scopes every `StorageProvider` key under (see
|
|
38
|
+
* `BlobStorage`'s own module doc: "a tenant id, a workspace id, a project id, whatever the
|
|
39
|
+
* host application scopes storage by"). `StorageProvider`'s `key` maps 1:1 onto `BlobStorage`'s
|
|
40
|
+
* `relpath` within this fixed namespace — this adapter does not expose namespace switching,
|
|
41
|
+
* matching `StorageProvider`'s single flat `key` surface (bind a separate `BlobStorageProvider`
|
|
42
|
+
* per namespace if a host needs more than one).
|
|
43
|
+
*/
|
|
44
|
+
readonly namespace: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* `StorageProvider` adapter that delegates to an injected `BlobStorage` instance
|
|
48
|
+
* (`@jini-ai/platform`'s real, tested port — `LocalBlobStorage` or `S3BlobStorage`). A thin
|
|
49
|
+
* method-shape mapping, not a reimplementation: every operation is one `BlobStorage` call plus
|
|
50
|
+
* field renaming (`path`→`key`, `mtimeMs`→`updatedAt`).
|
|
51
|
+
*
|
|
52
|
+
* Known limitation: `BlobFileMeta` (the metadata `BlobStorage` actually persists) has no
|
|
53
|
+
* `contentType` field, so `StoragePutOptions.contentType` cannot be durably stored — `put()`
|
|
54
|
+
* echoes it straight back in the `StorageObjectMeta` it returns (matching the option the caller
|
|
55
|
+
* just passed), but a later `get`-equivalent lookup (`list()`) can never recover it, since
|
|
56
|
+
* nothing under `../platform` persists it. `StorageObjectMeta.contentType` is optional
|
|
57
|
+
* specifically so an adapter is free to omit it when the backing store can't carry it — this is
|
|
58
|
+
* a deliberate, documented adapter-level gap, not a `StorageProvider` interface change.
|
|
59
|
+
*/
|
|
60
|
+
export declare class BlobStorageProvider implements StorageProvider {
|
|
61
|
+
private readonly blobStorage;
|
|
62
|
+
private readonly options;
|
|
63
|
+
constructor(blobStorage: BlobStorage, options: BlobStorageProviderOptions);
|
|
64
|
+
put(key: string, data: Uint8Array, options?: StoragePutOptions): Promise<StorageObjectMeta>;
|
|
65
|
+
get(key: string): Promise<Uint8Array | null>;
|
|
66
|
+
delete(key: string): Promise<void>;
|
|
67
|
+
list(prefix?: string): Promise<StorageObjectMeta[]>;
|
|
68
|
+
private toObjectMeta;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAgB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGnE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,eAAe;IAC9B,+DAA+D;IAC/D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC5F,gEAAgE;IAChE,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAC7C,gEAAgE;IAChE,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,0GAA0G;IAC1G,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;CACrD;AAED,MAAM,WAAW,0BAA0B;IACzC;;;;;;;OAOG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,mBAAoB,YAAW,eAAe;IAEvD,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADP,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,0BAA0B;IAOhD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAK/F,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAS5C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMlC,IAAI,CAAC,MAAM,SAAK,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAQrD,OAAO,CAAC,YAAY;CAQrB"}
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { StorageError as BlobStorageError } from '@jini-ai/platform';
|
|
2
|
+
/**
|
|
3
|
+
* `StorageProvider` adapter that delegates to an injected `BlobStorage` instance
|
|
4
|
+
* (`@jini-ai/platform`'s real, tested port — `LocalBlobStorage` or `S3BlobStorage`). A thin
|
|
5
|
+
* method-shape mapping, not a reimplementation: every operation is one `BlobStorage` call plus
|
|
6
|
+
* field renaming (`path`→`key`, `mtimeMs`→`updatedAt`).
|
|
7
|
+
*
|
|
8
|
+
* Known limitation: `BlobFileMeta` (the metadata `BlobStorage` actually persists) has no
|
|
9
|
+
* `contentType` field, so `StoragePutOptions.contentType` cannot be durably stored — `put()`
|
|
10
|
+
* echoes it straight back in the `StorageObjectMeta` it returns (matching the option the caller
|
|
11
|
+
* just passed), but a later `get`-equivalent lookup (`list()`) can never recover it, since
|
|
12
|
+
* nothing under `../platform` persists it. `StorageObjectMeta.contentType` is optional
|
|
13
|
+
* specifically so an adapter is free to omit it when the backing store can't carry it — this is
|
|
14
|
+
* a deliberate, documented adapter-level gap, not a `StorageProvider` interface change.
|
|
15
|
+
*/
|
|
16
|
+
export class BlobStorageProvider {
|
|
17
|
+
blobStorage;
|
|
18
|
+
options;
|
|
19
|
+
constructor(blobStorage, options) {
|
|
20
|
+
this.blobStorage = blobStorage;
|
|
21
|
+
this.options = options;
|
|
22
|
+
if (!options.namespace) {
|
|
23
|
+
throw new Error('BlobStorageProvider requires a non-empty options.namespace');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async put(key, data, options = {}) {
|
|
27
|
+
const meta = await this.blobStorage.writeFile(this.options.namespace, key, Buffer.from(data));
|
|
28
|
+
return this.toObjectMeta(meta, options.contentType);
|
|
29
|
+
}
|
|
30
|
+
async get(key) {
|
|
31
|
+
try {
|
|
32
|
+
return await this.blobStorage.readFile(this.options.namespace, key);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
if (err instanceof BlobStorageError && err.code === 'NOT_FOUND')
|
|
36
|
+
return null;
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async delete(key) {
|
|
41
|
+
// `BlobStorage.deleteFile` is already documented idempotent (missing files don't throw),
|
|
42
|
+
// matching `StorageProvider.delete`'s "no-op if it doesn't exist" contract directly.
|
|
43
|
+
await this.blobStorage.deleteFile(this.options.namespace, key);
|
|
44
|
+
}
|
|
45
|
+
async list(prefix = '') {
|
|
46
|
+
const files = await this.blobStorage.listFiles(this.options.namespace);
|
|
47
|
+
return files
|
|
48
|
+
.filter((file) => file.path.startsWith(prefix))
|
|
49
|
+
.map((file) => this.toObjectMeta(file))
|
|
50
|
+
.sort((a, b) => a.key.localeCompare(b.key));
|
|
51
|
+
}
|
|
52
|
+
toObjectMeta(meta, contentType) {
|
|
53
|
+
return {
|
|
54
|
+
key: meta.path,
|
|
55
|
+
size: meta.size,
|
|
56
|
+
updatedAt: meta.mtimeMs,
|
|
57
|
+
...(contentType !== undefined ? { contentType } : {}),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAoCrE;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,mBAAmB;IAEX;IACA;IAFnB,YACmB,WAAwB,EACxB,OAAmC;QADnC,gBAAW,GAAX,WAAW,CAAa;QACxB,YAAO,GAAP,OAAO,CAA4B;QAEpD,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;QAChF,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,IAAgB,EAAE,UAA6B,EAAE;QACtE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9F,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC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@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AuthProvider } from './auth.js';
|
|
2
|
+
import type { DbProvider } from './db.js';
|
|
3
|
+
import type { PaymentsProvider } from './payments.js';
|
|
4
|
+
import type { RealtimeProvider } from './realtime.js';
|
|
5
|
+
import type { StorageProvider } from './storage.js';
|
|
6
|
+
export declare const AuthProviderToken: import("@jini-ai/core").Token<AuthProvider, string>;
|
|
7
|
+
export declare const StorageProviderToken: import("@jini-ai/core").Token<StorageProvider, string>;
|
|
8
|
+
export declare const PaymentsProviderToken: import("@jini-ai/core").Token<PaymentsProvider, string>;
|
|
9
|
+
export declare const DbProviderToken: import("@jini-ai/core").Token<DbProvider, string>;
|
|
10
|
+
export declare const RealtimeProviderToken: import("@jini-ai/core").Token<RealtimeProvider, string>;
|
|
11
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,eAAO,MAAM,iBAAiB,qDAAuD,CAAC;AACtF,eAAO,MAAM,oBAAoB,wDAA6D,CAAC;AAC/F,eAAO,MAAM,qBAAqB,yDAA+D,CAAC;AAClG,eAAO,MAAM,eAAe,mDAAmD,CAAC;AAChF,eAAO,MAAM,qBAAqB,yDAA+D,CAAC"}
|
package/dist/tokens.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed DI tokens for each capability-provider port, following the exact
|
|
3
|
+
* pattern `@jini-ai/core`'s `token()` establishes (see
|
|
4
|
+
* `packages/core/src/token.ts`) and the naming convention `@jini-ai/daemon`'s
|
|
5
|
+
* `src/tokens.ts` / `@jini-ai/media`'s `src/tokens.ts` already set
|
|
6
|
+
* (bare-interface-name-suffixed-`Token`).
|
|
7
|
+
*
|
|
8
|
+
* These tokens are exported for a future consumer to `bind()` in its own
|
|
9
|
+
* composition — this package itself does not bind them anywhere, and
|
|
10
|
+
* nothing else in this repo imports this package (see `source-map.md`).
|
|
11
|
+
*/
|
|
12
|
+
import { token } from '@jini-ai/core';
|
|
13
|
+
export const AuthProviderToken = token('jini.capabilityProviders.auth');
|
|
14
|
+
export const StorageProviderToken = token('jini.capabilityProviders.storage');
|
|
15
|
+
export const PaymentsProviderToken = token('jini.capabilityProviders.payments');
|
|
16
|
+
export const DbProviderToken = token('jini.capabilityProviders.db');
|
|
17
|
+
export const RealtimeProviderToken = token('jini.capabilityProviders.realtime');
|
|
18
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAOtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAe,+BAA+B,CAAC,CAAC;AACtF,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAkB,kCAAkC,CAAC,CAAC;AAC/F,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAmB,mCAAmC,CAAC,CAAC;AAClG,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAa,6BAA6B,CAAC,CAAC;AAChF,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAmB,mCAAmC,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UNSAFE REFERENCE IMPLEMENTATION — not production code. See the header
|
|
3
|
+
* comment in `src/unsafe-reference/index.ts` for the full warning; the
|
|
4
|
+
* short version: `createInMemoryAuthProvider` stores plaintext passwords
|
|
5
|
+
* and issues predictable, non-cryptographic session tokens. It exists only
|
|
6
|
+
* to prove `AuthProvider` (defined in `../auth.ts`) is implementable and
|
|
7
|
+
* unit-testable. Never wire this into anything that handles real
|
|
8
|
+
* credentials.
|
|
9
|
+
*
|
|
10
|
+
* A real adapter (Supabase Auth, Auth0, a JWT-backed service) implements
|
|
11
|
+
* the same `AuthProvider` interface without importing this file.
|
|
12
|
+
*/
|
|
13
|
+
import type { AuthProvider } from '../auth.js';
|
|
14
|
+
export interface InMemoryAuthProviderOptions {
|
|
15
|
+
/** Session lifetime in ms. Defaults to 1 hour. */
|
|
16
|
+
readonly sessionTtlMs?: number;
|
|
17
|
+
/** Injectable clock for deterministic tests; defaults to `Date.now`. */
|
|
18
|
+
readonly now?: () => number;
|
|
19
|
+
}
|
|
20
|
+
/** Creates the in-memory reference `AuthProvider`. No persistence — state is lost on process exit. */
|
|
21
|
+
export declare function createInMemoryAuthProvider(options?: InMemoryAuthProviderOptions): AuthProvider;
|
|
22
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/unsafe-reference/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAmB,YAAY,EAAyB,MAAM,YAAY,CAAC;AAEvF,MAAM,WAAW,2BAA2B;IAC1C,kDAAkD;IAClD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,wEAAwE;IACxE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CAC7B;AAQD,sGAAsG;AACtG,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,2BAAgC,GAAG,YAAY,CAuDlG"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const DEFAULT_SESSION_TTL_MS = 60 * 60 * 1000;
|
|
2
|
+
/** Creates the in-memory reference `AuthProvider`. No persistence — state is lost on process exit. */
|
|
3
|
+
export function createInMemoryAuthProvider(options = {}) {
|
|
4
|
+
const sessionTtlMs = options.sessionTtlMs ?? DEFAULT_SESSION_TTL_MS;
|
|
5
|
+
const now = options.now ?? Date.now;
|
|
6
|
+
const usersByEmail = new Map();
|
|
7
|
+
const sessions = new Map();
|
|
8
|
+
let nextId = 1;
|
|
9
|
+
let nextToken = 1;
|
|
10
|
+
return {
|
|
11
|
+
async signUp(credentials) {
|
|
12
|
+
if (usersByEmail.has(credentials.email)) {
|
|
13
|
+
throw new Error(`email already registered: ${credentials.email}`);
|
|
14
|
+
}
|
|
15
|
+
const user = {
|
|
16
|
+
id: `user-${nextId++}`,
|
|
17
|
+
email: credentials.email,
|
|
18
|
+
password: credentials.password,
|
|
19
|
+
createdAt: now(),
|
|
20
|
+
};
|
|
21
|
+
usersByEmail.set(credentials.email, user);
|
|
22
|
+
return { id: user.id, email: user.email, createdAt: user.createdAt };
|
|
23
|
+
},
|
|
24
|
+
async signIn(credentials) {
|
|
25
|
+
const user = usersByEmail.get(credentials.email);
|
|
26
|
+
if (!user || user.password !== credentials.password) {
|
|
27
|
+
throw new Error('invalid email or password');
|
|
28
|
+
}
|
|
29
|
+
const session = {
|
|
30
|
+
token: `session-${nextToken++}`,
|
|
31
|
+
userId: user.id,
|
|
32
|
+
expiresAt: now() + sessionTtlMs,
|
|
33
|
+
};
|
|
34
|
+
sessions.set(session.token, session);
|
|
35
|
+
return session;
|
|
36
|
+
},
|
|
37
|
+
async signOut(token) {
|
|
38
|
+
sessions.delete(token);
|
|
39
|
+
},
|
|
40
|
+
async verifySession(token) {
|
|
41
|
+
const session = sessions.get(token);
|
|
42
|
+
if (!session)
|
|
43
|
+
return null;
|
|
44
|
+
if (session.expiresAt <= now()) {
|
|
45
|
+
sessions.delete(token);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
// This port surface has no deleteUser, so a session's userId always
|
|
49
|
+
// resolves — the non-null assertion documents that invariant rather
|
|
50
|
+
// than a defensive branch with no real runtime path.
|
|
51
|
+
const user = [...usersByEmail.values()].find((u) => u.id === session.userId);
|
|
52
|
+
return { id: user.id, email: user.email, createdAt: user.createdAt };
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/unsafe-reference/auth.ts"],"names":[],"mappings":"AAqBA,MAAM,sBAAsB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAM9C,sGAAsG;AACtG,MAAM,UAAU,0BAA0B,CAAC,UAAuC,EAAE;IAClF,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,sBAAsB,CAAC;IACpE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;IACpC,MAAM,YAAY,GAAG,IAAI,GAAG,EAAsB,CAAC;IACnD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IAChD,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,OAAO;QACL,KAAK,CAAC,MAAM,CAAC,WAA4B;YACvC,IAAI,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;gBACxC,MAAM,IAAI,KAAK,CAAC,6BAA6B,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;YACpE,CAAC;YACD,MAAM,IAAI,GAAe;gBACvB,EAAE,EAAE,QAAQ,MAAM,EAAE,EAAE;gBACtB,KAAK,EAAE,WAAW,CAAC,KAAK;gBACxB,QAAQ,EAAE,WAAW,CAAC,QAAQ;gBAC9B,SAAS,EAAE,GAAG,EAAE;aACjB,CAAC;YACF,YAAY,CAAC,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AE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,MAAM,CAAE,CAAC;YAC9E,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;QACvE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UNSAFE REFERENCE IMPLEMENTATION — not production code. See the header
|
|
3
|
+
* comment in `src/unsafe-reference/index.ts` for the full warning; the
|
|
4
|
+
* short version: `createInMemoryDbProvider` has no principal/tenant/ACL
|
|
5
|
+
* dimension, no quotas, and no size bounds. It exists only to prove
|
|
6
|
+
* `DbProvider` (defined in `../db.ts`) is implementable and unit-testable.
|
|
7
|
+
* Never wire this into anything that handles real user data.
|
|
8
|
+
*
|
|
9
|
+
* A real adapter (`@jini-ai/sqlite`, Supabase Postgres) implements the same
|
|
10
|
+
* `DbProvider` interface without importing this file — this is
|
|
11
|
+
* deliberately not that adapter (see the scope note in `source-map.md`).
|
|
12
|
+
*/
|
|
13
|
+
import type { DbProvider } from '../db.js';
|
|
14
|
+
/** Creates the in-memory reference `DbProvider`. No persistence — state is lost on process exit. */
|
|
15
|
+
export declare function createInMemoryDbProvider(): DbProvider;
|
|
16
|
+
//# sourceMappingURL=db.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/unsafe-reference/db.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,UAAU,EAAqB,MAAM,UAAU,CAAC;AAO9D,oGAAoG;AACpG,wBAAgB,wBAAwB,IAAI,UAAU,CA6CrD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
function matchesWhere(record, where) {
|
|
2
|
+
if (!where)
|
|
3
|
+
return true;
|
|
4
|
+
return Object.entries(where).every(([key, value]) => record[key] === value);
|
|
5
|
+
}
|
|
6
|
+
/** Creates the in-memory reference `DbProvider`. No persistence — state is lost on process exit. */
|
|
7
|
+
export function createInMemoryDbProvider() {
|
|
8
|
+
const collections = new Map();
|
|
9
|
+
function collectionFor(name) {
|
|
10
|
+
let collection = collections.get(name);
|
|
11
|
+
if (!collection) {
|
|
12
|
+
collection = new Map();
|
|
13
|
+
collections.set(name, collection);
|
|
14
|
+
}
|
|
15
|
+
return collection;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
async insert(collectionName, record) {
|
|
19
|
+
const collection = collectionFor(collectionName);
|
|
20
|
+
if (collection.has(record.id)) {
|
|
21
|
+
throw new Error(`record already exists: ${collectionName}/${record.id}`);
|
|
22
|
+
}
|
|
23
|
+
collection.set(record.id, record);
|
|
24
|
+
return record;
|
|
25
|
+
},
|
|
26
|
+
async get(collectionName, id) {
|
|
27
|
+
return collections.get(collectionName)?.get(id) ?? null;
|
|
28
|
+
},
|
|
29
|
+
async update(collectionName, id, patch) {
|
|
30
|
+
const collection = collections.get(collectionName);
|
|
31
|
+
const existing = collection?.get(id);
|
|
32
|
+
if (!collection || !existing)
|
|
33
|
+
return null;
|
|
34
|
+
const updated = { ...existing, ...patch, id };
|
|
35
|
+
collection.set(id, updated);
|
|
36
|
+
return updated;
|
|
37
|
+
},
|
|
38
|
+
async delete(collectionName, id) {
|
|
39
|
+
collections.get(collectionName)?.delete(id);
|
|
40
|
+
},
|
|
41
|
+
async query(collectionName, query = {}) {
|
|
42
|
+
const collection = collections.get(collectionName);
|
|
43
|
+
if (!collection)
|
|
44
|
+
return [];
|
|
45
|
+
return [...collection.values()].filter((record) => matchesWhere(record, query.where));
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=db.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.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AI,CAAC;QAC1D,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,cAAsB,EAAE,EAAU,EAAE,KAAwC;YACvF,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YACnD,MAAM,QAAQ,GAAG,UAAU,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;YACrC,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ;gBAAE,OAAO,IAAI,CAAC;YAC1C,MAAM,OAAO,GAAa,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE,CAAC;YACxD,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;YAC5B,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,cAAsB,EAAE,EAAU;YAC7C,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QAC9C,CAAC;QAED,KAAK,CAAC,KAAK,CAAC,cAAsB,EAAE,QAAiB,EAAE;YACrD,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YACnD,IAAI,CAAC,UAAU;gBAAE,OAAO,EAAE,CAAC;YAC3B,OAAO,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACxF,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@jini-ai/capability-providers/unsafe-reference` — UNSAFE, NON-PRODUCTION
|
|
3
|
+
* reference implementations. Read this before importing anything from this
|
|
4
|
+
* directory.
|
|
5
|
+
*
|
|
6
|
+
* Every factory exported from this module (`createInMemoryAuthProvider`,
|
|
7
|
+
* `createInMemoryStorageProvider`, `createInMemoryPaymentsProvider`,
|
|
8
|
+
* `createInMemoryDbProvider`, `createInMemoryRealtimeProvider`) is a
|
|
9
|
+
* minimal, non-cryptographic, in-memory reference stub whose only purpose
|
|
10
|
+
* is to prove that the corresponding port interface in the package's normal
|
|
11
|
+
* entry point (`@jini-ai/capability-providers`) is genuinely implementable and
|
|
12
|
+
* unit-testable. None of them is, or is intended to become, a production
|
|
13
|
+
* adapter:
|
|
14
|
+
*
|
|
15
|
+
* - `createInMemoryAuthProvider` stores passwords in plaintext and issues
|
|
16
|
+
* predictable, incrementing `user-N`/`session-N` identifiers — no
|
|
17
|
+
* hashing, no secure randomness, no rate limiting, no password policy.
|
|
18
|
+
* - `createInMemoryPaymentsProvider` deterministically succeeds every
|
|
19
|
+
* charge (rejecting only a non-positive amount) — no real money moves,
|
|
20
|
+
* no idempotency, no replay protection.
|
|
21
|
+
* - `createInMemoryStorageProvider`, `createInMemoryDbProvider`, and
|
|
22
|
+
* `createInMemoryRealtimeProvider` have no principal/tenant/ACL
|
|
23
|
+
* dimension, no quotas, and no size bounds — all state is unbounded,
|
|
24
|
+
* process-local memory.
|
|
25
|
+
*
|
|
26
|
+
* Do not wire any of these into anything that handles real credentials,
|
|
27
|
+
* payments, or user data — not behind a feature flag, not "just for now,"
|
|
28
|
+
* not in a demo that might get deployed. If you need a real adapter,
|
|
29
|
+
* implement the port interface (`AuthProvider`, `PaymentsProvider`,
|
|
30
|
+
* `StorageProvider`, `DbProvider`, `RealtimeProvider`) against an actual
|
|
31
|
+
* provider (Supabase, Auth0, Stripe, S3, a real Postgres/SQLite-backed
|
|
32
|
+
* store, etc.) instead.
|
|
33
|
+
*
|
|
34
|
+
* This is why these implementations live at the separate
|
|
35
|
+
* `@jini-ai/capability-providers/unsafe-reference` import path rather than the
|
|
36
|
+
* package's normal `@jini-ai/capability-providers` barrel: importing them
|
|
37
|
+
* requires opting in to this path by name, so they can't be pulled in by
|
|
38
|
+
* accident alongside the port interfaces/types and typed DI tokens (which
|
|
39
|
+
* *are* stable, safe-to-depend-on exports of the normal entry point). See
|
|
40
|
+
* `packages/capability-providers/source-map.md` and
|
|
41
|
+
* `ADS-memory/reports/security/SEC-remaining-backend-audit-2026-07-21.md`
|
|
42
|
+
* finding SEC-RB-006 for the audit that prompted this split.
|
|
43
|
+
*/
|
|
44
|
+
export * from './auth.js';
|
|
45
|
+
export * from './storage.js';
|
|
46
|
+
export * from './payments.js';
|
|
47
|
+
export * from './db.js';
|
|
48
|
+
export * from './realtime.js';
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/unsafe-reference/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@jini-ai/capability-providers/unsafe-reference` — UNSAFE, NON-PRODUCTION
|
|
3
|
+
* reference implementations. Read this before importing anything from this
|
|
4
|
+
* directory.
|
|
5
|
+
*
|
|
6
|
+
* Every factory exported from this module (`createInMemoryAuthProvider`,
|
|
7
|
+
* `createInMemoryStorageProvider`, `createInMemoryPaymentsProvider`,
|
|
8
|
+
* `createInMemoryDbProvider`, `createInMemoryRealtimeProvider`) is a
|
|
9
|
+
* minimal, non-cryptographic, in-memory reference stub whose only purpose
|
|
10
|
+
* is to prove that the corresponding port interface in the package's normal
|
|
11
|
+
* entry point (`@jini-ai/capability-providers`) is genuinely implementable and
|
|
12
|
+
* unit-testable. None of them is, or is intended to become, a production
|
|
13
|
+
* adapter:
|
|
14
|
+
*
|
|
15
|
+
* - `createInMemoryAuthProvider` stores passwords in plaintext and issues
|
|
16
|
+
* predictable, incrementing `user-N`/`session-N` identifiers — no
|
|
17
|
+
* hashing, no secure randomness, no rate limiting, no password policy.
|
|
18
|
+
* - `createInMemoryPaymentsProvider` deterministically succeeds every
|
|
19
|
+
* charge (rejecting only a non-positive amount) — no real money moves,
|
|
20
|
+
* no idempotency, no replay protection.
|
|
21
|
+
* - `createInMemoryStorageProvider`, `createInMemoryDbProvider`, and
|
|
22
|
+
* `createInMemoryRealtimeProvider` have no principal/tenant/ACL
|
|
23
|
+
* dimension, no quotas, and no size bounds — all state is unbounded,
|
|
24
|
+
* process-local memory.
|
|
25
|
+
*
|
|
26
|
+
* Do not wire any of these into anything that handles real credentials,
|
|
27
|
+
* payments, or user data — not behind a feature flag, not "just for now,"
|
|
28
|
+
* not in a demo that might get deployed. If you need a real adapter,
|
|
29
|
+
* implement the port interface (`AuthProvider`, `PaymentsProvider`,
|
|
30
|
+
* `StorageProvider`, `DbProvider`, `RealtimeProvider`) against an actual
|
|
31
|
+
* provider (Supabase, Auth0, Stripe, S3, a real Postgres/SQLite-backed
|
|
32
|
+
* store, etc.) instead.
|
|
33
|
+
*
|
|
34
|
+
* This is why these implementations live at the separate
|
|
35
|
+
* `@jini-ai/capability-providers/unsafe-reference` import path rather than the
|
|
36
|
+
* package's normal `@jini-ai/capability-providers` barrel: importing them
|
|
37
|
+
* requires opting in to this path by name, so they can't be pulled in by
|
|
38
|
+
* accident alongside the port interfaces/types and typed DI tokens (which
|
|
39
|
+
* *are* stable, safe-to-depend-on exports of the normal entry point). See
|
|
40
|
+
* `packages/capability-providers/source-map.md` and
|
|
41
|
+
* `ADS-memory/reports/security/SEC-remaining-backend-audit-2026-07-21.md`
|
|
42
|
+
* finding SEC-RB-006 for the audit that prompted this split.
|
|
43
|
+
*/
|
|
44
|
+
export * from './auth.js';
|
|
45
|
+
export * from './storage.js';
|
|
46
|
+
export * from './payments.js';
|
|
47
|
+
export * from './db.js';
|
|
48
|
+
export * from './realtime.js';
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/unsafe-reference/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UNSAFE REFERENCE IMPLEMENTATION — not production code. See the header
|
|
3
|
+
* comment in `src/unsafe-reference/index.ts` for the full warning; the
|
|
4
|
+
* short version: `createInMemoryPaymentsProvider` deterministically
|
|
5
|
+
* succeeds every charge (rejecting only a non-positive amount) — no
|
|
6
|
+
* idempotency, no replay protection, no real money movement. It exists
|
|
7
|
+
* only to prove `PaymentsProvider` (defined in `../payments.ts`) is
|
|
8
|
+
* implementable and unit-testable. Never wire this into anything that
|
|
9
|
+
* handles real payments.
|
|
10
|
+
*
|
|
11
|
+
* A real adapter (Stripe, a payment processor) implements the same
|
|
12
|
+
* `PaymentsProvider` interface without importing this file.
|
|
13
|
+
*/
|
|
14
|
+
import type { PaymentsProvider } from '../payments.js';
|
|
15
|
+
/** Creates the in-memory reference `PaymentsProvider`. No persistence, no real money movement. */
|
|
16
|
+
export declare function createInMemoryPaymentsProvider(): PaymentsProvider;
|
|
17
|
+
//# sourceMappingURL=payments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../../src/unsafe-reference/payments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAuB,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE5E,kGAAkG;AAClG,wBAAgB,8BAA8B,IAAI,gBAAgB,CAsCjE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Creates the in-memory reference `PaymentsProvider`. No persistence, no real money movement. */
|
|
2
|
+
export function createInMemoryPaymentsProvider() {
|
|
3
|
+
const charges = new Map();
|
|
4
|
+
let nextChargeId = 1;
|
|
5
|
+
return {
|
|
6
|
+
async charge(input) {
|
|
7
|
+
if (input.amountCents <= 0) {
|
|
8
|
+
throw new Error('amountCents must be positive');
|
|
9
|
+
}
|
|
10
|
+
const record = {
|
|
11
|
+
id: `charge-${nextChargeId++}`,
|
|
12
|
+
status: 'succeeded',
|
|
13
|
+
amountCents: input.amountCents,
|
|
14
|
+
currency: input.currency,
|
|
15
|
+
customerRef: input.customerRef,
|
|
16
|
+
createdAt: Date.now(),
|
|
17
|
+
};
|
|
18
|
+
charges.set(record.id, record);
|
|
19
|
+
return record;
|
|
20
|
+
},
|
|
21
|
+
async getCharge(id) {
|
|
22
|
+
return charges.get(id) ?? null;
|
|
23
|
+
},
|
|
24
|
+
async refund(id) {
|
|
25
|
+
const existing = charges.get(id);
|
|
26
|
+
if (!existing) {
|
|
27
|
+
throw new Error(`unknown charge: ${id}`);
|
|
28
|
+
}
|
|
29
|
+
if (existing.status !== 'succeeded') {
|
|
30
|
+
throw new Error(`charge ${id} is not refundable from status "${existing.status}"`);
|
|
31
|
+
}
|
|
32
|
+
const refunded = { ...existing, status: 'refunded' };
|
|
33
|
+
charges.set(id, refunded);
|
|
34
|
+
return refunded;
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=payments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.js","sourceRoot":"","sources":["../../src/unsafe-reference/payments.ts"],"names":[],"mappings":"AAeA,kGAAkG;AAClG,MAAM,UAAU,8BAA8B;IAC5C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,OAAO;QACL,KAAK,CAAC,MAAM,CAAC,KAAkB;YAC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
* UNSAFE REFERENCE IMPLEMENTATION — not production code. See the header
|
|
3
|
+
* comment in `src/unsafe-reference/index.ts` for the full warning; the
|
|
4
|
+
* short version: `createInMemoryRealtimeProvider` has no principal/tenant/
|
|
5
|
+
* channel-authorization dimension and retains subscribers in unbounded
|
|
6
|
+
* memory. It exists only to prove `RealtimeProvider` (defined in
|
|
7
|
+
* `../realtime.ts`) is implementable and unit-testable. Never wire this
|
|
8
|
+
* into anything that handles real user data.
|
|
9
|
+
*
|
|
10
|
+
* A real adapter (Supabase Realtime, a WebSocket/Redis pub-sub service)
|
|
11
|
+
* implements the same `RealtimeProvider` interface without importing this
|
|
12
|
+
* file.
|
|
13
|
+
*/
|
|
14
|
+
import type { RealtimeProvider } from '../realtime.js';
|
|
15
|
+
/** Creates the in-memory reference `RealtimeProvider`. Delivery is in-process only — no cross-process fan-out. */
|
|
16
|
+
export declare function createInMemoryRealtimeProvider(): RealtimeProvider;
|
|
17
|
+
//# sourceMappingURL=realtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realtime.d.ts","sourceRoot":"","sources":["../../src/unsafe-reference/realtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAmB,gBAAgB,EAAuB,MAAM,gBAAgB,CAAC;AAE7F,kHAAkH;AAClH,wBAAgB,8BAA8B,IAAI,gBAAgB,CAgCjE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Creates the in-memory reference `RealtimeProvider`. Delivery is in-process only — no cross-process fan-out. */
|
|
2
|
+
export function createInMemoryRealtimeProvider() {
|
|
3
|
+
const channels = new Map();
|
|
4
|
+
function subscribersFor(channel) {
|
|
5
|
+
let subscribers = channels.get(channel);
|
|
6
|
+
if (!subscribers) {
|
|
7
|
+
subscribers = new Set();
|
|
8
|
+
channels.set(channel, subscribers);
|
|
9
|
+
}
|
|
10
|
+
return subscribers;
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
async publish(channel, event) {
|
|
14
|
+
const subscribers = channels.get(channel);
|
|
15
|
+
if (!subscribers)
|
|
16
|
+
return;
|
|
17
|
+
for (const handler of [...subscribers]) {
|
|
18
|
+
handler(event);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
subscribe(channel, handler) {
|
|
22
|
+
const subscribers = subscribersFor(channel);
|
|
23
|
+
subscribers.add(handler);
|
|
24
|
+
let unsubscribed = false;
|
|
25
|
+
return () => {
|
|
26
|
+
if (unsubscribed)
|
|
27
|
+
return;
|
|
28
|
+
unsubscribed = true;
|
|
29
|
+
subscribers.delete(handler);
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=realtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"realtime.js","sourceRoot":"","sources":["../../src/unsafe-reference/realtime.ts"],"names":[],"mappings":"AAeA,kHAAkH;AAClH,MAAM,UAAU,8BAA8B;IAC5C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAgC,CAAC;IAEzD,SAAS,cAAc,CAAC,OAAe;QACrC,IAAI,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;YACxB,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACrC,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,OAAO;QACL,KAAK,CAAC,OAAO,CAAI,OAAe,EAAE,KAAQ;YACxC,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,CAAC,WAAW;gBAAE,OAAO;YACzB,KAAK,MAAM,OAAO,IAAI,CAAC,GAAG,WAAW,CAAC,EAAE,CAAC;gBACvC,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC;QACH,CAAC;QAED,SAAS,CAAI,OAAe,EAAE,OAA2B;YACvD,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;YAC5C,WAAW,CAAC,GAAG,CAAC,OAA0B,CAAC,CAAC;YAC5C,IAAI,YAAY,GAAG,KAAK,CAAC;YACzB,OAAO,GAAG,EAAE;gBACV,IAAI,YAAY;oBAAE,OAAO;gBACzB,YAAY,GAAG,IAAI,CAAC;gBACpB,WAAW,CAAC,MAAM,CAAC,OAA0B,CAAC,CAAC;YACjD,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UNSAFE REFERENCE IMPLEMENTATION — not production code. See the header
|
|
3
|
+
* comment in `src/unsafe-reference/index.ts` for the full warning; the
|
|
4
|
+
* short version: `createInMemoryStorageProvider` has no principal/tenant/
|
|
5
|
+
* ACL dimension, no quotas, and no size bounds. It exists only to prove
|
|
6
|
+
* `StorageProvider` (defined in `../storage.ts`) is implementable and
|
|
7
|
+
* unit-testable. Never wire this into anything that handles real user
|
|
8
|
+
* data.
|
|
9
|
+
*
|
|
10
|
+
* A real adapter (S3, R2, Supabase Storage, local disk) implements the
|
|
11
|
+
* same `StorageProvider` interface without importing this file.
|
|
12
|
+
*/
|
|
13
|
+
import type { StorageProvider } from '../storage.js';
|
|
14
|
+
/** Creates the in-memory reference `StorageProvider`. No persistence — state is lost on process exit. */
|
|
15
|
+
export declare function createInMemoryStorageProvider(): StorageProvider;
|
|
16
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/unsafe-reference/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAqB,eAAe,EAAqB,MAAM,eAAe,CAAC;AAE3F,yGAAyG;AACzG,wBAAgB,6BAA6B,IAAI,eAAe,CA+B/D"}
|