@peers-app/peers-sdk 0.1.4
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/README.md +1 -0
- package/dist/context/data-context.d.ts +31 -0
- package/dist/context/data-context.js +56 -0
- package/dist/context/index.d.ts +3 -0
- package/dist/context/index.js +19 -0
- package/dist/context/user-context-singleton.d.ts +11 -0
- package/dist/context/user-context-singleton.js +121 -0
- package/dist/context/user-context.d.ts +55 -0
- package/dist/context/user-context.js +205 -0
- package/dist/data/assistants.d.ts +68 -0
- package/dist/data/assistants.js +64 -0
- package/dist/data/change-tracking.d.ts +219 -0
- package/dist/data/change-tracking.js +119 -0
- package/dist/data/channels.d.ts +29 -0
- package/dist/data/channels.js +25 -0
- package/dist/data/data-locks.d.ts +37 -0
- package/dist/data/data-locks.js +180 -0
- package/dist/data/data-locks.test.d.ts +1 -0
- package/dist/data/data-locks.test.js +456 -0
- package/dist/data/device-sync-info.d.ts +19 -0
- package/dist/data/device-sync-info.js +24 -0
- package/dist/data/devices.d.ts +51 -0
- package/dist/data/devices.js +36 -0
- package/dist/data/embeddings.d.ts +47 -0
- package/dist/data/embeddings.js +36 -0
- package/dist/data/files/file-read-stream.d.ts +27 -0
- package/dist/data/files/file-read-stream.js +195 -0
- package/dist/data/files/file-write-stream.d.ts +20 -0
- package/dist/data/files/file-write-stream.js +113 -0
- package/dist/data/files/file.types.d.ts +47 -0
- package/dist/data/files/file.types.js +55 -0
- package/dist/data/files/files.d.ts +28 -0
- package/dist/data/files/files.js +127 -0
- package/dist/data/files/files.test.d.ts +1 -0
- package/dist/data/files/files.test.js +728 -0
- package/dist/data/files/index.d.ts +4 -0
- package/dist/data/files/index.js +23 -0
- package/dist/data/group-member-roles.d.ts +9 -0
- package/dist/data/group-member-roles.js +25 -0
- package/dist/data/group-members.d.ts +39 -0
- package/dist/data/group-members.js +68 -0
- package/dist/data/group-members.test.d.ts +1 -0
- package/dist/data/group-members.test.js +287 -0
- package/dist/data/group-permissions.d.ts +8 -0
- package/dist/data/group-permissions.js +73 -0
- package/dist/data/group-share.d.ts +50 -0
- package/dist/data/group-share.js +196 -0
- package/dist/data/groups.d.ts +50 -0
- package/dist/data/groups.js +73 -0
- package/dist/data/groups.test.d.ts +1 -0
- package/dist/data/groups.test.js +153 -0
- package/dist/data/index.d.ts +31 -0
- package/dist/data/index.js +47 -0
- package/dist/data/knowledge/knowledge-frames.d.ts +34 -0
- package/dist/data/knowledge/knowledge-frames.js +34 -0
- package/dist/data/knowledge/knowledge-links.d.ts +30 -0
- package/dist/data/knowledge/knowledge-links.js +25 -0
- package/dist/data/knowledge/knowledge-values.d.ts +35 -0
- package/dist/data/knowledge/knowledge-values.js +35 -0
- package/dist/data/knowledge/peer-types.d.ts +112 -0
- package/dist/data/knowledge/peer-types.js +27 -0
- package/dist/data/knowledge/predicates.d.ts +34 -0
- package/dist/data/knowledge/predicates.js +27 -0
- package/dist/data/messages.d.ts +57 -0
- package/dist/data/messages.js +97 -0
- package/dist/data/orm/client-proxy.data-source.d.ts +27 -0
- package/dist/data/orm/client-proxy.data-source.js +65 -0
- package/dist/data/orm/cursor.d.ts +25 -0
- package/dist/data/orm/cursor.js +47 -0
- package/dist/data/orm/cursor.test.d.ts +1 -0
- package/dist/data/orm/cursor.test.js +315 -0
- package/dist/data/orm/data-query.d.ts +96 -0
- package/dist/data/orm/data-query.js +208 -0
- package/dist/data/orm/data-query.mongo.d.ts +17 -0
- package/dist/data/orm/data-query.mongo.js +267 -0
- package/dist/data/orm/data-query.mongo.test.d.ts +1 -0
- package/dist/data/orm/data-query.mongo.test.js +398 -0
- package/dist/data/orm/data-query.sqlite.d.ts +14 -0
- package/dist/data/orm/data-query.sqlite.js +297 -0
- package/dist/data/orm/data-query.sqlite.test.d.ts +1 -0
- package/dist/data/orm/data-query.sqlite.test.js +377 -0
- package/dist/data/orm/data-query.test.d.ts +1 -0
- package/dist/data/orm/data-query.test.js +553 -0
- package/dist/data/orm/decorators.d.ts +6 -0
- package/dist/data/orm/decorators.js +21 -0
- package/dist/data/orm/dependency-injection.test.d.ts +1 -0
- package/dist/data/orm/dependency-injection.test.js +171 -0
- package/dist/data/orm/doc.d.ts +26 -0
- package/dist/data/orm/doc.js +124 -0
- package/dist/data/orm/event-registry.d.ts +24 -0
- package/dist/data/orm/event-registry.js +40 -0
- package/dist/data/orm/event-registry.test.d.ts +1 -0
- package/dist/data/orm/event-registry.test.js +44 -0
- package/dist/data/orm/factory.d.ts +8 -0
- package/dist/data/orm/factory.js +147 -0
- package/dist/data/orm/index.d.ts +16 -0
- package/dist/data/orm/index.js +32 -0
- package/dist/data/orm/multi-cursors.d.ts +11 -0
- package/dist/data/orm/multi-cursors.js +146 -0
- package/dist/data/orm/multi-cursors.test.d.ts +1 -0
- package/dist/data/orm/multi-cursors.test.js +455 -0
- package/dist/data/orm/sql-db.d.ts +6 -0
- package/dist/data/orm/sql-db.js +2 -0
- package/dist/data/orm/sql.data-source.d.ts +38 -0
- package/dist/data/orm/sql.data-source.js +379 -0
- package/dist/data/orm/sql.data-source.test.d.ts +1 -0
- package/dist/data/orm/sql.data-source.test.js +406 -0
- package/dist/data/orm/subscribable.data-source.d.ts +25 -0
- package/dist/data/orm/subscribable.data-source.js +72 -0
- package/dist/data/orm/table-container-events.test.d.ts +1 -0
- package/dist/data/orm/table-container-events.test.js +93 -0
- package/dist/data/orm/table-container.d.ts +39 -0
- package/dist/data/orm/table-container.js +96 -0
- package/dist/data/orm/table-definitions.system.d.ts +9 -0
- package/dist/data/orm/table-definitions.system.js +29 -0
- package/dist/data/orm/table-definitions.type.d.ts +19 -0
- package/dist/data/orm/table-definitions.type.js +2 -0
- package/dist/data/orm/table-dependencies.d.ts +32 -0
- package/dist/data/orm/table-dependencies.js +2 -0
- package/dist/data/orm/table.d.ts +42 -0
- package/dist/data/orm/table.event-source.test.d.ts +1 -0
- package/dist/data/orm/table.event-source.test.js +341 -0
- package/dist/data/orm/table.js +244 -0
- package/dist/data/orm/types.d.ts +20 -0
- package/dist/data/orm/types.js +115 -0
- package/dist/data/orm/types.test.d.ts +1 -0
- package/dist/data/orm/types.test.js +71 -0
- package/dist/data/package-permissions.d.ts +7 -0
- package/dist/data/package-permissions.js +18 -0
- package/dist/data/packages.d.ts +92 -0
- package/dist/data/packages.js +90 -0
- package/dist/data/peer-events/peer-event-handlers.d.ts +21 -0
- package/dist/data/peer-events/peer-event-handlers.js +28 -0
- package/dist/data/peer-events/peer-event-types.d.ts +119 -0
- package/dist/data/peer-events/peer-event-types.js +29 -0
- package/dist/data/peer-events/peer-events.d.ts +41 -0
- package/dist/data/peer-events/peer-events.js +102 -0
- package/dist/data/persistent-vars.d.ts +87 -0
- package/dist/data/persistent-vars.js +230 -0
- package/dist/data/tool-tests.d.ts +37 -0
- package/dist/data/tool-tests.js +27 -0
- package/dist/data/tools.d.ts +358 -0
- package/dist/data/tools.js +48 -0
- package/dist/data/user-permissions.d.ts +15 -0
- package/dist/data/user-permissions.js +39 -0
- package/dist/data/user-permissions.test.d.ts +1 -0
- package/dist/data/user-permissions.test.js +252 -0
- package/dist/data/users.d.ts +38 -0
- package/dist/data/users.js +73 -0
- package/dist/data/workflow-logs.d.ts +106 -0
- package/dist/data/workflow-logs.js +67 -0
- package/dist/data/workflow-runs.d.ts +103 -0
- package/dist/data/workflow-runs.js +313 -0
- package/dist/data/workflows.d.ts +16 -0
- package/dist/data/workflows.js +21 -0
- package/dist/device/connection.d.ts +41 -0
- package/dist/device/connection.js +249 -0
- package/dist/device/connection.test.d.ts +1 -0
- package/dist/device/connection.test.js +292 -0
- package/dist/device/device-election.d.ts +36 -0
- package/dist/device/device-election.js +137 -0
- package/dist/device/device.d.ts +22 -0
- package/dist/device/device.js +110 -0
- package/dist/device/device.test.d.ts +1 -0
- package/dist/device/device.test.js +203 -0
- package/dist/device/get-trust-level.d.ts +3 -0
- package/dist/device/get-trust-level.js +87 -0
- package/dist/device/socket.type.d.ts +20 -0
- package/dist/device/socket.type.js +15 -0
- package/dist/device/streamed-socket.d.ts +27 -0
- package/dist/device/streamed-socket.js +154 -0
- package/dist/device/streamed-socket.test.d.ts +1 -0
- package/dist/device/streamed-socket.test.js +44 -0
- package/dist/events.d.ts +35 -0
- package/dist/events.js +128 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +50 -0
- package/dist/keys.d.ts +51 -0
- package/dist/keys.js +234 -0
- package/dist/keys.test.d.ts +1 -0
- package/dist/keys.test.js +215 -0
- package/dist/mentions.d.ts +9 -0
- package/dist/mentions.js +46 -0
- package/dist/observable.d.ts +19 -0
- package/dist/observable.js +112 -0
- package/dist/observable.test.d.ts +1 -0
- package/dist/observable.test.js +183 -0
- package/dist/package-loader/get-require.d.ts +10 -0
- package/dist/package-loader/get-require.js +31 -0
- package/dist/package-loader/index.d.ts +1 -0
- package/dist/package-loader/index.js +17 -0
- package/dist/package-loader/package-loader.d.ts +16 -0
- package/dist/package-loader/package-loader.js +102 -0
- package/dist/peers-ui/peers-ui.d.ts +15 -0
- package/dist/peers-ui/peers-ui.js +23 -0
- package/dist/peers-ui/peers-ui.types.d.ts +35 -0
- package/dist/peers-ui/peers-ui.types.js +3 -0
- package/dist/rpc-types.d.ts +45 -0
- package/dist/rpc-types.js +47 -0
- package/dist/serial-json.d.ts +5 -0
- package/dist/serial-json.js +186 -0
- package/dist/serial-json.test.d.ts +1 -0
- package/dist/serial-json.test.js +86 -0
- package/dist/system-ids.d.ts +6 -0
- package/dist/system-ids.js +10 -0
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.js +17 -0
- package/dist/tools/tools-factory.d.ts +5 -0
- package/dist/tools/tools-factory.js +34 -0
- package/dist/types/app-nav.d.ts +18 -0
- package/dist/types/app-nav.js +10 -0
- package/dist/types/assistant-runner-args.d.ts +9 -0
- package/dist/types/assistant-runner-args.js +2 -0
- package/dist/types/field-type.d.ts +37 -0
- package/dist/types/field-type.js +26 -0
- package/dist/types/peer-device.d.ts +40 -0
- package/dist/types/peer-device.js +14 -0
- package/dist/types/peers-package.d.ts +23 -0
- package/dist/types/peers-package.js +2 -0
- package/dist/types/workflow-logger.d.ts +2 -0
- package/dist/types/workflow-logger.js +2 -0
- package/dist/types/workflow-run-context.d.ts +12 -0
- package/dist/types/workflow-run-context.js +2 -0
- package/dist/types/workflow.d.ts +72 -0
- package/dist/types/workflow.js +24 -0
- package/dist/types/zod-types.d.ts +7 -0
- package/dist/types/zod-types.js +12 -0
- package/dist/users.query.d.ts +13 -0
- package/dist/users.query.js +134 -0
- package/dist/utils.d.ts +39 -0
- package/dist/utils.js +240 -0
- package/dist/utils.test.d.ts +1 -0
- package/dist/utils.test.js +140 -0
- package/package.json +50 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const keys_1 = require("./keys");
|
|
4
|
+
describe('keys', () => {
|
|
5
|
+
it('should allow creating a new key pair', () => {
|
|
6
|
+
const keys = (0, keys_1.newKeys)();
|
|
7
|
+
expect(keys.publicKey).toBeTruthy();
|
|
8
|
+
expect(keys.secretKey).toBeTruthy();
|
|
9
|
+
expect(keys.publicBoxKey).toBeTruthy();
|
|
10
|
+
});
|
|
11
|
+
describe('message signing', () => {
|
|
12
|
+
it('should allow signing a message with a secret key and opening it with the corresponding public key', () => {
|
|
13
|
+
const keys = (0, keys_1.newKeys)();
|
|
14
|
+
const msg = 'hello world';
|
|
15
|
+
const signed = (0, keys_1.signMessageWithSecretKey)(msg, keys.secretKey);
|
|
16
|
+
expect(signed).toBeTruthy();
|
|
17
|
+
expect(signed).not.toEqual(msg);
|
|
18
|
+
const opened = (0, keys_1.openMessageWithPublicKey)(signed, keys.publicKey);
|
|
19
|
+
expect(opened).toEqual(msg);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe('object signing', () => {
|
|
23
|
+
it('should allow signing an object with a secret key and opening it with the corresponding public key', () => {
|
|
24
|
+
const keys = (0, keys_1.newKeys)();
|
|
25
|
+
const obj = { hello: 'world' };
|
|
26
|
+
const signed = (0, keys_1.signObjectWithSecretKey)(obj, keys.secretKey);
|
|
27
|
+
expect(signed).toBeTruthy();
|
|
28
|
+
expect(signed).not.toEqual(obj);
|
|
29
|
+
const opened = (0, keys_1.openSignedObject)(signed);
|
|
30
|
+
expect(opened).toEqual(obj);
|
|
31
|
+
});
|
|
32
|
+
it('should throw an error if the data changes after the signature', () => {
|
|
33
|
+
const keys = (0, keys_1.newKeys)();
|
|
34
|
+
const obj = { hello: 'world' };
|
|
35
|
+
const signed = (0, keys_1.signObjectWithSecretKey)(obj, keys.secretKey);
|
|
36
|
+
expect(signed).toBeTruthy();
|
|
37
|
+
signed.contents = { hello: 'world2' };
|
|
38
|
+
expect(signed).not.toEqual(obj);
|
|
39
|
+
expect(() => (0, keys_1.openSignedObject)(signed)).toThrow(/signature/i);
|
|
40
|
+
});
|
|
41
|
+
it('should handle null and undefined gracefully', () => {
|
|
42
|
+
const keys = (0, keys_1.newKeys)();
|
|
43
|
+
const obj = undefined;
|
|
44
|
+
const signed = (0, keys_1.signObjectWithSecretKey)(obj, keys.secretKey);
|
|
45
|
+
expect(signed).toBeTruthy();
|
|
46
|
+
expect(signed).not.toEqual(obj);
|
|
47
|
+
const opened = (0, keys_1.openSignedObject)(signed);
|
|
48
|
+
expect(opened).toEqual(obj);
|
|
49
|
+
});
|
|
50
|
+
it.each([false, true, 0, 1, 3.1415, "", "s"])(`should handle simple values: \`%s\``, (value) => {
|
|
51
|
+
const keys = (0, keys_1.newKeys)();
|
|
52
|
+
const signed = (0, keys_1.signObjectWithSecretKey)(value, keys.secretKey);
|
|
53
|
+
expect(signed).toBeTruthy();
|
|
54
|
+
expect(signed).not.toEqual(value);
|
|
55
|
+
const opened = (0, keys_1.openSignedObject)(signed);
|
|
56
|
+
expect(opened).toEqual(value);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe('message boxing', () => {
|
|
60
|
+
it('should allow boxing data with a public key so it can only be opened with the secret key', () => {
|
|
61
|
+
const from = (0, keys_1.newKeys)();
|
|
62
|
+
const to = (0, keys_1.newKeys)();
|
|
63
|
+
const msg = 'hello world';
|
|
64
|
+
const boxed = (0, keys_1.boxDataWithKeys)(msg, to.publicBoxKey, from.secretKey);
|
|
65
|
+
expect(boxed).toBeTruthy();
|
|
66
|
+
const opened = (0, keys_1.openBoxWithSecretKey)(boxed, to.secretKey);
|
|
67
|
+
expect(opened).toEqual(msg);
|
|
68
|
+
});
|
|
69
|
+
it('should allow boxing objects', () => {
|
|
70
|
+
const from = (0, keys_1.newKeys)();
|
|
71
|
+
const to = (0, keys_1.newKeys)();
|
|
72
|
+
const msg = { hello: 'world' };
|
|
73
|
+
const boxed = (0, keys_1.boxDataWithKeys)(msg, to.publicBoxKey, from.secretKey);
|
|
74
|
+
expect(boxed).toBeTruthy();
|
|
75
|
+
const opened = (0, keys_1.openBoxWithSecretKey)(boxed, to.secretKey);
|
|
76
|
+
expect(opened).toEqual(msg);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe('message encryption', () => {
|
|
80
|
+
it('should allow encrypting a message with a secret key so it can only be decrypted with that same secret key', () => {
|
|
81
|
+
const keys = (0, keys_1.newKeys)();
|
|
82
|
+
const msg = 'hello world';
|
|
83
|
+
const boxed = (0, keys_1.encryptData)(msg, keys.secretKey);
|
|
84
|
+
expect(boxed).toBeTruthy();
|
|
85
|
+
const opened = (0, keys_1.decryptData)(boxed, keys.secretKey);
|
|
86
|
+
expect(opened).toEqual(msg);
|
|
87
|
+
});
|
|
88
|
+
it('should allow encrypting objects', () => {
|
|
89
|
+
const keys = (0, keys_1.newKeys)();
|
|
90
|
+
const msg = { hello: 'world' };
|
|
91
|
+
const boxed = (0, keys_1.encryptData)(msg, keys.secretKey);
|
|
92
|
+
expect(boxed).toBeTruthy();
|
|
93
|
+
const opened = (0, keys_1.decryptData)(boxed, keys.secretKey);
|
|
94
|
+
expect(opened).toEqual(msg);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
describe('loading keys', () => {
|
|
98
|
+
it('should allow loading keys from a secret key', () => {
|
|
99
|
+
const keys = (0, keys_1.newKeys)();
|
|
100
|
+
const loadedKeys = (0, keys_1.loadKeys)(keys.secretKey);
|
|
101
|
+
expect(loadedKeys.secretKey).toEqual(keys.secretKey);
|
|
102
|
+
expect(loadedKeys.publicKey).toEqual(keys.publicKey);
|
|
103
|
+
expect(loadedKeys.publicBoxKey).toEqual(keys.publicBoxKey);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
describe('hashBytes', () => {
|
|
107
|
+
it('should hash buffer data consistently', () => {
|
|
108
|
+
const data = Buffer.from('Hello, World!', 'utf8');
|
|
109
|
+
const hash1 = (0, keys_1.hashBytes)(data);
|
|
110
|
+
const hash2 = (0, keys_1.hashBytes)(data);
|
|
111
|
+
expect(hash1).toBe(hash2);
|
|
112
|
+
expect(hash1).toBeTruthy();
|
|
113
|
+
});
|
|
114
|
+
it('should produce different hashes for different data', () => {
|
|
115
|
+
const data1 = Buffer.from('Hello, World!', 'utf8');
|
|
116
|
+
const data2 = Buffer.from('Hello, World?', 'utf8');
|
|
117
|
+
const hash1 = (0, keys_1.hashBytes)(data1);
|
|
118
|
+
const hash2 = (0, keys_1.hashBytes)(data2);
|
|
119
|
+
expect(hash1).not.toBe(hash2);
|
|
120
|
+
});
|
|
121
|
+
it('should work with binary data', () => {
|
|
122
|
+
// Create binary data with all byte values
|
|
123
|
+
const binaryData = Buffer.alloc(256);
|
|
124
|
+
for (let i = 0; i < 256; i++) {
|
|
125
|
+
binaryData[i] = i;
|
|
126
|
+
}
|
|
127
|
+
const hash = (0, keys_1.hashBytes)(binaryData);
|
|
128
|
+
expect(hash).toBeTruthy();
|
|
129
|
+
// Verify consistency
|
|
130
|
+
const hash2 = (0, keys_1.hashBytes)(binaryData);
|
|
131
|
+
expect(hash).toBe(hash2);
|
|
132
|
+
});
|
|
133
|
+
it('should be equivalent to hashValue for string data', () => {
|
|
134
|
+
const text = 'Hello, World!';
|
|
135
|
+
const stringBuffer = Buffer.from(text, 'utf8');
|
|
136
|
+
const bufferHash = (0, keys_1.hashBytes)(stringBuffer);
|
|
137
|
+
const stringHash = (0, keys_1.hashValue)(text);
|
|
138
|
+
expect(bufferHash).toBe(stringHash);
|
|
139
|
+
});
|
|
140
|
+
it('should handle empty buffer', () => {
|
|
141
|
+
const emptyBuffer = Buffer.alloc(0);
|
|
142
|
+
const hash = (0, keys_1.hashBytes)(emptyBuffer);
|
|
143
|
+
expect(hash).toBeTruthy();
|
|
144
|
+
});
|
|
145
|
+
it('should handle large buffers', () => {
|
|
146
|
+
// 1MB of data
|
|
147
|
+
const largeBuffer = Buffer.alloc(1024 * 1024, 'A');
|
|
148
|
+
const hash = (0, keys_1.hashBytes)(largeBuffer);
|
|
149
|
+
expect(hash).toBeTruthy();
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
describe('object signature embedding', () => {
|
|
153
|
+
it('should add signature to object and verify it successfully', () => {
|
|
154
|
+
const keys = (0, keys_1.newKeys)();
|
|
155
|
+
const obj = { name: 'test', value: 42 };
|
|
156
|
+
const signedObj = (0, keys_1.addSignatureToObject)(obj, keys.secretKey);
|
|
157
|
+
expect(signedObj).toHaveProperty('signature');
|
|
158
|
+
expect(signedObj.name).toBe('test');
|
|
159
|
+
expect(signedObj.value).toBe(42);
|
|
160
|
+
expect((0, keys_1.isObjectSignatureValid)(signedObj)).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
it('should fail verification if object is modified after signing', () => {
|
|
163
|
+
const keys = (0, keys_1.newKeys)();
|
|
164
|
+
const obj = { name: 'test', value: 42 };
|
|
165
|
+
const signedObj = (0, keys_1.addSignatureToObject)(obj, keys.secretKey);
|
|
166
|
+
signedObj.value = 999; // modify after signing
|
|
167
|
+
expect((0, keys_1.isObjectSignatureValid)(signedObj)).toBe(false);
|
|
168
|
+
});
|
|
169
|
+
it('should fail verification if signature is tampered with', () => {
|
|
170
|
+
const keys = (0, keys_1.newKeys)();
|
|
171
|
+
const obj = { name: 'test', value: 42 };
|
|
172
|
+
const signedObj = (0, keys_1.addSignatureToObject)(obj, keys.secretKey);
|
|
173
|
+
signedObj.signature = signedObj.signature + 'tampered';
|
|
174
|
+
expect((0, keys_1.isObjectSignatureValid)(signedObj)).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
it('should extract public key from signature', () => {
|
|
177
|
+
const keys = (0, keys_1.newKeys)();
|
|
178
|
+
const obj = { name: 'test', value: 42 };
|
|
179
|
+
const signedObj = (0, keys_1.addSignatureToObject)(obj, keys.secretKey);
|
|
180
|
+
const extractedPublicKey = (0, keys_1.getPublicKeyFromObjectSignature)(signedObj);
|
|
181
|
+
expect(extractedPublicKey).toBe(keys.publicKey);
|
|
182
|
+
});
|
|
183
|
+
it('should return undefined for malformed signature', () => {
|
|
184
|
+
const obj = { name: 'test', value: 42, signature: 'malformed' };
|
|
185
|
+
const extractedPublicKey = (0, keys_1.getPublicKeyFromObjectSignature)(obj);
|
|
186
|
+
expect(extractedPublicKey).toBeUndefined();
|
|
187
|
+
});
|
|
188
|
+
it('should handle objects with existing signature property', () => {
|
|
189
|
+
const keys = (0, keys_1.newKeys)();
|
|
190
|
+
const obj = { name: 'test', value: 42, signature: 'old-signature' };
|
|
191
|
+
const signedObj = (0, keys_1.addSignatureToObject)(obj, keys.secretKey);
|
|
192
|
+
expect(signedObj.signature).not.toBe('old-signature');
|
|
193
|
+
expect((0, keys_1.isObjectSignatureValid)(signedObj)).toBe(true);
|
|
194
|
+
});
|
|
195
|
+
it('should work with complex nested objects', () => {
|
|
196
|
+
const keys = (0, keys_1.newKeys)();
|
|
197
|
+
const obj = {
|
|
198
|
+
user: { name: 'Alice', age: 30 },
|
|
199
|
+
settings: { theme: 'dark', notifications: true },
|
|
200
|
+
data: [1, 2, 3, { nested: true }]
|
|
201
|
+
};
|
|
202
|
+
const signedObj = (0, keys_1.addSignatureToObject)(obj, keys.secretKey);
|
|
203
|
+
expect((0, keys_1.isObjectSignatureValid)(signedObj)).toBe(true);
|
|
204
|
+
expect(signedObj.user.name).toBe('Alice');
|
|
205
|
+
expect(signedObj.data[3].nested).toBe(true);
|
|
206
|
+
});
|
|
207
|
+
it('should handle empty objects', () => {
|
|
208
|
+
const keys = (0, keys_1.newKeys)();
|
|
209
|
+
const obj = {};
|
|
210
|
+
const signedObj = (0, keys_1.addSignatureToObject)(obj, keys.secretKey);
|
|
211
|
+
expect((0, keys_1.isObjectSignatureValid)(signedObj)).toBe(true);
|
|
212
|
+
expect((0, keys_1.getPublicKeyFromObjectSignature)(signedObj)).toBe(keys.publicKey);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type IMentionData = {
|
|
2
|
+
kind: string;
|
|
3
|
+
name: string;
|
|
4
|
+
id: string;
|
|
5
|
+
clickable?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const mentionRegex: () => RegExp;
|
|
8
|
+
export declare const formatMention: (data: IMentionData) => string;
|
|
9
|
+
export declare const getAllMentions: (markdown: string) => IMentionData[];
|
package/dist/mentions.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAllMentions = exports.formatMention = exports.mentionRegex = void 0;
|
|
4
|
+
// export const mentionRegex = () => /<(@user|@assistant|\$tool|\$workflow|\$event|\$task):([a-zA-Z0-9_-]+):([a-zA-Z0-9]{25})(:([a-zA-Z0-9]{25}))?>/;
|
|
5
|
+
// export const mentionRegex = () => /<(@|$)([a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+):([a-zA-Z0-9]{25})(:([a-zA-Z0-9]{25}))?>/;
|
|
6
|
+
const mentionRegex = () => /<(@|\$)([a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+):([a-zA-Z0-9]{25})?>/;
|
|
7
|
+
exports.mentionRegex = mentionRegex;
|
|
8
|
+
const formatMention = (data) => {
|
|
9
|
+
let prefix = '$';
|
|
10
|
+
if (data.kind === 'assistant' || data.kind === 'user') {
|
|
11
|
+
prefix = '@';
|
|
12
|
+
}
|
|
13
|
+
let name = data.name.replace(/\s/g, '_');
|
|
14
|
+
// remove non-alphanumeric characters
|
|
15
|
+
name = name.replace(/[^a-zA-Z0-9_-]/g, '');
|
|
16
|
+
let mention = `<${prefix}${data.kind}:${name}:${data.id}`;
|
|
17
|
+
// if (data.kind === 'assistant') {
|
|
18
|
+
// mention += `:${data.userId}`;
|
|
19
|
+
// }
|
|
20
|
+
mention += '>';
|
|
21
|
+
return mention;
|
|
22
|
+
};
|
|
23
|
+
exports.formatMention = formatMention;
|
|
24
|
+
const getAllMentions = (markdown) => {
|
|
25
|
+
const mentions = [];
|
|
26
|
+
let lastIndex = 0;
|
|
27
|
+
let match;
|
|
28
|
+
let cnt = 0;
|
|
29
|
+
const regex = (0, exports.mentionRegex)();
|
|
30
|
+
while ((match = regex.exec(markdown)) !== null) {
|
|
31
|
+
cnt++;
|
|
32
|
+
markdown = markdown.slice(match.index + match[0].length);
|
|
33
|
+
const kind = match[2];
|
|
34
|
+
const name = match[3].replace(/_/g, ' ');
|
|
35
|
+
const id = match[4];
|
|
36
|
+
const data = {
|
|
37
|
+
kind: kind,
|
|
38
|
+
name,
|
|
39
|
+
id,
|
|
40
|
+
};
|
|
41
|
+
mentions.push(data);
|
|
42
|
+
lastIndex = regex.lastIndex;
|
|
43
|
+
}
|
|
44
|
+
return mentions;
|
|
45
|
+
};
|
|
46
|
+
exports.getAllMentions = getAllMentions;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type ObservableFn<T> = ((newValue?: T) => T);
|
|
2
|
+
export type Subscription = {
|
|
3
|
+
dispose: () => void;
|
|
4
|
+
};
|
|
5
|
+
type ObservableProps<T> = {
|
|
6
|
+
subscribe: (subscriber: (newValue: T) => void) => Subscription;
|
|
7
|
+
notifySubscribers: (newValue?: T) => void;
|
|
8
|
+
subscriberCount: () => number;
|
|
9
|
+
};
|
|
10
|
+
export type Observable<T> = ObservableFn<T> & ObservableProps<T>;
|
|
11
|
+
export declare function observable<T>(initialValue?: T): Observable<T>;
|
|
12
|
+
export declare function computed<T>(fn: ({
|
|
13
|
+
read: () => T;
|
|
14
|
+
write?: (val: T) => void;
|
|
15
|
+
}) | (() => T)): Observable<T>;
|
|
16
|
+
export declare function isSubscribable(obj: any): obj is Observable<any>;
|
|
17
|
+
export declare function unwrapObservable<T>(obj: T | Observable<T>): T;
|
|
18
|
+
export declare function linkObservables<T>(obs1: Observable<T>, obs2: Observable<T>): Subscription;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.observable = observable;
|
|
4
|
+
exports.computed = computed;
|
|
5
|
+
exports.isSubscribable = isSubscribable;
|
|
6
|
+
exports.unwrapObservable = unwrapObservable;
|
|
7
|
+
exports.linkObservables = linkObservables;
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const _ = require("lodash");
|
|
11
|
+
const runningComputes = {};
|
|
12
|
+
function observable(initialValue) {
|
|
13
|
+
let value = initialValue;
|
|
14
|
+
const subscribers = [];
|
|
15
|
+
const obs = ((newValue) => {
|
|
16
|
+
Object.values(runningComputes).forEach(c => c.push(obs));
|
|
17
|
+
if (newValue !== undefined && newValue !== value) {
|
|
18
|
+
value = newValue;
|
|
19
|
+
obs.notifySubscribers();
|
|
20
|
+
}
|
|
21
|
+
// TODO - get typings to say if a value is passed in it's type T otherwise it's T | undefined
|
|
22
|
+
return value;
|
|
23
|
+
});
|
|
24
|
+
obs.notifySubscribers = (newValue) => {
|
|
25
|
+
if (newValue !== undefined) {
|
|
26
|
+
value = newValue;
|
|
27
|
+
}
|
|
28
|
+
subscribers.forEach(subscriber => subscriber(value)); // TODO fix typing here too
|
|
29
|
+
};
|
|
30
|
+
obs.subscribe = (subscriber) => {
|
|
31
|
+
subscribers.push(subscriber);
|
|
32
|
+
// if (value !== undefined) {
|
|
33
|
+
// subscriber(value);
|
|
34
|
+
// }
|
|
35
|
+
return {
|
|
36
|
+
dispose: () => {
|
|
37
|
+
const iSub = subscribers.indexOf(subscriber);
|
|
38
|
+
if (iSub >= 0) {
|
|
39
|
+
subscribers.splice(iSub, 1);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
obs.subscriberCount = () => subscribers.length;
|
|
45
|
+
return obs;
|
|
46
|
+
}
|
|
47
|
+
function computed(fn) {
|
|
48
|
+
const read = _.isFunction(fn) ? fn : fn.read;
|
|
49
|
+
const write = _.isFunction(fn) ? undefined : fn.write;
|
|
50
|
+
// compute dependencies and initial value;
|
|
51
|
+
const dependencies = [];
|
|
52
|
+
const runId = (0, utils_1.newid)();
|
|
53
|
+
runningComputes[runId] = dependencies;
|
|
54
|
+
const _obs = observable(read());
|
|
55
|
+
delete runningComputes[runId];
|
|
56
|
+
let dirty = false;
|
|
57
|
+
const recompute = () => {
|
|
58
|
+
dirty = false;
|
|
59
|
+
return _obs(read());
|
|
60
|
+
};
|
|
61
|
+
const obs = (newValue) => {
|
|
62
|
+
if (newValue !== undefined) {
|
|
63
|
+
if (write) {
|
|
64
|
+
write(newValue);
|
|
65
|
+
return recompute();
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw new Error('Computed value is readonly');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (dirty) {
|
|
72
|
+
return recompute();
|
|
73
|
+
}
|
|
74
|
+
return _obs();
|
|
75
|
+
};
|
|
76
|
+
const onDepChange = () => {
|
|
77
|
+
if (_obs.subscriberCount() === 0) {
|
|
78
|
+
dirty = true;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
recompute();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
// subscribe to dependencies
|
|
85
|
+
(0, lodash_1.uniq)(dependencies).forEach(dep => dep.subscribe(onDepChange));
|
|
86
|
+
Object.assign(obs, _obs);
|
|
87
|
+
return obs;
|
|
88
|
+
}
|
|
89
|
+
function isSubscribable(obj) {
|
|
90
|
+
return obj && typeof obj === 'function' && obj.subscribe && obj.notifySubscribers;
|
|
91
|
+
}
|
|
92
|
+
function unwrapObservable(obj) {
|
|
93
|
+
return isSubscribable(obj) ? obj() : obj;
|
|
94
|
+
}
|
|
95
|
+
function linkObservables(obs1, obs2) {
|
|
96
|
+
const sub1 = obs1.subscribe(value => {
|
|
97
|
+
if (value !== obs2()) {
|
|
98
|
+
obs2(value);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
const sub2 = obs2.subscribe(value => {
|
|
102
|
+
if (value !== obs1()) {
|
|
103
|
+
obs1(value);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
dispose: () => {
|
|
108
|
+
sub1.dispose();
|
|
109
|
+
sub2.dispose();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const observable_1 = require("./observable");
|
|
4
|
+
describe('observable.ts', () => {
|
|
5
|
+
describe('observable', () => {
|
|
6
|
+
it('should be able to create an observable', () => {
|
|
7
|
+
const obs = (0, observable_1.observable)(3);
|
|
8
|
+
expect(obs()).toBe(3);
|
|
9
|
+
});
|
|
10
|
+
it('should be able to update an observable', () => {
|
|
11
|
+
const obs = (0, observable_1.observable)(3);
|
|
12
|
+
obs(4);
|
|
13
|
+
expect(obs()).toBe(4);
|
|
14
|
+
});
|
|
15
|
+
it('should be able to subscribe to an observable', () => {
|
|
16
|
+
const obs = (0, observable_1.observable)(3);
|
|
17
|
+
let value = 0;
|
|
18
|
+
const sub = obs.subscribe(newValue => {
|
|
19
|
+
value = newValue;
|
|
20
|
+
});
|
|
21
|
+
expect(value).toBe(0);
|
|
22
|
+
obs(4);
|
|
23
|
+
expect(value).toBe(4);
|
|
24
|
+
sub.dispose();
|
|
25
|
+
obs(5);
|
|
26
|
+
expect(value).toBe(4);
|
|
27
|
+
});
|
|
28
|
+
it('should return the value when writing to itself', () => {
|
|
29
|
+
const obs = (0, observable_1.observable)(3);
|
|
30
|
+
expect(obs(4)).toBe(4);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe('computed', () => {
|
|
34
|
+
it('should be able to create a computed observable', () => {
|
|
35
|
+
const com = (0, observable_1.computed)(() => 3);
|
|
36
|
+
expect(com()).toBe(3);
|
|
37
|
+
});
|
|
38
|
+
it('should throw if trying to set value', () => {
|
|
39
|
+
const com = (0, observable_1.computed)(() => 3);
|
|
40
|
+
expect(() => com(4)).toThrow();
|
|
41
|
+
});
|
|
42
|
+
it('should be able to create a computed observable that depends on another observable', () => {
|
|
43
|
+
const obs1 = (0, observable_1.observable)(3);
|
|
44
|
+
const com1 = (0, observable_1.computed)(() => obs1() + 1);
|
|
45
|
+
expect(com1()).toBe(4);
|
|
46
|
+
obs1(5);
|
|
47
|
+
expect(com1()).toBe(6);
|
|
48
|
+
});
|
|
49
|
+
it('should be able to create a computed observable that depends on another computed observable', () => {
|
|
50
|
+
const obs1 = (0, observable_1.observable)(3);
|
|
51
|
+
const com1 = (0, observable_1.computed)(() => obs1() + 1);
|
|
52
|
+
const com2 = (0, observable_1.computed)(() => com1() + 1);
|
|
53
|
+
expect(com2()).toBe(5);
|
|
54
|
+
obs1(5);
|
|
55
|
+
expect(com2()).toBe(7);
|
|
56
|
+
});
|
|
57
|
+
it('should be able to create a computed observable that depends on another computed observable that depends on another computed observable', () => {
|
|
58
|
+
const obs1 = (0, observable_1.observable)(3);
|
|
59
|
+
const com1 = (0, observable_1.computed)(() => obs1() + 1);
|
|
60
|
+
const com2 = (0, observable_1.computed)(() => com1() + 1);
|
|
61
|
+
const com3 = (0, observable_1.computed)(() => com2() + 1);
|
|
62
|
+
expect(com3()).toBe(6);
|
|
63
|
+
});
|
|
64
|
+
it('should notify subscribers of new value when a dependency changes', () => {
|
|
65
|
+
const obs1 = (0, observable_1.observable)(3);
|
|
66
|
+
const com1 = (0, observable_1.computed)(() => obs1() + 1);
|
|
67
|
+
let newValue = 0;
|
|
68
|
+
com1.subscribe(val => {
|
|
69
|
+
newValue = val;
|
|
70
|
+
});
|
|
71
|
+
expect(com1()).toBe(4);
|
|
72
|
+
expect(newValue).toBe(0);
|
|
73
|
+
obs1(5);
|
|
74
|
+
expect(newValue).toBe(6);
|
|
75
|
+
});
|
|
76
|
+
it('should not notify subscribers of new value when a dependency changes if there are no subscribers', () => {
|
|
77
|
+
const obs1 = (0, observable_1.observable)(1);
|
|
78
|
+
let computeCount = 0;
|
|
79
|
+
const com1 = (0, observable_1.computed)(() => {
|
|
80
|
+
computeCount++;
|
|
81
|
+
return obs1() + 1;
|
|
82
|
+
});
|
|
83
|
+
let newValue = 0;
|
|
84
|
+
const sub = com1.subscribe(val => {
|
|
85
|
+
newValue = val;
|
|
86
|
+
});
|
|
87
|
+
expect(computeCount).toBe(1);
|
|
88
|
+
expect(com1()).toBe(2);
|
|
89
|
+
expect(newValue).toBe(0);
|
|
90
|
+
expect(computeCount).toBe(1);
|
|
91
|
+
obs1(2);
|
|
92
|
+
expect(computeCount).toBe(2);
|
|
93
|
+
expect(com1()).toBe(3);
|
|
94
|
+
expect(newValue).toBe(3);
|
|
95
|
+
sub.dispose();
|
|
96
|
+
obs1(3);
|
|
97
|
+
expect(computeCount).toBe(2);
|
|
98
|
+
expect(com1()).toBe(4);
|
|
99
|
+
expect(computeCount).toBe(3);
|
|
100
|
+
expect(com1()).toBe(4);
|
|
101
|
+
});
|
|
102
|
+
it('should only recompute value when a dependency changes if there are subscribers', () => {
|
|
103
|
+
const obs1 = (0, observable_1.observable)(1);
|
|
104
|
+
let recomputeCount = 0;
|
|
105
|
+
const com1 = (0, observable_1.computed)(() => {
|
|
106
|
+
recomputeCount++;
|
|
107
|
+
return obs1() + recomputeCount;
|
|
108
|
+
});
|
|
109
|
+
expect(com1()).toBe(2);
|
|
110
|
+
expect(recomputeCount).toBe(1);
|
|
111
|
+
expect(com1()).toBe(2);
|
|
112
|
+
expect(recomputeCount).toBe(1);
|
|
113
|
+
obs1(2);
|
|
114
|
+
expect(recomputeCount).toBe(1);
|
|
115
|
+
expect(obs1()).toBe(2);
|
|
116
|
+
expect(recomputeCount).toBe(1);
|
|
117
|
+
// NOTE the recomputeCount only changed when we inspected com1 (lazy evaluation)
|
|
118
|
+
// this probably won't be used much right now but if we implement `deferCompute` this can have a big impact
|
|
119
|
+
expect(com1()).toBe(4);
|
|
120
|
+
expect(recomputeCount).toBe(2);
|
|
121
|
+
});
|
|
122
|
+
it('should immediately, and still only, recompute value when a dependency changes if there are subscribers', () => {
|
|
123
|
+
const obs1 = (0, observable_1.observable)(1);
|
|
124
|
+
let recomputeCount = 0;
|
|
125
|
+
const com1 = (0, observable_1.computed)(() => {
|
|
126
|
+
recomputeCount++;
|
|
127
|
+
return obs1() + recomputeCount;
|
|
128
|
+
});
|
|
129
|
+
let newValue = 0;
|
|
130
|
+
com1.subscribe(val => {
|
|
131
|
+
newValue = val;
|
|
132
|
+
});
|
|
133
|
+
expect(com1()).toBe(2);
|
|
134
|
+
expect(recomputeCount).toBe(1);
|
|
135
|
+
expect(newValue).toBe(0);
|
|
136
|
+
obs1(2);
|
|
137
|
+
expect(recomputeCount).toBe(2);
|
|
138
|
+
expect(newValue).toBe(4);
|
|
139
|
+
expect(recomputeCount).toBe(2);
|
|
140
|
+
expect(com1()).toBe(4);
|
|
141
|
+
expect(com1()).toBe(4);
|
|
142
|
+
});
|
|
143
|
+
it('notify should set the value and notify subscribers without recomputing', () => {
|
|
144
|
+
const obs1 = (0, observable_1.observable)(1);
|
|
145
|
+
let recomputeCount = 0;
|
|
146
|
+
const com1 = (0, observable_1.computed)(() => {
|
|
147
|
+
recomputeCount++;
|
|
148
|
+
return obs1() + recomputeCount;
|
|
149
|
+
});
|
|
150
|
+
let newValue = 0;
|
|
151
|
+
com1.subscribe(val => {
|
|
152
|
+
newValue = val;
|
|
153
|
+
});
|
|
154
|
+
expect(com1()).toBe(2);
|
|
155
|
+
expect(recomputeCount).toBe(1);
|
|
156
|
+
expect(newValue).toBe(0);
|
|
157
|
+
obs1(2);
|
|
158
|
+
expect(recomputeCount).toBe(2);
|
|
159
|
+
expect(newValue).toBe(4);
|
|
160
|
+
expect(recomputeCount).toBe(2);
|
|
161
|
+
expect(com1()).toBe(4);
|
|
162
|
+
expect(com1()).toBe(4);
|
|
163
|
+
com1.notifySubscribers(5);
|
|
164
|
+
expect(newValue).toBe(5);
|
|
165
|
+
expect(com1()).toBe(5);
|
|
166
|
+
expect(recomputeCount).toBe(2);
|
|
167
|
+
});
|
|
168
|
+
it('should allow configuring a write function', () => {
|
|
169
|
+
const obs1 = (0, observable_1.observable)(1);
|
|
170
|
+
const com1 = (0, observable_1.computed)({
|
|
171
|
+
read: () => obs1() + 1,
|
|
172
|
+
write: (val) => obs1(val),
|
|
173
|
+
});
|
|
174
|
+
expect(com1()).toBe(2);
|
|
175
|
+
com1(2);
|
|
176
|
+
expect(obs1()).toBe(2);
|
|
177
|
+
expect(com1()).toBe(3);
|
|
178
|
+
obs1(3);
|
|
179
|
+
expect(obs1()).toBe(3);
|
|
180
|
+
expect(com1()).toBe(4);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type RequireFn = (id: string) => any;
|
|
2
|
+
/**
|
|
3
|
+
* Get a safe require function.
|
|
4
|
+
*
|
|
5
|
+
* - Uses the injected one if provided
|
|
6
|
+
* - Falls back to Node's require in CJS
|
|
7
|
+
* - Falls back to createRequire in ESM
|
|
8
|
+
*/
|
|
9
|
+
export declare function getRequire(injected?: RequireFn): Promise<RequireFn>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRequire = getRequire;
|
|
4
|
+
/**
|
|
5
|
+
* Get a safe require function.
|
|
6
|
+
*
|
|
7
|
+
* - Uses the injected one if provided
|
|
8
|
+
* - Falls back to Node's require in CJS
|
|
9
|
+
* - Falls back to createRequire in ESM
|
|
10
|
+
*/
|
|
11
|
+
async function getRequire(injected) {
|
|
12
|
+
if (injected)
|
|
13
|
+
return injected;
|
|
14
|
+
// Try CommonJS require
|
|
15
|
+
if (typeof require === "function") {
|
|
16
|
+
return require;
|
|
17
|
+
}
|
|
18
|
+
// Try ESM fallback: createRequire(import.meta.url)
|
|
19
|
+
try {
|
|
20
|
+
const mod = await Promise.resolve().then(() => require("module"));
|
|
21
|
+
// Use import.meta.url if TS target supports it, else __filename
|
|
22
|
+
const urlOrPath =
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
typeof import.meta !== "undefined" && import.meta.url ? import.meta.url
|
|
25
|
+
: __filename;
|
|
26
|
+
return mod.createRequire(urlOrPath);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw new Error("No require function available. You must provide one to the package loader.");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./package-loader";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./package-loader"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DataContext } from "../context/data-context";
|
|
2
|
+
import type { IPeersPackage } from "../types/peers-package";
|
|
3
|
+
import { IPackage } from "../data/packages";
|
|
4
|
+
export declare class PackageLoader {
|
|
5
|
+
readonly dataContext: DataContext;
|
|
6
|
+
private packageInstances;
|
|
7
|
+
require: (<T>(module: string) => T) | undefined;
|
|
8
|
+
constructor(dataContext: DataContext);
|
|
9
|
+
loadAllPackages(opts?: {
|
|
10
|
+
force?: boolean;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
loadPackage(pkg: IPackage, opts?: {
|
|
13
|
+
force?: boolean;
|
|
14
|
+
}): Promise<IPeersPackage | null>;
|
|
15
|
+
}
|
|
16
|
+
export declare function setDefaultRequire(require: (<T>(module: string) => T)): void;
|