@peers-app/peers-sdk 0.12.6 → 0.13.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.
@@ -141,7 +141,6 @@ rpc_types_1.rpcServerCalls.getFileContentsBase64 = async (fileId) => {
141
141
  rpc_types_1.rpcServerCalls.saveFile = async (input) => {
142
142
  const fileId = input.fileId || (0, utils_1.newid)();
143
143
  const encoding = input.encoding || 'utf8';
144
- // Convert data to Uint8Array based on encoding
145
144
  const dataBuffer = encoding === 'base64'
146
145
  ? Buffer.from(input.data, 'base64')
147
146
  : Buffer.from(input.data, 'utf8');
@@ -2,5 +2,9 @@
2
2
  * Decorator that marks a table method as server-side only.
3
3
  * When used on the client side, these methods will be automatically proxied
4
4
  * to the server via rpcServerCalls.tableMethodCall.
5
+ *
6
+ * The original (unproxied) method is stored on the proxy function as `__original`
7
+ * so that same-process implementations (e.g. PWA) can call it directly and avoid
8
+ * an infinite proxy loop.
5
9
  */
6
10
  export declare function ProxyClientTableMethodCalls(): (target: any, context: any) => any;
@@ -6,16 +6,22 @@ const rpc_types_1 = require("../../rpc-types");
6
6
  * Decorator that marks a table method as server-side only.
7
7
  * When used on the client side, these methods will be automatically proxied
8
8
  * to the server via rpcServerCalls.tableMethodCall.
9
+ *
10
+ * The original (unproxied) method is stored on the proxy function as `__original`
11
+ * so that same-process implementations (e.g. PWA) can call it directly and avoid
12
+ * an infinite proxy loop.
9
13
  */
10
14
  function ProxyClientTableMethodCalls() {
11
15
  return function (target, context) {
12
16
  if (context.kind === 'method' && rpc_types_1.isClient) {
13
17
  const methodName = context.name;
14
18
  // WARNING: Using typescript's magical `this` param
15
- return function (...args) {
19
+ const proxyFn = function (...args) {
16
20
  const dataContextId = this.dataSource.dataContextId || this.groupId || '';
17
21
  return rpc_types_1.rpcServerCalls.tableMethodCall(dataContextId, this.tableName, methodName, ...args);
18
22
  };
23
+ proxyFn.__original = target;
24
+ return proxyFn;
19
25
  }
20
26
  return target;
21
27
  };
@@ -33,7 +33,7 @@ class Table {
33
33
  const eventName = this.tableName + "_DataChanged";
34
34
  this.dataChangedEmitter = deps.eventRegistry.getEmitter(eventName);
35
35
  this.dataChanged = this.dataChangedEmitter.event;
36
- if (rpc_types_1.isClient) {
36
+ if (rpc_types_1.isClient && !(0, rpc_types_1.isSingleProcessClient)()) {
37
37
  // Don't emit table events from client (they are just duplicates from server)
38
38
  this.dataChangedEmitter.emit = lodash_1.noop;
39
39
  }
@@ -92,5 +92,9 @@ export declare function PackageVersions(dataContext?: DataContext): PackageVersi
92
92
  */
93
93
  export declare function computePackageVersionHash(version: string, versionTag: string, packageBundleFileHash: string, routesBundleFileHash?: string, uiBundleFileHash?: string): string;
94
94
  export declare function isVersionInRange(activeVersion: string, incomingVersion: string, range: 'pinned' | 'patch' | 'minor' | 'latest'): boolean;
95
+ /**
96
+ * Returns true if incomingVersion is strictly newer than activeVersion (semver comparison).
97
+ */
98
+ export declare function isNewerVersion(activeVersion: string, incomingVersion: string): boolean;
95
99
  export declare function doesTagMatch(activeVersionTag: string | undefined, incomingVersionTag: string | undefined, followVersionTags: string | undefined, deviceVersionTag: string | undefined): boolean;
96
100
  export {};
@@ -38,6 +38,7 @@ exports.PackageVersionsTable = void 0;
38
38
  exports.PackageVersions = PackageVersions;
39
39
  exports.computePackageVersionHash = computePackageVersionHash;
40
40
  exports.isVersionInRange = isVersionInRange;
41
+ exports.isNewerVersion = isNewerVersion;
41
42
  exports.doesTagMatch = doesTagMatch;
42
43
  const zod_1 = require("zod");
43
44
  const context_1 = require("../context");
@@ -149,6 +150,18 @@ function isVersionInRange(activeVersion, incomingVersion, range) {
149
150
  return aMaj === iMaj;
150
151
  return false;
151
152
  }
153
+ /**
154
+ * Returns true if incomingVersion is strictly newer than activeVersion (semver comparison).
155
+ */
156
+ function isNewerVersion(activeVersion, incomingVersion) {
157
+ const [aMaj = 0, aMin = 0, aPat = 0] = activeVersion.split('.').map(Number);
158
+ const [iMaj = 0, iMin = 0, iPat = 0] = incomingVersion.split('.').map(Number);
159
+ if (iMaj !== aMaj)
160
+ return iMaj > aMaj;
161
+ if (iMin !== aMin)
162
+ return iMin > aMin;
163
+ return iPat > aPat;
164
+ }
152
165
  function doesTagMatch(activeVersionTag, incomingVersionTag, followVersionTags, deviceVersionTag) {
153
166
  const inTag = incomingVersionTag || 'stable';
154
167
  if (deviceVersionTag)
@@ -39,6 +39,7 @@ export declare const rpcServerCalls: {
39
39
  setUserIdAndSecretKey: ((userId: string, secretKey: string) => Promise<void>);
40
40
  getUserId: () => Promise<string | undefined>;
41
41
  encryptData: ((value: string, groupId?: string) => Promise<string>);
42
+ logout: (() => Promise<void>);
42
43
  tableMethodCall: ((dataContextId: string, tableName: string, methodName: string, ...args: any[]) => Promise<any>);
43
44
  getFileContents: ((fileId: string, encoding?: BufferEncoding) => Promise<string>);
44
45
  getFileContentsBase64: ((fileId: string) => Promise<string>);
@@ -145,3 +146,5 @@ export declare const rpcClientCalls: {
145
146
  export type RpcServerNames = keyof typeof rpcServerCalls;
146
147
  export type RpcClientNames = keyof typeof rpcClientCalls;
147
148
  export declare const isClient: boolean;
149
+ export declare function setSingleProcessClient(value: boolean): void;
150
+ export declare function isSingleProcessClient(): boolean;
package/dist/rpc-types.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isClient = exports.rpcClientCalls = exports.rpcServerCalls = void 0;
4
+ exports.setSingleProcessClient = setSingleProcessClient;
5
+ exports.isSingleProcessClient = isSingleProcessClient;
4
6
  function rpcStub(rpcName) {
5
7
  return async (...args) => {
6
8
  console.warn(rpcName + ': rpc fn not set. This means that an RPC call is happening before the RPC function has been set. This is either a race condition or the RPC handler was never set.' + JSON.stringify({ rpcName, args }, null, 2));
@@ -16,6 +18,7 @@ exports.rpcServerCalls = {
16
18
  setUserIdAndSecretKey: rpcStub('setUserIdAndSecretKey'),
17
19
  getUserId: rpcStub('getUserId'),
18
20
  encryptData: rpcStub('encryptData'),
21
+ logout: rpcStub('logout'),
19
22
  tableMethodCall: rpcStub('tableMethodCall'),
20
23
  // TODO lock this down so not all code can get any file contents
21
24
  getFileContents: rpcStub('getFileContents'),
@@ -79,6 +82,11 @@ exports.rpcClientCalls = {
79
82
  // - CLI: process.env.PEERS_IS_CLIENT === 'true'
80
83
  exports.isClient = (typeof window !== 'undefined' && typeof document !== 'undefined')
81
84
  || (typeof process !== 'undefined' && process.env?.PEERS_IS_CLIENT === 'true');
85
+ // Single-process mode (PWA): client and server live in the same process,
86
+ // so Table events must NOT be suppressed on the client side.
87
+ let _singleProcessClient = false;
88
+ function setSingleProcessClient(value) { _singleProcessClient = value; }
89
+ function isSingleProcessClient() { return _singleProcessClient; }
82
90
  if (exports.isClient) {
83
91
  if (typeof window !== 'undefined') {
84
92
  // @ts-ignore
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-sdk",
3
- "version": "0.12.6",
3
+ "version": "0.13.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/peers-app/peers-sdk.git"