@peers-app/peers-sdk 0.23.2 → 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/group-share.d.ts +13 -0
- package/dist/data/group-share.js +32 -8
- package/dist/data/group-share.test.d.ts +1 -0
- package/dist/data/group-share.test.js +110 -0
- 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/group-invite/group-invite.types.d.ts +15 -5
- 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
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const package_table_identity_1 = require("../data/package-table-identity");
|
|
4
|
+
const field_type_1 = require("../types/field-type");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const isolated_table_gateway_1 = require("./isolated-table-gateway");
|
|
7
|
+
function makeDeclaration(overrides = {}) {
|
|
8
|
+
const packageId = overrides.packageId ?? (0, utils_1.newid)();
|
|
9
|
+
return {
|
|
10
|
+
packageId,
|
|
11
|
+
tableName: "State",
|
|
12
|
+
description: "Owned state",
|
|
13
|
+
primaryKeyName: "stateId",
|
|
14
|
+
fields: [
|
|
15
|
+
{ name: "stateId", type: field_type_1.FieldType.id },
|
|
16
|
+
{ name: "count", type: field_type_1.FieldType.number },
|
|
17
|
+
],
|
|
18
|
+
...overrides,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
describe("isolated package table gateway", () => {
|
|
22
|
+
test("memory gateway binds a table and persists get/save across re-register", async () => {
|
|
23
|
+
const gateway = (0, isolated_table_gateway_1.createMemoryIsolatedPackageTableGateway)();
|
|
24
|
+
const declaration = makeDeclaration();
|
|
25
|
+
const recordId = (0, utils_1.newid)();
|
|
26
|
+
await gateway.register(declaration);
|
|
27
|
+
expect(await gateway.get(declaration, recordId)).toBeUndefined();
|
|
28
|
+
await expect(gateway.save(declaration, { stateId: recordId, count: 1 })).resolves.toEqual({
|
|
29
|
+
stateId: recordId,
|
|
30
|
+
count: 1,
|
|
31
|
+
});
|
|
32
|
+
await expect(gateway.get(declaration, recordId)).resolves.toEqual({
|
|
33
|
+
stateId: recordId,
|
|
34
|
+
count: 1,
|
|
35
|
+
});
|
|
36
|
+
await expect(gateway.call(declaration, "count", [{}])).resolves.toBe(1);
|
|
37
|
+
await expect(gateway.call(declaration, "list", [{ count: 1 }])).resolves.toEqual([
|
|
38
|
+
{ stateId: recordId, count: 1 },
|
|
39
|
+
]);
|
|
40
|
+
await expect(gateway.call(declaration, "findOne", [{ count: 1 }])).resolves.toEqual({
|
|
41
|
+
stateId: recordId,
|
|
42
|
+
count: 1,
|
|
43
|
+
});
|
|
44
|
+
await gateway.register(declaration);
|
|
45
|
+
await expect(gateway.get(declaration, recordId)).resolves.toEqual({
|
|
46
|
+
stateId: recordId,
|
|
47
|
+
count: 1,
|
|
48
|
+
});
|
|
49
|
+
await expect(gateway.call(declaration, "update", [{ stateId: recordId, count: 2 }])).resolves.toEqual({ stateId: recordId, count: 2 });
|
|
50
|
+
await expect(gateway.call(declaration, "delete", [recordId])).resolves.toBeUndefined();
|
|
51
|
+
await expect(gateway.call(declaration, "get", [recordId])).resolves.toBeUndefined();
|
|
52
|
+
});
|
|
53
|
+
test("memory gateway denies undeclared tables and separates package-local names", async () => {
|
|
54
|
+
const gateway = (0, isolated_table_gateway_1.createMemoryIsolatedPackageTableGateway)();
|
|
55
|
+
const owner = makeDeclaration();
|
|
56
|
+
const other = makeDeclaration({ tableName: owner.tableName });
|
|
57
|
+
const recordId = (0, utils_1.newid)();
|
|
58
|
+
await gateway.register(owner);
|
|
59
|
+
await gateway.register(other);
|
|
60
|
+
await gateway.save(owner, { stateId: recordId, count: 1 });
|
|
61
|
+
await gateway.save(other, { stateId: recordId, count: 2 });
|
|
62
|
+
await expect(gateway.get(owner, recordId)).resolves.toEqual({
|
|
63
|
+
stateId: recordId,
|
|
64
|
+
count: 1,
|
|
65
|
+
});
|
|
66
|
+
await expect(gateway.get(other, recordId)).resolves.toEqual({
|
|
67
|
+
stateId: recordId,
|
|
68
|
+
count: 2,
|
|
69
|
+
});
|
|
70
|
+
await expect(gateway.get({ ...owner, packageId: (0, utils_1.newid)() }, (0, utils_1.newid)())).rejects.toThrow(/Undeclared isolated table/);
|
|
71
|
+
});
|
|
72
|
+
test("memory gateway preserves Date and binary fields without retaining references", async () => {
|
|
73
|
+
const gateway = (0, isolated_table_gateway_1.createMemoryIsolatedPackageTableGateway)();
|
|
74
|
+
const declaration = makeDeclaration({
|
|
75
|
+
fields: [
|
|
76
|
+
{ name: "stateId", type: field_type_1.FieldType.id },
|
|
77
|
+
{ name: "count", type: field_type_1.FieldType.number },
|
|
78
|
+
{ name: "savedAt", type: field_type_1.FieldType.Date },
|
|
79
|
+
{ name: "payload", type: field_type_1.FieldType.blob },
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
const recordId = (0, utils_1.newid)();
|
|
83
|
+
const input = {
|
|
84
|
+
stateId: recordId,
|
|
85
|
+
count: 1,
|
|
86
|
+
savedAt: new Date("2026-08-24T12:00:00.000Z"),
|
|
87
|
+
payload: new Uint8Array([4, 5, 6]),
|
|
88
|
+
};
|
|
89
|
+
await gateway.register(declaration);
|
|
90
|
+
await gateway.save(declaration, input);
|
|
91
|
+
input.savedAt.setUTCFullYear(2030);
|
|
92
|
+
input.payload[0] = 9;
|
|
93
|
+
await expect(gateway.get(declaration, recordId)).resolves.toEqual({
|
|
94
|
+
stateId: recordId,
|
|
95
|
+
count: 1,
|
|
96
|
+
savedAt: new Date("2026-08-24T12:00:00.000Z"),
|
|
97
|
+
payload: new Uint8Array([4, 5, 6]),
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
test("memory gateway preserves rows across upgrades and rejects unsafe schema changes", async () => {
|
|
101
|
+
const gateway = (0, isolated_table_gateway_1.createMemoryIsolatedPackageTableGateway)();
|
|
102
|
+
const v1 = makeDeclaration({ versionNumber: 1 });
|
|
103
|
+
const rowId = (0, utils_1.newid)();
|
|
104
|
+
await gateway.register(v1);
|
|
105
|
+
await gateway.save(v1, { stateId: rowId, count: 1 });
|
|
106
|
+
const conflictingV1 = {
|
|
107
|
+
...v1,
|
|
108
|
+
fields: [...v1.fields, { name: "other", type: field_type_1.FieldType.string, optional: true }],
|
|
109
|
+
};
|
|
110
|
+
await expect(gateway.register(conflictingV1)).rejects.toThrow(/different schemas at version 1/);
|
|
111
|
+
const v2 = { ...conflictingV1, versionNumber: 2 };
|
|
112
|
+
await gateway.register(v2);
|
|
113
|
+
await expect(gateway.get(v2, rowId)).resolves.toEqual({ stateId: rowId, count: 1 });
|
|
114
|
+
await expect(gateway.register(v1)).rejects.toThrow(/schema downgrade/);
|
|
115
|
+
await expect(gateway.register(makeDeclaration({ tableName: 'Unsafe"; DROP TABLE State; --' }))).rejects.toThrow(/only letters, numbers, and underscores/);
|
|
116
|
+
});
|
|
117
|
+
test("rejects a table batch without publishing declarations that came before the conflict", async () => {
|
|
118
|
+
const gateway = (0, isolated_table_gateway_1.createMemoryIsolatedPackageTableGateway)();
|
|
119
|
+
const first = makeDeclaration({ versionNumber: 1 });
|
|
120
|
+
const conflicting = {
|
|
121
|
+
...first,
|
|
122
|
+
fields: [...first.fields, { name: "other", type: field_type_1.FieldType.string, optional: true }],
|
|
123
|
+
};
|
|
124
|
+
await expect(gateway.registerBatch([first, conflicting])).rejects.toThrow(/different schemas at version 1/);
|
|
125
|
+
await expect(gateway.get(first, (0, utils_1.newid)())).rejects.toThrow(/Undeclared isolated table/);
|
|
126
|
+
});
|
|
127
|
+
test("preflights every stored schema before applying a data-context table batch", async () => {
|
|
128
|
+
const first = makeDeclaration({ versionNumber: 1 });
|
|
129
|
+
const second = makeDeclaration({
|
|
130
|
+
packageId: first.packageId,
|
|
131
|
+
tableName: "OtherState",
|
|
132
|
+
versionNumber: 1,
|
|
133
|
+
});
|
|
134
|
+
const secondTableId = (0, package_table_identity_1.packageScopedTableId)(second.packageId, second.tableName);
|
|
135
|
+
const storedDefinitions = new Map([
|
|
136
|
+
[
|
|
137
|
+
secondTableId,
|
|
138
|
+
{
|
|
139
|
+
tableId: secondTableId,
|
|
140
|
+
name: `${second.tableName}_${second.packageId}`,
|
|
141
|
+
metaData: {
|
|
142
|
+
tableId: secondTableId,
|
|
143
|
+
packageId: second.packageId,
|
|
144
|
+
name: second.tableName,
|
|
145
|
+
description: second.description,
|
|
146
|
+
primaryKeyName: second.primaryKeyName,
|
|
147
|
+
fields: second.fields,
|
|
148
|
+
versionNumber: 2,
|
|
149
|
+
},
|
|
150
|
+
versionNumber: 2,
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
]);
|
|
154
|
+
const table = {
|
|
155
|
+
get: jest.fn(async (id) => storedDefinitions.get(id)),
|
|
156
|
+
save: jest.fn(async (record) => record),
|
|
157
|
+
};
|
|
158
|
+
const registerTableDefinition = jest.fn();
|
|
159
|
+
const gateway = (0, isolated_table_gateway_1.createIsolatedPackageTableGateway)({
|
|
160
|
+
tableContainer: { registerTableDefinition, getTable: jest.fn(() => table) },
|
|
161
|
+
});
|
|
162
|
+
await expect(gateway.registerBatch([first, second])).rejects.toThrow(/schema downgrade/);
|
|
163
|
+
expect(table.save).not.toHaveBeenCalled();
|
|
164
|
+
expect(registerTableDefinition).not.toHaveBeenCalled();
|
|
165
|
+
});
|
|
166
|
+
test("data-context gateway registers the host table and copies rows", async () => {
|
|
167
|
+
const declaration = makeDeclaration();
|
|
168
|
+
const recordId = (0, utils_1.newid)();
|
|
169
|
+
const rows = new Map();
|
|
170
|
+
const table = {
|
|
171
|
+
get: jest.fn(async (id) => rows.get(id)),
|
|
172
|
+
save: jest.fn(async (record) => {
|
|
173
|
+
rows.set(String(record.stateId), record);
|
|
174
|
+
return record;
|
|
175
|
+
}),
|
|
176
|
+
};
|
|
177
|
+
const registerTableDefinition = jest.fn();
|
|
178
|
+
const getTable = jest.fn(() => table);
|
|
179
|
+
const gateway = (0, isolated_table_gateway_1.createIsolatedPackageTableGateway)({
|
|
180
|
+
tableContainer: { registerTableDefinition, getTable },
|
|
181
|
+
});
|
|
182
|
+
await gateway.register(declaration);
|
|
183
|
+
expect(registerTableDefinition).toHaveBeenCalled();
|
|
184
|
+
await gateway.save(declaration, { stateId: recordId, count: 4 });
|
|
185
|
+
expect(registerTableDefinition).toHaveBeenCalledWith(expect.objectContaining({
|
|
186
|
+
metaData: expect.objectContaining({
|
|
187
|
+
tableId: (0, package_table_identity_1.packageScopedTableId)(declaration.packageId, declaration.tableName),
|
|
188
|
+
packageId: declaration.packageId,
|
|
189
|
+
name: "State",
|
|
190
|
+
primaryKeyName: "stateId",
|
|
191
|
+
}),
|
|
192
|
+
}), { overwrite: true });
|
|
193
|
+
const registeredMetaData = registerTableDefinition.mock.calls[0][0].metaData;
|
|
194
|
+
expect(registeredMetaData.tableId).toBe((0, package_table_identity_1.packageScopedTableId)(declaration.packageId, declaration.tableName));
|
|
195
|
+
expect((0, utils_1.getFullTableName)(registeredMetaData)).toBe(`${declaration.tableName}_${declaration.packageId}`);
|
|
196
|
+
expect(getTable).toHaveBeenCalled();
|
|
197
|
+
await expect(gateway.get(declaration, recordId)).resolves.toEqual({
|
|
198
|
+
stateId: recordId,
|
|
199
|
+
count: 4,
|
|
200
|
+
});
|
|
201
|
+
await expect(gateway.call(declaration, "get", [recordId])).resolves.toEqual({
|
|
202
|
+
stateId: recordId,
|
|
203
|
+
count: 4,
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy a value accepted by the isolated package boundary without losing
|
|
3
|
+
* Peers' Date or binary field types.
|
|
4
|
+
*
|
|
5
|
+
* The worker codec performs the same authority-boundary validation. Gateways
|
|
6
|
+
* repeat the copy so in-process tests and host-side adapters cannot retain
|
|
7
|
+
* mutable guest references.
|
|
8
|
+
*
|
|
9
|
+
* @param value Value to copy.
|
|
10
|
+
* @returns A detached value containing only supported primitives, arrays,
|
|
11
|
+
* plain objects, Dates, and Uint8Arrays.
|
|
12
|
+
* @throws When a value is cyclic, non-finite, or has an unsupported prototype.
|
|
13
|
+
*/
|
|
14
|
+
export declare function copyIsolatedValue<T>(value: T): T;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyIsolatedValue = copyIsolatedValue;
|
|
4
|
+
/**
|
|
5
|
+
* Copy a value accepted by the isolated package boundary without losing
|
|
6
|
+
* Peers' Date or binary field types.
|
|
7
|
+
*
|
|
8
|
+
* The worker codec performs the same authority-boundary validation. Gateways
|
|
9
|
+
* repeat the copy so in-process tests and host-side adapters cannot retain
|
|
10
|
+
* mutable guest references.
|
|
11
|
+
*
|
|
12
|
+
* @param value Value to copy.
|
|
13
|
+
* @returns A detached value containing only supported primitives, arrays,
|
|
14
|
+
* plain objects, Dates, and Uint8Arrays.
|
|
15
|
+
* @throws When a value is cyclic, non-finite, or has an unsupported prototype.
|
|
16
|
+
*/
|
|
17
|
+
function copyIsolatedValue(value) {
|
|
18
|
+
return copyValue(value, new WeakSet());
|
|
19
|
+
}
|
|
20
|
+
function copyValue(value, seen) {
|
|
21
|
+
if (value === null ||
|
|
22
|
+
typeof value === "string" ||
|
|
23
|
+
typeof value === "boolean" ||
|
|
24
|
+
value === undefined) {
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
if (typeof value === "number") {
|
|
28
|
+
if (!Number.isFinite(value)) {
|
|
29
|
+
throw new Error("Isolated value numbers must be finite");
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
if (typeof value !== "object") {
|
|
34
|
+
throw new Error("Isolated value contains an unsupported value");
|
|
35
|
+
}
|
|
36
|
+
if (seen.has(value)) {
|
|
37
|
+
throw new Error("Isolated value must not contain cycles");
|
|
38
|
+
}
|
|
39
|
+
if (value instanceof Date) {
|
|
40
|
+
const time = value.getTime();
|
|
41
|
+
if (!Number.isFinite(time)) {
|
|
42
|
+
throw new Error("Isolated value contains an invalid Date");
|
|
43
|
+
}
|
|
44
|
+
return new Date(time);
|
|
45
|
+
}
|
|
46
|
+
if (value instanceof Uint8Array) {
|
|
47
|
+
return new Uint8Array(value);
|
|
48
|
+
}
|
|
49
|
+
const prototype = Object.getPrototypeOf(value);
|
|
50
|
+
if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) {
|
|
51
|
+
throw new Error("Isolated value contains an unsupported object");
|
|
52
|
+
}
|
|
53
|
+
seen.add(value);
|
|
54
|
+
try {
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
return value.map((item) => copyValue(item, seen));
|
|
57
|
+
}
|
|
58
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, copyValue(item, seen)]));
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
seen.delete(value);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -1,28 +1,139 @@
|
|
|
1
1
|
import type { DataContext } from "../context/data-context";
|
|
2
|
+
import { type IContractProviderEndpointRequest } from "../contracts/contract-provider-router";
|
|
3
|
+
import { type IContractConsumer, type IContractProviderEndpoint } from "../contracts/contract-proxy";
|
|
2
4
|
import { ContractRegistry } from "../contracts/registry";
|
|
5
|
+
import type { IConsumedContract } from "../contracts/types";
|
|
3
6
|
import { type IPackage } from "../data/packages";
|
|
4
7
|
import type { IPeersPackage } from "../types/peers-package";
|
|
8
|
+
import { type IIsolatedPackageRuntime } from "./isolated-runtime";
|
|
5
9
|
import "../contracts/system";
|
|
10
|
+
/** Host-only options for {@link PackageLoader.resolveContractEndpoint}. */
|
|
11
|
+
export interface IPackageContractEndpointOptions {
|
|
12
|
+
/** Provider package selected from trusted registry state. */
|
|
13
|
+
providerPackageId?: string;
|
|
14
|
+
/** Host-only package-variable resolver appended to local tool context. */
|
|
15
|
+
resolveVariable?: (variableName: string, requestingToolId: string) => Promise<string>;
|
|
16
|
+
/** Prevent recursion when an isolated consumer asks for a host provider. */
|
|
17
|
+
resolverOnly?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Loads package versions for one {@link DataContext}.
|
|
21
|
+
*
|
|
22
|
+
* Isolated artifacts (magic-header JSON) are installed without host
|
|
23
|
+
* evaluation. Legacy `package.bundle.js` files still evaluate in-process.
|
|
24
|
+
*/
|
|
6
25
|
export declare class PackageLoader {
|
|
7
26
|
readonly dataContext: DataContext;
|
|
27
|
+
/** Host-injected SDK module used as the `peers-sdk` / `PeersSDK` require. */
|
|
8
28
|
static PeersSDK: any;
|
|
29
|
+
/** Host-injected Zod module used as the `zod` require. */
|
|
9
30
|
static Zod: any;
|
|
10
31
|
private packageInstances;
|
|
11
32
|
/** Packages that were installed via the contract-based path (tools/assistants/tables already saved with packageId). */
|
|
12
33
|
private contractInstalledPackages;
|
|
34
|
+
/** Packages installed through the isolated runtime (no host eval). */
|
|
35
|
+
private isolatedPackageIds;
|
|
13
36
|
/**
|
|
14
37
|
* In-memory contract providers for this data context. Seeded with system
|
|
15
38
|
* contracts at construction; package providers are added via
|
|
16
|
-
* {@link installContractPackage}.
|
|
39
|
+
* {@link installContractPackage} or the isolated runtime.
|
|
17
40
|
*/
|
|
18
41
|
readonly contractRegistry: ContractRegistry;
|
|
42
|
+
/** Optional isolated-provider supervisor created from the host factory. */
|
|
43
|
+
readonly isolatedRuntime?: IIsolatedPackageRuntime;
|
|
44
|
+
/** Optional host `require` used when reading local bundles or evaluating legacy packages. */
|
|
19
45
|
require: (<T>(module: string) => T) | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* @param dataContext - Owning personal or group data context. Its
|
|
48
|
+
* `tableContainer` must already be assigned so isolated packages that
|
|
49
|
+
* declare tables receive a host gateway.
|
|
50
|
+
*/
|
|
20
51
|
constructor(dataContext: DataContext);
|
|
21
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Returns true if a package was installed via the contract-based
|
|
54
|
+
* `definePackage()` path or as an isolated artifact.
|
|
55
|
+
*
|
|
56
|
+
* @param packageId - Package to query.
|
|
57
|
+
*/
|
|
22
58
|
isContractInstalled(packageId: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Returns true if `packageId` was installed as an isolated artifact.
|
|
61
|
+
*
|
|
62
|
+
* @param packageId - Package to query.
|
|
63
|
+
*/
|
|
64
|
+
isIsolatedInstalled(packageId: string): boolean;
|
|
65
|
+
/** Return whether this host configured an isolated-package runtime. */
|
|
66
|
+
supportsIsolatedPackages(): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Return the active provider selected by this data context's trusted registry.
|
|
69
|
+
*
|
|
70
|
+
* @param contractId - Target contract identity.
|
|
71
|
+
* @param version - Target contract version.
|
|
72
|
+
*/
|
|
73
|
+
getActiveContractProviderPackageId(contractId: string, version: number): string | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Resolve one authorized endpoint through the registry-selected provider.
|
|
76
|
+
*
|
|
77
|
+
* Isolated providers are delegated to the host runtime; resolver-backed
|
|
78
|
+
* providers are looked up by provider package. Contracts that predate package
|
|
79
|
+
* registration may still use their legacy unscoped resolver.
|
|
80
|
+
* Provider identity comes only from trusted registry/options state, never
|
|
81
|
+
* from an {@link import("../contracts/contract-proxy").IContractCall}.
|
|
82
|
+
*
|
|
83
|
+
* @param request - Authorized contract route and notification sink.
|
|
84
|
+
* @param opts - Trusted provider override and host-only resolver capabilities.
|
|
85
|
+
* @throws If no provider or matching endpoint implementation is available.
|
|
86
|
+
*/
|
|
87
|
+
resolveContractEndpoint(request: IContractProviderEndpointRequest, opts?: IPackageContractEndpointOptions): Promise<IContractProviderEndpoint>;
|
|
88
|
+
/**
|
|
89
|
+
* Bind a legacy package's declared consume to its selected provider.
|
|
90
|
+
*
|
|
91
|
+
* The returned proxy can target either a resolver-backed or isolated provider.
|
|
92
|
+
* Its provider choice is captured from {@link ContractRegistry.selectProvider}
|
|
93
|
+
* before any consumer call payload is processed.
|
|
94
|
+
*
|
|
95
|
+
* @param dependency - Validated package consume declaration.
|
|
96
|
+
* @returns A live consumer proxy, or `undefined` when no provider matches.
|
|
97
|
+
*/
|
|
98
|
+
resolveConsumedContract(dependency: IConsumedContract): Promise<IContractConsumer | undefined>;
|
|
99
|
+
/**
|
|
100
|
+
* Resolve a sandbox-backed provider endpoint when this context owns an
|
|
101
|
+
* isolated provider for the requested contract.
|
|
102
|
+
*
|
|
103
|
+
* @param request - Authorized contract/version/data-context route.
|
|
104
|
+
*/
|
|
105
|
+
resolveIsolatedEndpoint(request: IContractProviderEndpointRequest): Promise<IContractProviderEndpoint | undefined>;
|
|
106
|
+
/**
|
|
107
|
+
* Stop an isolated worker (if any) and drop the in-memory package instance.
|
|
108
|
+
*
|
|
109
|
+
* @param packageId - Package to unload.
|
|
110
|
+
*/
|
|
111
|
+
unloadPackage(packageId: string): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Dispose the isolated runtime for this data context.
|
|
114
|
+
*/
|
|
115
|
+
dispose(): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Resolve and load every non-disabled package in this data context.
|
|
118
|
+
* Disabled packages that were previously loaded are unloaded.
|
|
119
|
+
*
|
|
120
|
+
* @param opts - Forwarded to {@link resolveDevicePackageVersion}.
|
|
121
|
+
*/
|
|
23
122
|
loadAllPackages(opts?: {
|
|
24
123
|
force?: boolean;
|
|
25
124
|
}): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Load one package version into this data context.
|
|
127
|
+
*
|
|
128
|
+
* Isolated artifacts are parsed and installed without evaluating provider
|
|
129
|
+
* source. A recognized but malformed isolated envelope fails closed and
|
|
130
|
+
* never falls back to `new Function`. When `localPath` points at a rebuilt
|
|
131
|
+
* isolated `dist/package.bundle.js`, that disk artifact wins over a stale
|
|
132
|
+
* stored Files bundle so local-dev packages pick up new contract versions.
|
|
133
|
+
*
|
|
134
|
+
* @param pkg - Package row.
|
|
135
|
+
* @param opts - Optional force reload, local path fallback, and PV id.
|
|
136
|
+
*/
|
|
26
137
|
loadPackage(pkg: IPackage, opts?: {
|
|
27
138
|
force?: boolean;
|
|
28
139
|
localPath?: string;
|
|
@@ -31,11 +142,19 @@ export declare class PackageLoader {
|
|
|
31
142
|
private _readLocalBundle;
|
|
32
143
|
/**
|
|
33
144
|
* Post-correction: if the package definition carries a version string,
|
|
34
|
-
* update the
|
|
35
|
-
*
|
|
145
|
+
* update the selected IPackageVersion record to match — but only when that
|
|
146
|
+
* selected version is the mutable `dev` working copy. Never rewrite
|
|
36
147
|
* beta/stable version labels from a local package.json bump.
|
|
37
148
|
*/
|
|
38
149
|
private correctPackageVersion;
|
|
150
|
+
private _loadBundle;
|
|
151
|
+
private _installIsolated;
|
|
39
152
|
private _evaluateBundle;
|
|
40
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Set the process-wide `require` used when a {@link PackageLoader} instance
|
|
156
|
+
* does not supply its own.
|
|
157
|
+
*
|
|
158
|
+
* @param require - Host `require` function.
|
|
159
|
+
*/
|
|
41
160
|
export declare function setDefaultRequire(require: <T>(module: string) => T): void;
|