@peers-app/peers-sdk 0.23.4 → 0.23.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.
Files changed (75) hide show
  1. package/dist/context/data-context.d.ts +36 -5
  2. package/dist/context/data-context.js +44 -9
  3. package/dist/context/user-context.d.ts +44 -0
  4. package/dist/context/user-context.js +91 -12
  5. package/dist/contracts/__tests__/contract-provider-router.test.js +26 -0
  6. package/dist/contracts/__tests__/contract-resolvers.test.js +44 -0
  7. package/dist/contracts/__tests__/registry.test.js +104 -0
  8. package/dist/contracts/contract-provider-router.d.ts +21 -0
  9. package/dist/contracts/contract-provider-router.js +31 -5
  10. package/dist/contracts/contract-proxy.d.ts +3 -0
  11. package/dist/contracts/contract-proxy.js +3 -0
  12. package/dist/contracts/contract-resolvers.d.ts +21 -3
  13. package/dist/contracts/contract-resolvers.js +105 -32
  14. package/dist/contracts/index.d.ts +3 -3
  15. package/dist/contracts/registry.d.ts +59 -0
  16. package/dist/contracts/registry.js +155 -25
  17. package/dist/contracts/system-contracts.js +3 -1
  18. package/dist/data/index.d.ts +1 -0
  19. package/dist/data/index.js +1 -0
  20. package/dist/data/orm/types.d.ts +19 -0
  21. package/dist/data/orm/types.js +11 -0
  22. package/dist/data/package-table-identity.d.ts +46 -0
  23. package/dist/data/package-table-identity.js +71 -0
  24. package/dist/data/package-table-identity.test.d.ts +1 -0
  25. package/dist/data/package-table-identity.test.js +46 -0
  26. package/dist/data/package-version-resolver.d.ts +13 -0
  27. package/dist/data/package-version-resolver.js +142 -6
  28. package/dist/data/package-version-resolver.test.js +42 -0
  29. package/dist/data/persistent-var-identity.d.ts +37 -0
  30. package/dist/data/persistent-var-identity.js +69 -0
  31. package/dist/data/persistent-vars.d.ts +3 -5
  32. package/dist/data/persistent-vars.js +25 -13
  33. package/dist/data/persistent-vars.package-scope.test.d.ts +1 -0
  34. package/dist/data/persistent-vars.package-scope.test.js +27 -0
  35. package/dist/data/tools.d.ts +3 -3
  36. package/dist/package-installer/index.d.ts +1 -0
  37. package/dist/package-installer/index.js +1 -0
  38. package/dist/package-installer/package-cloner.d.ts +1 -1
  39. package/dist/package-installer/package-cloner.js +11 -16
  40. package/dist/package-installer/package-cloner.test.js +5 -3
  41. package/dist/package-installer/package-creator.d.ts +4 -3
  42. package/dist/package-installer/package-creator.js +13 -5
  43. package/dist/package-installer/package-creator.test.js +19 -0
  44. package/dist/package-installer/package-dev-tools.d.ts +30 -0
  45. package/dist/package-installer/package-dev-tools.js +63 -0
  46. package/dist/package-installer/package-dev-tools.test.d.ts +1 -0
  47. package/dist/package-installer/package-dev-tools.test.js +64 -0
  48. package/dist/package-loader/contract-package-loader.js +20 -8
  49. package/dist/package-loader/contract-package-loader.test.js +16 -0
  50. package/dist/package-loader/index.d.ts +4 -0
  51. package/dist/package-loader/index.js +4 -0
  52. package/dist/package-loader/isolated-artifact.d.ts +233 -0
  53. package/dist/package-loader/isolated-artifact.js +643 -0
  54. package/dist/package-loader/isolated-artifact.test.d.ts +1 -0
  55. package/dist/package-loader/isolated-artifact.test.js +270 -0
  56. package/dist/package-loader/isolated-persistent-var-gateway.d.ts +20 -0
  57. package/dist/package-loader/isolated-persistent-var-gateway.js +106 -0
  58. package/dist/package-loader/isolated-persistent-var-gateway.test.d.ts +1 -0
  59. package/dist/package-loader/isolated-persistent-var-gateway.test.js +56 -0
  60. package/dist/package-loader/isolated-runtime.d.ts +229 -0
  61. package/dist/package-loader/isolated-runtime.js +37 -0
  62. package/dist/package-loader/isolated-table-gateway.d.ts +16 -0
  63. package/dist/package-loader/isolated-table-gateway.js +375 -0
  64. package/dist/package-loader/isolated-table-gateway.test.d.ts +1 -0
  65. package/dist/package-loader/isolated-table-gateway.test.js +206 -0
  66. package/dist/package-loader/isolated-value.d.ts +14 -0
  67. package/dist/package-loader/isolated-value.js +63 -0
  68. package/dist/package-loader/package-loader.d.ts +123 -4
  69. package/dist/package-loader/package-loader.js +417 -46
  70. package/dist/package-loader/package-loader.test.js +478 -12
  71. package/dist/package-loader/resolve-consumed-contracts.d.ts +3 -3
  72. package/dist/package-loader/resolve-consumed-contracts.js +18 -10
  73. package/dist/utils.d.ts +21 -2
  74. package/dist/utils.js +46 -7
  75. package/package.json +1 -1
