orez-sync-executor 0.11.1 → 0.11.2
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/realtime/host.d.ts +7 -0
- package/dist/realtime/host.d.ts.map +1 -0
- package/dist/realtime/host.js +77 -0
- package/dist/realtime/host.js.map +1 -0
- package/dist/realtime/hub.d.ts +67 -0
- package/dist/realtime/hub.d.ts.map +1 -0
- package/dist/realtime/hub.js +456 -0
- package/dist/realtime/hub.js.map +1 -0
- package/dist/realtime/index.d.ts +24 -0
- package/dist/realtime/index.d.ts.map +1 -0
- package/dist/realtime/index.js +27 -0
- package/dist/realtime/index.js.map +1 -0
- package/dist/realtime/local.d.ts +15 -0
- package/dist/realtime/local.d.ts.map +1 -0
- package/dist/realtime/local.js +63 -0
- package/dist/realtime/local.js.map +1 -0
- package/dist/realtime/manifest.d.ts +51 -0
- package/dist/realtime/manifest.d.ts.map +1 -0
- package/dist/realtime/manifest.js +110 -0
- package/dist/realtime/manifest.js.map +1 -0
- package/dist/realtime/message-port.d.ts +34 -0
- package/dist/realtime/message-port.d.ts.map +1 -0
- package/dist/realtime/message-port.js +141 -0
- package/dist/realtime/message-port.js.map +1 -0
- package/dist/realtime/producer-socket.d.ts +10 -0
- package/dist/realtime/producer-socket.d.ts.map +1 -0
- package/dist/realtime/producer-socket.js +90 -0
- package/dist/realtime/producer-socket.js.map +1 -0
- package/dist/realtime/producer.d.ts +16 -0
- package/dist/realtime/producer.d.ts.map +1 -0
- package/dist/realtime/producer.js +51 -0
- package/dist/realtime/producer.js.map +1 -0
- package/dist/realtime/protocol.d.ts +99 -0
- package/dist/realtime/protocol.d.ts.map +1 -0
- package/dist/realtime/protocol.js +191 -0
- package/dist/realtime/protocol.js.map +1 -0
- package/dist/realtime/publisher.d.ts +28 -0
- package/dist/realtime/publisher.d.ts.map +1 -0
- package/dist/realtime/publisher.js +309 -0
- package/dist/realtime/publisher.js.map +1 -0
- package/dist/realtime/socket-host.d.ts +25 -0
- package/dist/realtime/socket-host.d.ts.map +1 -0
- package/dist/realtime/socket-host.js +105 -0
- package/dist/realtime/socket-host.js.map +1 -0
- package/dist/realtime/store.d.ts +28 -0
- package/dist/realtime/store.d.ts.map +1 -0
- package/dist/realtime/store.js +0 -0
- package/dist/realtime/store.js.map +1 -0
- package/dist/realtime/writer.d.ts +17 -0
- package/dist/realtime/writer.d.ts.map +1 -0
- package/dist/realtime/writer.js +138 -0
- package/dist/realtime/writer.js.map +1 -0
- package/package.json +5 -1
- package/dist/adapters.d.ts +0 -25
- package/dist/adapters.d.ts.map +0 -1
- package/dist/adapters.js +0 -116
- package/dist/adapters.js.map +0 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// Imperative field writing, for producers that think in "here is the current
|
|
2
|
+
// value of this row's field" rather than in stream generations.
|
|
3
|
+
//
|
|
4
|
+
// The session API underneath is explicit on purpose: a generation has a
|
|
5
|
+
// beginning, a commit, and an end, and a cross-client producer needs to control
|
|
6
|
+
// all three. But most producer code is a loop that already holds the whole
|
|
7
|
+
// current value and just wants it on screen. Soot's agent loop is exactly this
|
|
8
|
+
// shape (`setStreamingMessageText(id, text)` on every model event), and making
|
|
9
|
+
// it open, track, and close a session per message would be bookkeeping the
|
|
10
|
+
// writer can do instead.
|
|
11
|
+
//
|
|
12
|
+
// Generations are opened lazily on the first `set` for a topic and closed by
|
|
13
|
+
// `finish` or `abort`. A `set` after a finish opens a NEW generation, which is
|
|
14
|
+
// the same rule the hub applies: a later generation supersedes an earlier one.
|
|
15
|
+
import { canonicalTopic } from './protocol.js';
|
|
16
|
+
export class FieldWriter {
|
|
17
|
+
#publisher;
|
|
18
|
+
#onError;
|
|
19
|
+
#entries = new Map();
|
|
20
|
+
constructor(publisher, options = {}) {
|
|
21
|
+
this.#publisher = publisher;
|
|
22
|
+
this.#onError =
|
|
23
|
+
options.onError ??
|
|
24
|
+
((error, topic) => {
|
|
25
|
+
console.error(`orez realtime write failed for ${topic.table}.${topic.field}`, error);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// The handle already carries its spec, so a call site cannot name a field
|
|
29
|
+
// that is not in the manifest and there is nothing to look up per write.
|
|
30
|
+
#id(handle) {
|
|
31
|
+
return canonicalTopic(handle.spec.primaryKey, handle.topic);
|
|
32
|
+
}
|
|
33
|
+
// Publish the field's current value. Synchronous and safe to call on every
|
|
34
|
+
// token: the first call opens a generation in the background, later calls
|
|
35
|
+
// reach the open session directly.
|
|
36
|
+
set(handle, value) {
|
|
37
|
+
const { topic } = handle;
|
|
38
|
+
const id = this.#id(handle);
|
|
39
|
+
const existing = this.#entries.get(id);
|
|
40
|
+
if (existing && !existing.closed) {
|
|
41
|
+
if (existing.session) {
|
|
42
|
+
try {
|
|
43
|
+
existing.session.set(value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
this.#fail(id, error, topic);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
existing.queued = value;
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const entry = {
|
|
55
|
+
session: undefined,
|
|
56
|
+
queued: value,
|
|
57
|
+
opening: undefined,
|
|
58
|
+
closed: false,
|
|
59
|
+
};
|
|
60
|
+
this.#entries.set(id, entry);
|
|
61
|
+
entry.opening = this.#publisher
|
|
62
|
+
.begin(topic.table, topic.field, { namespace: '', key: topic.key })
|
|
63
|
+
.then((session) => {
|
|
64
|
+
// the writer may have been closed while begin was in flight
|
|
65
|
+
if (this.#entries.get(id) !== entry) {
|
|
66
|
+
void session.abort();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
entry.session = session;
|
|
70
|
+
if (entry.queued !== undefined)
|
|
71
|
+
session.set(entry.queued);
|
|
72
|
+
})
|
|
73
|
+
.catch((error) => this.#fail(id, error, topic));
|
|
74
|
+
}
|
|
75
|
+
// Deliver pending values for one topic, honouring its rate bounds.
|
|
76
|
+
async flush(handle) {
|
|
77
|
+
const entry = this.#entries.get(this.#id(handle));
|
|
78
|
+
if (!entry)
|
|
79
|
+
return;
|
|
80
|
+
await entry.opening;
|
|
81
|
+
await entry.session?.flush();
|
|
82
|
+
}
|
|
83
|
+
// Close the generation: flush the final value, run the application's durable
|
|
84
|
+
// write, then tell subscribers to hold the overlay until Zero produces it.
|
|
85
|
+
async finish(handle, value, commit) {
|
|
86
|
+
const id = this.#id(handle);
|
|
87
|
+
const entry = this.#entries.get(id);
|
|
88
|
+
if (!entry || entry.closed) {
|
|
89
|
+
// nothing was ever streamed for this row; the durable write still has to
|
|
90
|
+
// happen, and it is the only thing that matters
|
|
91
|
+
await commit();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
entry.closed = true;
|
|
95
|
+
await entry.opening;
|
|
96
|
+
this.#entries.delete(id);
|
|
97
|
+
if (!entry.session) {
|
|
98
|
+
await commit();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
await entry.session.finish(value, commit);
|
|
102
|
+
}
|
|
103
|
+
// Drop the overlay now and reveal the durable row. Used when a run is
|
|
104
|
+
// cancelled or errors: there is no value worth showing.
|
|
105
|
+
async abort(handle) {
|
|
106
|
+
const id = this.#id(handle);
|
|
107
|
+
const entry = this.#entries.get(id);
|
|
108
|
+
if (!entry || entry.closed)
|
|
109
|
+
return;
|
|
110
|
+
entry.closed = true;
|
|
111
|
+
this.#entries.delete(id);
|
|
112
|
+
await entry.opening;
|
|
113
|
+
await entry.session?.abort();
|
|
114
|
+
}
|
|
115
|
+
isStreaming(handle) {
|
|
116
|
+
const entry = this.#entries.get(this.#id(handle));
|
|
117
|
+
return !!entry && !entry.closed;
|
|
118
|
+
}
|
|
119
|
+
// Abort every open generation. For a producer shutting down: without it,
|
|
120
|
+
// subscribers would wait out their inactivity deadline before revealing the
|
|
121
|
+
// durable value.
|
|
122
|
+
async abortAll() {
|
|
123
|
+
const entries = [...this.#entries.values()];
|
|
124
|
+
this.#entries.clear();
|
|
125
|
+
await Promise.all(entries.map(async (entry) => {
|
|
126
|
+
if (entry.closed)
|
|
127
|
+
return;
|
|
128
|
+
entry.closed = true;
|
|
129
|
+
await entry.opening;
|
|
130
|
+
await entry.session?.abort();
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
#fail(id, error, topic) {
|
|
134
|
+
this.#entries.delete(id);
|
|
135
|
+
this.#onError(error instanceof Error ? error : new Error(String(error)), topic);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writer.js","sourceRoot":"","sources":["../../src/realtime/writer.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,gEAAgE;AAChE,EAAE;AACF,wEAAwE;AACxE,gFAAgF;AAChF,2EAA2E;AAC3E,+EAA+E;AAC/E,+EAA+E;AAC/E,2EAA2E;AAC3E,yBAAyB;AACzB,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,+EAA+E;AAE/E,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAqB9C,MAAM,OAAO,WAAW;IACb,UAAU,CAAmB;IAC7B,QAAQ,CAA8C;IACtD,QAAQ,GAAG,IAAI,GAAG,EAAiB,CAAA;IAE5C,YAAY,SAA4B,EAAE,UAA8B,EAAE;QACxE,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;QAC3B,IAAI,CAAC,QAAQ;YACX,OAAO,CAAC,OAAO;gBACf,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;oBAChB,OAAO,CAAC,KAAK,CACX,kCAAkC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,EAC9D,KAAK,CACN,CAAA;gBACH,CAAC,CAAC,CAAA;IACN,CAAC;IAED,0EAA0E;IAC1E,yEAAyE;IACzE,GAAG,CAAC,MAA4B;QAC9B,OAAO,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,MA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M,GAAG,IAAI,CAAA;YACnB,MAAM,KAAK,CAAC,OAAO,CAAA;YACnB,MAAM,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,CAAA;QAC9B,CAAC,CAAC,CACH,CAAA;IACH,CAAC;IAED,KAAK,CAAC,EAAU,EAAE,KAAc,EAAE,KAAoB;QACpD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QACxB,IAAI,CAAC,QAAQ,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;IACjF,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orez-sync-executor",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
"./sqlite": {
|
|
20
20
|
"types": "./dist/sqlite.d.ts",
|
|
21
21
|
"import": "./dist/sqlite.js"
|
|
22
|
+
},
|
|
23
|
+
"./realtime": {
|
|
24
|
+
"types": "./dist/realtime/index.d.ts",
|
|
25
|
+
"import": "./dist/realtime/index.js"
|
|
22
26
|
}
|
|
23
27
|
},
|
|
24
28
|
"scripts": {
|
package/dist/adapters.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { ApplicationDatabase, ApplicationTransaction, JsonValue, TransactionQueryFormat } from './types.js';
|
|
2
|
-
import type { Schema } from '@rocicorp/zero';
|
|
3
|
-
export type PostgreSQLQueryResult<Row extends Record<string, unknown>> = {
|
|
4
|
-
readonly rows: readonly Row[];
|
|
5
|
-
readonly rowCount?: number | null;
|
|
6
|
-
};
|
|
7
|
-
export type PostgreSQLClient = {
|
|
8
|
-
query<Row extends Record<string, unknown> = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<PostgreSQLQueryResult<Row>>;
|
|
9
|
-
release(): void;
|
|
10
|
-
};
|
|
11
|
-
export type PostgreSQLPool = {
|
|
12
|
-
connect(): Promise<PostgreSQLClient>;
|
|
13
|
-
query<Row extends Record<string, unknown> = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<PostgreSQLQueryResult<Row>>;
|
|
14
|
-
};
|
|
15
|
-
export type PostgreSQLApplicationDatabaseOptions = {
|
|
16
|
-
readonly internalSchema?: string;
|
|
17
|
-
readonly schema?: Schema;
|
|
18
|
-
readonly queryAst?: <Result>(tx: PostgreSQLClient, ast: JsonValue, format: TransactionQueryFormat, queryName?: string) => Promise<Result>;
|
|
19
|
-
};
|
|
20
|
-
export declare function createPostgreSQLApplicationDatabase(pool: PostgreSQLPool, options?: PostgreSQLApplicationDatabaseOptions): ApplicationDatabase;
|
|
21
|
-
export declare function createSQLiteApplicationDatabase(options: {
|
|
22
|
-
transaction<Value>(work: (tx: ApplicationTransaction) => Value | Promise<Value>): Promise<Value>;
|
|
23
|
-
query<Row extends Record<string, unknown> = Record<string, unknown>>(sql: string, params?: readonly unknown[]): Promise<readonly Row[]>;
|
|
24
|
-
}): ApplicationDatabase;
|
|
25
|
-
//# sourceMappingURL=adapters.d.ts.map
|
package/dist/adapters.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../src/adapters.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EAEtB,SAAS,EAET,sBAAsB,EACvB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAA8B,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGxE,MAAM,MAAM,qBAAqB,CAAC,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IACvE,QAAQ,CAAC,IAAI,EAAE,SA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AAE,CAAC,EAAE,EAAE,sBAAsB,KAAK,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAC3D,OAAO,CAAC,KAAK,CAAC,CAAA;IACjB,KAAK,CAAC,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjE,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAC1B,OAAO,CAAC,SAAS,GAAG,EAAE,CAAC,CAAA;CAC3B,GAAG,mBAAmB,CAEtB"}
|
package/dist/adapters.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { executePostgresQuery } from '@rocicorp/zero/server';
|
|
2
|
-
export function createPostgreSQLApplicationDatabase(pool, options = {}) {
|
|
3
|
-
let serverSchema;
|
|
4
|
-
async function introspectServerSchema(client) {
|
|
5
|
-
if (!options.schema) {
|
|
6
|
-
throw new TypeError('PostgreSQL application database requires schema or queryAst for ZQL reads');
|
|
7
|
-
}
|
|
8
|
-
const tables = Object.values(options.schema.tables).map((table) => {
|
|
9
|
-
const serverName = table.serverName ?? table.name;
|
|
10
|
-
const period = serverName.indexOf('.');
|
|
11
|
-
return period < 0
|
|
12
|
-
? { schema: 'public', table: serverName }
|
|
13
|
-
: {
|
|
14
|
-
schema: serverName.slice(0, period),
|
|
15
|
-
table: serverName.slice(period + 1),
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
if (tables.length === 0)
|
|
19
|
-
return {};
|
|
20
|
-
const params = tables.flatMap((table) => [table.schema, table.table]);
|
|
21
|
-
const where = tables
|
|
22
|
-
.map((_, index) => `(c.table_schema = $${index * 2 + 1} AND c.table_name = $${index * 2 + 2})`)
|
|
23
|
-
.join(' OR ');
|
|
24
|
-
const rows = (await client.query(`SELECT
|
|
25
|
-
c.table_schema::text AS schema,
|
|
26
|
-
c.table_name::text AS table,
|
|
27
|
-
c.column_name::text AS column,
|
|
28
|
-
c.data_type::text AS "dataType",
|
|
29
|
-
t.typtype::text AS typtype,
|
|
30
|
-
t.typname::text AS typename,
|
|
31
|
-
CASE WHEN t.typelem <> 0 THEN et.typtype::text ELSE NULL END AS "elemTyptype",
|
|
32
|
-
CASE WHEN t.typelem <> 0 THEN et.typname::text ELSE NULL END AS "elemTypname"
|
|
33
|
-
FROM information_schema.columns c
|
|
34
|
-
JOIN pg_catalog.pg_type t ON c.udt_name = t.typname
|
|
35
|
-
LEFT JOIN pg_catalog.pg_type et ON t.typelem = et.oid
|
|
36
|
-
JOIN pg_catalog.pg_namespace n ON t.typnamespace = n.oid
|
|
37
|
-
WHERE ${where}`, params)).rows;
|
|
38
|
-
const result = {};
|
|
39
|
-
for (const row of rows) {
|
|
40
|
-
const tableName = row.schema === 'public' ? row.table : `${row.schema}.${row.table}`;
|
|
41
|
-
const table = (result[tableName] ??= {});
|
|
42
|
-
const isArray = row.elemTyptype !== null;
|
|
43
|
-
const isEnum = (row.elemTyptype ?? row.typtype) === 'e';
|
|
44
|
-
table[row.column] = {
|
|
45
|
-
type: isArray
|
|
46
|
-
? (row.elemTypname ?? row.dataType.toLowerCase())
|
|
47
|
-
: isEnum
|
|
48
|
-
? row.typename
|
|
49
|
-
: row.dataType.toLowerCase(),
|
|
50
|
-
isArray,
|
|
51
|
-
isEnum,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
const transactionFor = (client) => ({
|
|
57
|
-
async exec(sql, params = [], _metadata) {
|
|
58
|
-
const result = await client.query(sql, params);
|
|
59
|
-
return { changes: result.rowCount ?? 0 };
|
|
60
|
-
},
|
|
61
|
-
async query(sql, params = []) {
|
|
62
|
-
return (await client.query(sql, params)).rows;
|
|
63
|
-
},
|
|
64
|
-
queryAst(ast, format, queryName) {
|
|
65
|
-
if (!options.queryAst) {
|
|
66
|
-
if (!options.schema) {
|
|
67
|
-
throw new TypeError('PostgreSQL application database requires schema or queryAst for ZQL reads');
|
|
68
|
-
}
|
|
69
|
-
serverSchema ??= introspectServerSchema(client);
|
|
70
|
-
const dbTransaction = {
|
|
71
|
-
wrappedTransaction: client,
|
|
72
|
-
async query(sql, params) {
|
|
73
|
-
return (await client.query(sql, params)).rows;
|
|
74
|
-
},
|
|
75
|
-
runQuery(queryAst, queryFormat, schema, resolvedServerSchema) {
|
|
76
|
-
return executePostgresQuery(this, queryAst, queryFormat, schema, resolvedServerSchema);
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
return serverSchema.then((resolved) => executePostgresQuery(dbTransaction, ast, format, options.schema, resolved));
|
|
80
|
-
}
|
|
81
|
-
return options.queryAst(client, ast, format, queryName);
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
return {
|
|
85
|
-
dialect: 'postgresql',
|
|
86
|
-
internalSchema: options.internalSchema,
|
|
87
|
-
async transaction(work) {
|
|
88
|
-
const client = await pool.connect();
|
|
89
|
-
try {
|
|
90
|
-
await client.query('BEGIN');
|
|
91
|
-
const result = await work(transactionFor(client));
|
|
92
|
-
await client.query('COMMIT');
|
|
93
|
-
return result;
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
try {
|
|
97
|
-
await client.query('ROLLBACK');
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
// preserve the application or commit error that caused the rollback.
|
|
101
|
-
}
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
finally {
|
|
105
|
-
client.release();
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
async query(sql, params = []) {
|
|
109
|
-
return (await pool.query(sql, params)).rows;
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
export function createSQLiteApplicationDatabase(options) {
|
|
114
|
-
return { dialect: 'sqlite', ...options };
|
|
115
|
-
}
|
|
116
|
-
//# sourceMappingURL=adapters.js.map
|
package/dist/adapters.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file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