@peers-app/peers-sdk 0.16.4 → 0.16.6
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/user-context.js +6 -0
- package/dist/contracts/__tests__/builder.test.d.ts +1 -0
- package/dist/contracts/__tests__/builder.test.js +411 -0
- package/dist/contracts/__tests__/extract.test.d.ts +1 -0
- package/dist/contracts/__tests__/extract.test.js +145 -0
- package/dist/contracts/__tests__/integration.test.d.ts +1 -0
- package/dist/contracts/__tests__/integration.test.js +348 -0
- package/dist/contracts/__tests__/registry.test.d.ts +1 -0
- package/dist/contracts/__tests__/registry.test.js +324 -0
- package/dist/contracts/__tests__/validate.test.d.ts +1 -0
- package/dist/contracts/__tests__/validate.test.js +699 -0
- package/dist/contracts/builder.d.ts +97 -0
- package/dist/contracts/builder.js +211 -0
- package/dist/contracts/contract-providers.table.d.ts +40 -0
- package/dist/contracts/contract-providers.table.js +41 -0
- package/dist/contracts/contracts.table.d.ts +44 -0
- package/dist/contracts/contracts.table.js +44 -0
- package/dist/contracts/extract.d.ts +46 -0
- package/dist/contracts/extract.js +51 -0
- package/dist/contracts/index.d.ts +9 -0
- package/dist/contracts/index.js +31 -0
- package/dist/contracts/persistent-registry.d.ts +32 -0
- package/dist/contracts/persistent-registry.js +138 -0
- package/dist/contracts/registry.d.ts +58 -0
- package/dist/contracts/registry.js +155 -0
- package/dist/contracts/types.d.ts +108 -0
- package/dist/contracts/types.js +10 -0
- package/dist/contracts/validate.d.ts +24 -0
- package/dist/contracts/validate.js +274 -0
- package/dist/data/assistants.d.ts +5 -0
- package/dist/data/assistants.js +1 -0
- package/dist/data/package-versions.d.ts +2 -2
- package/dist/data/persistent-vars.d.ts +3 -0
- package/dist/data/persistent-vars.js +17 -2
- package/dist/data/tools.d.ts +4 -0
- package/dist/data/tools.js +1 -0
- package/dist/data/workflows.d.ts +1 -0
- package/dist/events.d.ts +13 -0
- package/dist/events.js +218 -34
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/package-loader/contract-package-loader.d.ts +23 -0
- package/dist/package-loader/contract-package-loader.js +65 -0
- package/dist/package-loader/index.d.ts +1 -0
- package/dist/package-loader/index.js +1 -0
- package/dist/package-loader/package-loader.d.ts +11 -0
- package/dist/package-loader/package-loader.js +59 -8
- package/dist/rpc-types.d.ts +4 -0
- package/dist/rpc-types.js +5 -4
- package/dist/types/workflow.d.ts +3 -0
- package/dist/types/workflow.js +1 -0
- package/dist/utils.d.ts +15 -0
- package/dist/utils.js +39 -0
- package/package.json +1 -1
package/dist/utils.js
CHANGED
|
@@ -9,6 +9,8 @@ exports.idDate = idDate;
|
|
|
9
9
|
exports.idRandNums = idRandNums;
|
|
10
10
|
exports.simpleHash = simpleHash;
|
|
11
11
|
exports.simpleObjectHash = simpleObjectHash;
|
|
12
|
+
exports.deterministicPvarId = deterministicPvarId;
|
|
13
|
+
exports.isDeterministicPvarId = isDeterministicPvarId;
|
|
12
14
|
exports.sleep = sleep;
|
|
13
15
|
exports.camelCaseToSpaces = camelCaseToSpaces;
|
|
14
16
|
exports.camelCaseToHyphens = camelCaseToHyphens;
|
|
@@ -119,6 +121,43 @@ function simpleHash(str) {
|
|
|
119
121
|
function simpleObjectHash(obj) {
|
|
120
122
|
return simpleHash(stableStringify(obj));
|
|
121
123
|
}
|
|
124
|
+
/** Well-known prefix for deterministic persistent variable IDs. */
|
|
125
|
+
const DETERMINISTIC_PVAR_PREFIX = "000pvar0";
|
|
126
|
+
/**
|
|
127
|
+
* Converts a byte array to a base-36 string of the requested length, using unbiased modular reduction.
|
|
128
|
+
* Bytes >= 252 are skipped to avoid bias (same technique as {@link cryptoRandomString}).
|
|
129
|
+
*/
|
|
130
|
+
function bytesToBase36(bytes, length) {
|
|
131
|
+
let s = "";
|
|
132
|
+
for (let i = 0; i < bytes.length && s.length < length; i++) {
|
|
133
|
+
const n = bytes[i];
|
|
134
|
+
if (n >= 252)
|
|
135
|
+
continue;
|
|
136
|
+
s += (n % 36).toString(36);
|
|
137
|
+
}
|
|
138
|
+
return s.substring(0, length);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Generates a deterministic 25-character peer ID for a persistent variable.
|
|
142
|
+
* The ID has the fixed prefix `000pvar0` (8 chars) followed by 17 base-36 characters
|
|
143
|
+
* derived from a SHA-512 hash of the input name. Two calls with the same name always
|
|
144
|
+
* return the same ID.
|
|
145
|
+
*
|
|
146
|
+
* @param name The persistent variable name as stored in the database
|
|
147
|
+
* (already includes group suffixes for groupDevice/groupUser scopes)
|
|
148
|
+
*/
|
|
149
|
+
function deterministicPvarId(name) {
|
|
150
|
+
const hashSuffixLength = 25 - DETERMINISTIC_PVAR_PREFIX.length; // 17
|
|
151
|
+
const hash = nacl.hash(new TextEncoder().encode(name)); // 64-byte SHA-512
|
|
152
|
+
return DETERMINISTIC_PVAR_PREFIX + bytesToBase36(hash, hashSuffixLength);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Returns whether a peer ID was generated by {@link deterministicPvarId}
|
|
156
|
+
* (starts with the `000pvar0` prefix).
|
|
157
|
+
*/
|
|
158
|
+
function isDeterministicPvarId(id) {
|
|
159
|
+
return id.startsWith(DETERMINISTIC_PVAR_PREFIX);
|
|
160
|
+
}
|
|
122
161
|
/** Resolves after `ms` milliseconds (0 yields a microtask-yield on most runtimes). */
|
|
123
162
|
function sleep(ms = 0) {
|
|
124
163
|
return new Promise((resolve) => setTimeout(resolve, ms));
|