@@ -0,0 +1,233 @@
1
+ import type { IAlsoImplementsDeclaration, IConsumedContract, IContractDefinition, IContractObservable, IContractTool } from "../contracts/types";
2
+ import { type PersistentVarScope } from "../data/persistent-var-identity";
3
+ import type { IAppNav } from "../types/app-nav";
4
+ import { type IField } from "../types/field-type";
5
+ /**
6
+ * First line of an isolated package bundle. Existing `package.bundle.js`
7
+ * artifacts never start with this token, so the loader can detect the
8
+ * opt-in format without evaluating source.
9
+ */
10
+ export declare const ISOLATED_PACKAGE_MAGIC = "PEERS_ISOLATED_PACKAGE_V1";
11
+ /**
12
+ * Stable tool identity for isolated (and future contract-first) tools:
13
+ * `contractId + version + toolName`.
14
+ */
15
+ export interface IIsolatedContractToolRef {
16
+ contractId: string;
17
+ version: number;
18
+ toolName: string;
19
+ }
20
+ /**
21
+ * Tool advertised on an isolated provided contract.
22
+ *
23
+ * Shape matches {@link IContractTool}. `suggestedAccessLevel` is a package
24
+ * hint only — the host keeps the effective level at Self until an
25
+ * administrator approves it.
26
+ */
27
+ export interface IIsolatedContractTool extends Omit<IContractTool, "inputFields" | "outputFields"> {
28
+ /** Defaults to `[]` during validation when omitted. */
29
+ inputFields?: IField[];
30
+ /** Defaults to `[]` during validation when omitted. */
31
+ outputFields?: IField[];
32
+ /** Package suggestion only. Effective level stays Self until approved. */
33
+ suggestedAccessLevel?: number;
34
+ }
35
+ /**
36
+ * Private table schema declared by an isolated package.
37
+ *
38
+ * The host derives package-scoped physical identity. Contract consumers never
39
+ * receive this schema or raw table access.
40
+ */
41
+ export interface IIsolatedPackageTable {
42
+ name: string;
43
+ description?: string;
44
+ primaryKeyName: string;
45
+ fields: IField[];
46
+ /** Schema version for host table-definition updates. Defaults to `1`. */
47
+ versionNumber?: number;
48
+ }
49
+ /** Name-only reference that exposes one package table through a contract. */
50
+ export interface IIsolatedContractTableRef {
51
+ name: string;
52
+ }
53
+ /** Trusted manifest binding from a contract observable to a package-owned pvar. */
54
+ export interface IIsolatedContractPersistentVarBinding {
55
+ scope: PersistentVarScope;
56
+ name: string;
57
+ defaultValue: unknown;
58
+ }
59
+ /** Observable contract member backed by a package-owned persistent variable. */
60
+ export interface IIsolatedContractObservable extends IContractObservable {
61
+ persistentVar: IIsolatedContractPersistentVarBinding;
62
+ }
63
+ /** Contract this package implements and serves from its isolated worker. */
64
+ export interface IIsolatedProvidedContract {
65
+ contractId: string;
66
+ version: number;
67
+ name: string;
68
+ description?: string;
69
+ tools: IIsolatedContractTool[];
70
+ /** Name-only references to package tables exposed to consumers. */
71
+ tables?: IIsolatedContractTableRef[];
72
+ /** Pvar-backed observable values exposed to consumers. */
73
+ observables?: IIsolatedContractObservable[];
74
+ /** Older contract versions this provider shape also satisfies. */
75
+ alsoImplements?: IAlsoImplementsDeclaration[];
76
+ }
77
+ /** Contract this package is allowed to call through the trusted host. */
78
+ export interface IIsolatedConsumedContract {
79
+ contractId: string;
80
+ version: number;
81
+ optional?: boolean;
82
+ providerPackageIds?: string[];
83
+ fallbackToDefaultProvider?: boolean;
84
+ }
85
+ /**
86
+ * Pure-data package description. Validated on the host; never executed there.
87
+ */
88
+ export interface IIsolatedPackageManifest {
89
+ packageId: string;
90
+ version: string;
91
+ provides: IIsolatedProvidedContract[];
92
+ consumes: IIsolatedConsumedContract[];
93
+ /** Package-owned table schemas. Contract references decide public exposure. */
94
+ tables?: IIsolatedPackageTable[];
95
+ appNavs?: IAppNav[];
96
+ }
97
+ /**
98
+ * Installable isolated package: declarative manifest plus provider source
99
+ * that may run only inside a supervised worker.
100
+ */
101
+ export interface IIsolatedPackageArtifact {
102
+ manifest: IIsolatedPackageManifest;
103
+ providerSource: string;
104
+ }
105
+ /** Outcome of installing one isolated artifact into a host runtime. */
106
+ export interface IIsolatedInstallResult {
107
+ packageId: string;
108
+ provided: Array<{
109
+ contractId: string;
110
+ version: number;
111
+ }>;
112
+ consumes: Array<{
113
+ contractId: string;
114
+ version: number;
115
+ optional?: boolean;
116
+ satisfied: boolean;
117
+ }>;
118
+ }
119
+ /** Snapshot of an installed isolated package (no provider source). */
120
+ export interface IIsolatedInstalledPackage {
121
+ packageId: string;
122
+ version: string;
123
+ provides: IIsolatedProvidedContract[];
124
+ consumes: IIsolatedConsumedContract[];
125
+ tables: IIsolatedPackageTable[];
126
+ definitions: IContractDefinition[];
127
+ appNavs?: IAppNav[];
128
+ }
129
+ /** Host-contract member guests use to request a consumed-contract tool call. */
130
+ export declare const ISOLATED_CONSUME_HOST_MEMBER = "contract.consume";
131
+ /** Host-contract member guests use to read or write a package-owned table. */
132
+ export declare const ISOLATED_TABLE_HOST_MEMBER = "package.table";
133
+ /** Host-contract member guests use to read or write package-prefixed pvars. */
134
+ export declare const ISOLATED_PERSISTENT_VAR_HOST_MEMBER = "package.pvar";
135
+ /**
136
+ * True when `bundle` starts with {@link ISOLATED_PACKAGE_MAGIC}.
137
+ *
138
+ * A recognized header must never fall through to `new Function` evaluation,
139
+ * even if the rest of the envelope is malformed.
140
+ *
141
+ * @param bundle - Package bundle text from Files or `dist/package.bundle.js`.
142
+ */
143
+ export declare function looksLikeIsolatedPackageArtifact(bundle: string): boolean;
144
+ /**
145
+ * Validate a wire-safe isolated package artifact. Does not evaluate
146
+ * `providerSource`.
147
+ *
148
+ * @param artifact - Parsed artifact object.
149
+ * @returns The same manifest after in-place field normalization.
150
+ * @throws If identity, contracts, tools, or source are invalid.
151
+ */
152
+ export declare function validateIsolatedPackageArtifact(artifact: IIsolatedPackageArtifact): IIsolatedPackageManifest;
153
+ /**
154
+ * Parse a magic-header + JSON isolated package bundle.
155
+ *
156
+ * @param bundle - Full package-bundle text.
157
+ * @returns The validated artifact.
158
+ * @throws If the magic header is present but the envelope is malformed.
159
+ */
160
+ export declare function parseIsolatedPackageArtifact(bundle: string): IIsolatedPackageArtifact;
161
+ /**
162
+ * Serialize an isolated artifact into the package-bundle slot format.
163
+ *
164
+ * @param artifact - Validated or soon-to-be-validated artifact.
165
+ */
166
+ export declare function serializeIsolatedPackageArtifact(artifact: IIsolatedPackageArtifact): string;
167
+ /**
168
+ * Convert a provided-contract declaration into an SDK contract definition.
169
+ *
170
+ * Name-only table references are resolved from the package's schema list.
171
+ * Persistent-variable bindings stay host-only and are omitted from the public
172
+ * observable definition.
173
+ *
174
+ * @param contract - Isolated provided-contract declaration.
175
+ * @param packageTables - Package-owned schemas available for contract exposure.
176
+ */
177
+ export declare function isolatedContractToDefinition(contract: IIsolatedProvidedContract, packageTables: IIsolatedPackageTable[]): IContractDefinition;
178
+ /**
179
+ * True when `consumes` names this exact contract version.
180
+ *
181
+ * @param consumes - Declared package dependencies.
182
+ * @param contractId - Target contract id.
183
+ * @param version - Target contract version.
184
+ */
185
+ export declare function packageDeclaresConsume(consumes: IIsolatedConsumedContract[], contractId: string, version: number): boolean;
186
+ /**
187
+ * True when the package advertises this tool on a provided contract.
188
+ *
189
+ * @param provides - Provided contracts from the manifest.
190
+ * @param contractId - Target contract id.
191
+ * @param version - Target contract version.
192
+ * @param toolName - Tool name on that contract.
193
+ */
194
+ export declare function packageProvidesTool(provides: IIsolatedProvidedContract[], contractId: string, version: number, toolName: string): boolean;
195
+ /**
196
+ * Return a consumer-facing table reference from a provided contract.
197
+ *
198
+ * @param provides Provided contracts from the manifest.
199
+ * @param contractId Target contract ID.
200
+ * @param version Target contract version.
201
+ * @param tableName Public table name.
202
+ */
203
+ export declare function findProvidedContractTable(provides: IIsolatedProvidedContract[], contractId: string, version: number, tableName: string): IIsolatedContractTableRef | undefined;
204
+ /**
205
+ * Return a pvar-backed observable from a provided contract.
206
+ *
207
+ * @param provides Provided contracts from the manifest.
208
+ * @param contractId Target contract ID.
209
+ * @param version Target contract version.
210
+ * @param observableName Public observable name.
211
+ */
212
+ export declare function findProvidedContractObservable(provides: IIsolatedProvidedContract[], contractId: string, version: number, observableName: string): IIsolatedContractObservable | undefined;
213
+ /**
214
+ * True when the package declares a private table.
215
+ *
216
+ * @param tables - Package-private table schemas.
217
+ * @param tableName - Package-local table name.
218
+ */
219
+ export declare function packageProvidesTable(tables: IIsolatedPackageTable[], tableName: string): boolean;
220
+ /**
221
+ * Return the declared table when this package owns it.
222
+ *
223
+ * @param tables - Package-private table schemas.
224
+ * @param tableName - Package-local table name.
225
+ */
226
+ export declare function findPackageTable(tables: IIsolatedPackageTable[], tableName: string): IIsolatedPackageTable | undefined;
227
+ /**
228
+ * Map isolated consume declarations onto the registry's
229
+ * {@link IConsumedContract} shape (no deferred handles).
230
+ *
231
+ * @param consumes - Isolated consume list.
232
+ */
233
+ export declare function toConsumedContracts(consumes: IIsolatedConsumedContract[]): IConsumedContract[];