@peers-app/peers-sdk 0.23.4 → 0.23.5
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/context/data-context.d.ts +36 -5
- package/dist/context/data-context.js +44 -9
- package/dist/context/user-context.d.ts +44 -0
- package/dist/context/user-context.js +91 -12
- package/dist/contracts/__tests__/contract-provider-router.test.js +26 -0
- package/dist/contracts/__tests__/contract-resolvers.test.js +44 -0
- package/dist/contracts/__tests__/registry.test.js +104 -0
- package/dist/contracts/contract-provider-router.d.ts +21 -0
- package/dist/contracts/contract-provider-router.js +31 -5
- package/dist/contracts/contract-proxy.d.ts +3 -0
- package/dist/contracts/contract-proxy.js +3 -0
- package/dist/contracts/contract-resolvers.d.ts +21 -3
- package/dist/contracts/contract-resolvers.js +105 -32
- package/dist/contracts/index.d.ts +3 -3
- package/dist/contracts/registry.d.ts +59 -0
- package/dist/contracts/registry.js +155 -25
- package/dist/contracts/system-contracts.js +3 -1
- package/dist/data/index.d.ts +1 -0
- package/dist/data/index.js +1 -0
- package/dist/data/orm/types.d.ts +19 -0
- package/dist/data/orm/types.js +11 -0
- package/dist/data/package-table-identity.d.ts +46 -0
- package/dist/data/package-table-identity.js +71 -0
- package/dist/data/package-table-identity.test.d.ts +1 -0
- package/dist/data/package-table-identity.test.js +46 -0
- package/dist/data/package-version-resolver.d.ts +13 -0
- package/dist/data/package-version-resolver.js +142 -6
- package/dist/data/package-version-resolver.test.js +42 -0
- package/dist/data/persistent-var-identity.d.ts +37 -0
- package/dist/data/persistent-var-identity.js +69 -0
- package/dist/data/persistent-vars.d.ts +3 -5
- package/dist/data/persistent-vars.js +25 -13
- package/dist/data/persistent-vars.package-scope.test.d.ts +1 -0
- package/dist/data/persistent-vars.package-scope.test.js +27 -0
- package/dist/data/tools.d.ts +3 -3
- package/dist/package-loader/contract-package-loader.js +20 -8
- package/dist/package-loader/contract-package-loader.test.js +16 -0
- package/dist/package-loader/index.d.ts +4 -0
- package/dist/package-loader/index.js +4 -0
- package/dist/package-loader/isolated-artifact.d.ts +233 -0
- package/dist/package-loader/isolated-artifact.js +643 -0
- package/dist/package-loader/isolated-artifact.test.d.ts +1 -0
- package/dist/package-loader/isolated-artifact.test.js +270 -0
- package/dist/package-loader/isolated-persistent-var-gateway.d.ts +20 -0
- package/dist/package-loader/isolated-persistent-var-gateway.js +106 -0
- package/dist/package-loader/isolated-persistent-var-gateway.test.d.ts +1 -0
- package/dist/package-loader/isolated-persistent-var-gateway.test.js +56 -0
- package/dist/package-loader/isolated-runtime.d.ts +229 -0
- package/dist/package-loader/isolated-runtime.js +37 -0
- package/dist/package-loader/isolated-table-gateway.d.ts +16 -0
- package/dist/package-loader/isolated-table-gateway.js +375 -0
- package/dist/package-loader/isolated-table-gateway.test.d.ts +1 -0
- package/dist/package-loader/isolated-table-gateway.test.js +206 -0
- package/dist/package-loader/isolated-value.d.ts +14 -0
- package/dist/package-loader/isolated-value.js +63 -0
- package/dist/package-loader/package-loader.d.ts +123 -4
- package/dist/package-loader/package-loader.js +417 -46
- package/dist/package-loader/package-loader.test.js +478 -12
- package/dist/package-loader/resolve-consumed-contracts.d.ts +3 -3
- package/dist/package-loader/resolve-consumed-contracts.js +18 -10
- package/dist/utils.d.ts +21 -2
- package/dist/utils.js +46 -7
- package/package.json +1 -1
package/dist/utils.js
CHANGED
|
@@ -11,6 +11,8 @@ exports.simpleHash = simpleHash;
|
|
|
11
11
|
exports.simpleObjectHash = simpleObjectHash;
|
|
12
12
|
exports.deterministicPvarId = deterministicPvarId;
|
|
13
13
|
exports.isDeterministicPvarId = isDeterministicPvarId;
|
|
14
|
+
exports.deterministicTableId = deterministicTableId;
|
|
15
|
+
exports.isDeterministicTableId = isDeterministicTableId;
|
|
14
16
|
exports.sleep = sleep;
|
|
15
17
|
exports.camelCaseToSpaces = camelCaseToSpaces;
|
|
16
18
|
exports.camelCaseToHyphens = camelCaseToHyphens;
|
|
@@ -123,6 +125,8 @@ function simpleObjectHash(obj) {
|
|
|
123
125
|
}
|
|
124
126
|
/** Well-known prefix for deterministic persistent variable IDs. */
|
|
125
127
|
const DETERMINISTIC_PVAR_PREFIX = "000pvar0";
|
|
128
|
+
/** Well-known prefix for deterministic package-table IDs. */
|
|
129
|
+
const DETERMINISTIC_TABLE_PREFIX = "000tbl00";
|
|
126
130
|
/**
|
|
127
131
|
* Converts a byte array to a base-36 string of the requested length, using unbiased modular reduction.
|
|
128
132
|
* Bytes >= 252 are skipped to avoid bias (same technique as {@link cryptoRandomString}).
|
|
@@ -137,6 +141,11 @@ function bytesToBase36(bytes, length) {
|
|
|
137
141
|
}
|
|
138
142
|
return s.substring(0, length);
|
|
139
143
|
}
|
|
144
|
+
function deterministicPeerId(prefix, input) {
|
|
145
|
+
const hashSuffixLength = 25 - prefix.length;
|
|
146
|
+
const hash = nacl.hash(new TextEncoder().encode(input));
|
|
147
|
+
return prefix + bytesToBase36(hash, hashSuffixLength);
|
|
148
|
+
}
|
|
140
149
|
/**
|
|
141
150
|
* Generates a deterministic 25-character peer ID for a persistent variable.
|
|
142
151
|
* The ID has the fixed prefix `000pvar0` (8 chars) followed by 17 base-36 characters
|
|
@@ -147,9 +156,7 @@ function bytesToBase36(bytes, length) {
|
|
|
147
156
|
* (already includes group suffixes for groupDevice/groupUser scopes)
|
|
148
157
|
*/
|
|
149
158
|
function deterministicPvarId(name) {
|
|
150
|
-
|
|
151
|
-
const hash = nacl.hash(new TextEncoder().encode(name)); // 64-byte SHA-512
|
|
152
|
-
return DETERMINISTIC_PVAR_PREFIX + bytesToBase36(hash, hashSuffixLength);
|
|
159
|
+
return deterministicPeerId(DETERMINISTIC_PVAR_PREFIX, name);
|
|
153
160
|
}
|
|
154
161
|
/**
|
|
155
162
|
* Returns whether a peer ID was generated by {@link deterministicPvarId}
|
|
@@ -158,6 +165,25 @@ function deterministicPvarId(name) {
|
|
|
158
165
|
function isDeterministicPvarId(id) {
|
|
159
166
|
return id.startsWith(DETERMINISTIC_PVAR_PREFIX);
|
|
160
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Generate a stable host-only peer ID for a package-owned table.
|
|
170
|
+
*
|
|
171
|
+
* The physical SQLite name is derived separately; this ID keys synced
|
|
172
|
+
* `TableDefinitions` metadata and never comes from isolated guest code.
|
|
173
|
+
*
|
|
174
|
+
* @param identity Stable package-scoped table identity.
|
|
175
|
+
*/
|
|
176
|
+
function deterministicTableId(identity) {
|
|
177
|
+
return deterministicPeerId(DETERMINISTIC_TABLE_PREFIX, identity);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Return whether a peer ID was generated by {@link deterministicTableId}.
|
|
181
|
+
*
|
|
182
|
+
* @param id Peer ID to inspect.
|
|
183
|
+
*/
|
|
184
|
+
function isDeterministicTableId(id) {
|
|
185
|
+
return id.startsWith(DETERMINISTIC_TABLE_PREFIX);
|
|
186
|
+
}
|
|
161
187
|
/** Resolves after `ms` milliseconds (0 yields a microtask-yield on most runtimes). */
|
|
162
188
|
function sleep(ms = 0) {
|
|
163
189
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -220,7 +246,11 @@ function memoizePromise(fn, opts) {
|
|
|
220
246
|
});
|
|
221
247
|
cache.set(key, promise);
|
|
222
248
|
}
|
|
223
|
-
|
|
249
|
+
const cached = cache.get(key);
|
|
250
|
+
if (cached === undefined) {
|
|
251
|
+
throw new Error("memoizePromise cache entry unexpectedly missing");
|
|
252
|
+
}
|
|
253
|
+
return cached;
|
|
224
254
|
};
|
|
225
255
|
return memoized;
|
|
226
256
|
}
|
|
@@ -292,7 +322,9 @@ async function retryOnErrorOrTimeout({ fn, connection, opts = {}, }) {
|
|
|
292
322
|
}),
|
|
293
323
|
sleepPromise,
|
|
294
324
|
]);
|
|
295
|
-
|
|
325
|
+
if (sleepTimeout !== null) {
|
|
326
|
+
clearTimeout(sleepTimeout);
|
|
327
|
+
}
|
|
296
328
|
if (resultSet) {
|
|
297
329
|
const totalTime = Date.now() - startTime;
|
|
298
330
|
connection.latencyMs = totalTime * 0.1 + connection.latencyMs * 0.9;
|
|
@@ -329,9 +361,16 @@ async function retryOnErrorOrTimeout({ fn, connection, opts = {}, }) {
|
|
|
329
361
|
}
|
|
330
362
|
}
|
|
331
363
|
/**
|
|
332
|
-
*
|
|
333
|
-
*
|
|
364
|
+
* Return a table's physical storage name.
|
|
365
|
+
*
|
|
366
|
+
* Trusted package-scoped metadata uses `"name_packageId"`; every existing
|
|
367
|
+
* table continues to use `"name_tableId"` (or just `"name"` for system tables).
|
|
368
|
+
*
|
|
369
|
+
* @param metaData Table metadata from the ORM layer.
|
|
334
370
|
*/
|
|
335
371
|
function getFullTableName(metaData) {
|
|
372
|
+
if (metaData.packageId) {
|
|
373
|
+
return `${metaData.name}_${metaData.packageId}`;
|
|
374
|
+
}
|
|
336
375
|
return [metaData.name, metaData.tableId].filter((v) => v && v.length > 0).join("_");
|
|
337
376
|
}
|