@agoric/deploy-script-support 0.10.4-mainnet1B-dev-26244e8.0 → 0.10.4-orchestration-dev-096c4e8.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.
package/exported.js CHANGED
@@ -1,3 +1 @@
1
- import '@endo/bundle-source/exported.js';
2
-
3
1
  import './src/externalTypes.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/deploy-script-support",
3
- "version": "0.10.4-mainnet1B-dev-26244e8.0+26244e8",
3
+ "version": "0.10.4-orchestration-dev-096c4e8.0+096c4e8",
4
4
  "description": "Helpers and other support for writing deploy scripts",
5
5
  "type": "module",
6
6
  "main": "src/helpers.js",
@@ -13,7 +13,7 @@
13
13
  "test:xs": "exit 0",
14
14
  "lint-fix": "yarn lint:eslint --fix",
15
15
  "lint:eslint": "eslint .",
16
- "lint:types": "tsc -p jsconfig.json",
16
+ "lint:types": "tsc",
17
17
  "lint": "run-s --continue-on-error lint:*"
18
18
  },
19
19
  "repository": {
@@ -34,25 +34,26 @@
34
34
  },
35
35
  "homepage": "https://github.com/Agoric/agoric-sdk#readme",
36
36
  "dependencies": {
37
- "@agoric/assert": "0.6.1-mainnet1B-dev-26244e8.0+26244e8",
38
- "@agoric/ertp": "0.16.3-mainnet1B-dev-26244e8.0+26244e8",
39
- "@agoric/import-manager": "0.3.12-mainnet1B-dev-26244e8.0+26244e8",
40
- "@agoric/internal": "0.4.0-mainnet1B-dev-26244e8.0+26244e8",
41
- "@agoric/notifier": "0.6.3-mainnet1B-dev-26244e8.0+26244e8",
42
- "@agoric/store": "0.9.3-mainnet1B-dev-26244e8.0+26244e8",
43
- "@agoric/zoe": "0.26.3-mainnet1B-dev-26244e8.0+26244e8",
44
- "@endo/base64": "0.2.31",
45
- "@endo/bundle-source": "2.5.2-upstream-rollup",
46
- "@endo/far": "0.2.18",
47
- "@endo/marshal": "0.8.5",
48
- "@endo/nat": "4.1.27",
49
- "@endo/promise-kit": "0.2.56",
50
- "@endo/zip": "0.2.31"
37
+ "@agoric/assert": "0.6.1-orchestration-dev-096c4e8.0+096c4e8",
38
+ "@agoric/ertp": "0.16.3-orchestration-dev-096c4e8.0+096c4e8",
39
+ "@agoric/import-manager": "0.3.12-orchestration-dev-096c4e8.0+096c4e8",
40
+ "@agoric/internal": "0.3.3-orchestration-dev-096c4e8.0+096c4e8",
41
+ "@agoric/notifier": "0.6.3-orchestration-dev-096c4e8.0+096c4e8",
42
+ "@agoric/store": "0.9.3-orchestration-dev-096c4e8.0+096c4e8",
43
+ "@agoric/time": "0.3.3-orchestration-dev-096c4e8.0+096c4e8",
44
+ "@agoric/zoe": "0.26.3-orchestration-dev-096c4e8.0+096c4e8",
45
+ "@endo/base64": "^1.0.2",
46
+ "@endo/bundle-source": "^3.1.0",
47
+ "@endo/far": "^1.0.4",
48
+ "@endo/marshal": "^1.3.0",
49
+ "@endo/nat": "^5.0.4",
50
+ "@endo/promise-kit": "^1.0.4",
51
+ "@endo/zip": "^1.0.2"
51
52
  },
52
53
  "devDependencies": {
53
- "@agoric/vats": "0.15.2-mainnet1B-dev-26244e8.0+26244e8",
54
- "@endo/init": "0.5.56",
55
- "ava": "^5.2.0",
54
+ "@agoric/vats": "0.15.2-orchestration-dev-096c4e8.0+096c4e8",
55
+ "@endo/init": "^1.0.4",
56
+ "ava": "^5.3.0",
56
57
  "import-meta-resolve": "^2.2.1"
57
58
  },
58
59
  "files": [
@@ -63,10 +64,16 @@
63
64
  "ava": {
64
65
  "files": [
65
66
  "test/**/test-*.js"
67
+ ],
68
+ "require": [
69
+ "@endo/init/debug.js"
66
70
  ]
67
71
  },
68
72
  "publishConfig": {
69
73
  "access": "public"
70
74
  },
71
- "gitHead": "26244e821f1a83cd5868f0c7d54aa480c8c17e5e"
75
+ "typeCoverage": {
76
+ "atLeast": 81.47
77
+ },
78
+ "gitHead": "096c4e8fce80e9a509b0e1a30fda11736c4570e1"
72
79
  }
@@ -8,7 +8,20 @@ const t = 'makeCoreProposalBehavior';
8
8
  * @typedef {*} BootstrapPowers
9
9
  */
10
10
 
11
- // These permits apply to `allPowers` in `behavior` below.
11
+ /**
12
+ * @typedef {import('./externalTypes.js').ManifestBundleRef} ManifestBundleRef
13
+ * @typedef {[methodName: string, ...args: unknown[]]} FlatMethargs
14
+ * @typedef {Record<string, Record<string, unknown>>} Manifest
15
+ */
16
+
17
+ /**
18
+ * These permits are expected to be the minimum powers required by the
19
+ * `coreProposalBehavior` function returned from `makeCoreProposalBehavior`.
20
+ * They are merged with all of the manifest getter's permits to produce the
21
+ * total permits needed by the resulting core proposal (such as might be---and
22
+ * generally are---written into a *-permit.json file).
23
+ * @see {@link ./writeCoreProposal.js}
24
+ */
12
25
  export const permits = {
13
26
  consume: { agoricNamesAdmin: t, vatAdminSvc: t, zoe: t },
14
27
  evaluateBundleCap: t,
@@ -23,43 +36,74 @@ export const permits = {
23
36
  * for catching bugs. Thus, this maker must not reference any other modules or
24
37
  * definitions.
25
38
  *
26
- * @param {object} opts
27
- * @param {{ bundleName: string } | { bundleID: string }} opts.manifestBundleRef
28
- * @param {[string, ...unknown[]]} opts.getManifestCall
29
- * @param {Record<string, Record<string, unknown>>} [opts.overrideManifest]
30
- * @param {typeof import('@endo/far').E} opts.E
31
- * @param {(...args: unknown[]) => void} [opts.log]
32
- * @param {(ref: unknown) => Promise<unknown>} [opts.restoreRef]
39
+ * @param {object} inputs
40
+ * @param {ManifestBundleRef} inputs.manifestBundleRef
41
+ * @param {FlatMethargs} inputs.getManifestCall
42
+ * @param {Manifest} [inputs.customManifest]
43
+ * @param {typeof import('@endo/far').E} inputs.E
44
+ * @param {(...args: unknown[]) => void} [inputs.log]
45
+ * @param {(ref: import('./externalTypes.js').ManifestBundleRef) => Promise<import('@agoric/zoe/src/zoeService/utils.js').Installation<unknown>>} [inputs.customRestoreRef]
33
46
  * @returns {(vatPowers: unknown) => Promise<unknown>}
34
47
  */
35
48
  export const makeCoreProposalBehavior = ({
36
49
  manifestBundleRef,
37
- getManifestCall,
38
- overrideManifest,
50
+ getManifestCall: [manifestGetterName, ...manifestGetterArgs],
51
+ customManifest,
39
52
  E,
40
53
  log = console.info,
41
- restoreRef: overrideRestoreRef,
54
+ customRestoreRef,
42
55
  }) => {
43
56
  const { entries, fromEntries } = Object;
44
57
 
45
- // deeplyFulfilled is a bit overkill for what we need.
58
+ /**
59
+ * Given an object whose properties may be promise-valued, return a promise
60
+ * for an analogous object in which each such value has been replaced with its
61
+ * fulfillment.
62
+ * This is a non-recursive form of endo `deeplyFulfilled`.
63
+ *
64
+ * @template T
65
+ * @param {{[K in keyof T]: (T[K] | Promise<T[K]>)}} obj
66
+ * @returns {Promise<T>}
67
+ */
46
68
  const shallowlyFulfilled = async obj => {
47
69
  if (!obj) {
48
70
  return obj;
49
71
  }
50
- const ents = await Promise.all(
72
+ const awaitedEntries = await Promise.all(
51
73
  entries(obj).map(async ([key, valueP]) => {
52
74
  const value = await valueP;
53
75
  return [key, value];
54
76
  }),
55
77
  );
56
- return fromEntries(ents);
78
+ return fromEntries(awaitedEntries);
79
+ };
80
+
81
+ const makeRestoreRef = (vatAdminSvc, zoe) => {
82
+ /** @type {(ref: import('./externalTypes.js').ManifestBundleRef) => Promise<Installation<unknown>>} */
83
+ const defaultRestoreRef = async bundleRef => {
84
+ // extract-proposal.js creates these records, and bundleName is
85
+ // the optional name under which the bundle was installed into
86
+ // config.bundles
87
+ const bundleIdP =
88
+ 'bundleName' in bundleRef
89
+ ? E(vatAdminSvc).getBundleIDByName(bundleRef.bundleName)
90
+ : bundleRef.bundleID;
91
+ const bundleID = await bundleIdP;
92
+ const label = bundleID.slice(0, 8);
93
+ return E(zoe).installBundleID(bundleID, label);
94
+ };
95
+ return defaultRestoreRef;
57
96
  };
58
97
 
59
- /** @param {ChainBootstrapSpace & BootstrapPowers & { evaluateBundleCap: any }} allPowers */
60
- const behavior = async allPowers => {
61
- // NOTE: If updating any of these names extracted from `allPowers`, you must
62
- // change `permits` above to reflect their accessibility.
98
+ /** @param {ChainBootstrapSpace & BootstrapPowers & { evaluateBundleCap: any }} powers */
99
+ const coreProposalBehavior = async powers => {
100
+ // NOTE: `powers` is expected to match or be a superset of the above `permits` export,
101
+ // which should therefore be kept in sync with this deconstruction code.
102
+ // HOWEVER, do note that this function is invoked with at least the *union* of powers
103
+ // required by individual moduleBehaviors declared by the manifest getter, which is
104
+ // necessary so it can use `runModuleBehaviors` to provide the appropriate subset to
105
+ // each one (see ./writeCoreProposal.js).
106
+ // Handle `powers` with the requisite care.
63
107
  const {
64
108
  consume: { vatAdminSvc, zoe, agoricNamesAdmin },
65
109
  evaluateBundleCap,
@@ -67,70 +111,70 @@ export const makeCoreProposalBehavior = ({
67
111
  modules: {
68
112
  utils: { runModuleBehaviors },
69
113
  },
70
- } = allPowers;
71
- const [exportedGetManifest, ...manifestArgs] = getManifestCall;
72
-
73
- const defaultRestoreRef = async ref => {
74
- // extract-proposal.js creates these records, and bundleName is
75
- // the name under which the bundle was installed into
76
- // config.bundles
77
- const p = ref.bundleName
78
- ? E(vatAdminSvc).getBundleIDByName(ref.bundleName)
79
- : ref.bundleID;
80
- const bundleID = await p;
81
- const label = bundleID.slice(0, 8);
82
- return E(zoe).installBundleID(bundleID, label);
83
- };
84
- const restoreRef = overrideRestoreRef || defaultRestoreRef;
114
+ } = powers;
85
115
 
86
116
  // Get the on-chain installation containing the manifest and behaviors.
87
- console.info('evaluateBundleCap', {
117
+ log('evaluateBundleCap', {
88
118
  manifestBundleRef,
89
- exportedGetManifest,
119
+ manifestGetterName,
90
120
  vatAdminSvc,
91
121
  });
92
122
  let bcapP;
93
123
  if ('bundleName' in manifestBundleRef) {
94
124
  bcapP = E(vatAdminSvc).getNamedBundleCap(manifestBundleRef.bundleName);
95
- } else {
125
+ } else if ('bundleID' in manifestBundleRef) {
96
126
  bcapP = E(vatAdminSvc).getBundleCap(manifestBundleRef.bundleID);
127
+ } else {
128
+ const keys = Reflect.ownKeys(manifestBundleRef).map(key =>
129
+ typeof key === 'string' ? JSON.stringify(key) : String(key),
130
+ );
131
+ const keysStr = `[${keys.join(', ')}]`;
132
+ throw Error(
133
+ `bundleRef must have own bundleName or bundleID, missing in ${keysStr}`,
134
+ );
97
135
  }
98
136
  const bundleCap = await bcapP;
99
137
 
100
- const manifestNS = await evaluateBundleCap(bundleCap);
138
+ const proposalNS = await evaluateBundleCap(bundleCap);
101
139
 
102
- console.error('execute', {
103
- exportedGetManifest,
104
- behaviors: Object.keys(manifestNS),
140
+ // Get the manifest and its metadata.
141
+ log('execute', {
142
+ manifestGetterName,
143
+ bundleExports: Object.keys(proposalNS),
105
144
  });
145
+ const restoreRef = customRestoreRef || makeRestoreRef(vatAdminSvc, zoe);
106
146
  const {
107
147
  manifest,
108
148
  options: rawOptions,
109
149
  installations: rawInstallations,
110
- } = await manifestNS[exportedGetManifest](
150
+ } = await proposalNS[manifestGetterName](
111
151
  harden({ restoreRef }),
112
- ...manifestArgs,
152
+ ...manifestGetterArgs,
113
153
  );
114
154
 
115
- // Await references in the options or installations.
155
+ // Await promises in the returned options and installations records.
116
156
  const [options, installations] = await Promise.all(
117
157
  [rawOptions, rawInstallations].map(shallowlyFulfilled),
118
158
  );
119
159
 
120
- // Publish the installations for behavior dependencies.
121
- const installAdmin = E(agoricNamesAdmin).lookupAdmin('installation');
122
- await Promise.all(
123
- entries(installations || {}).map(([key, value]) => {
124
- produceInstallations[key].resolve(value);
125
- return E(installAdmin).update(key, value);
126
- }),
127
- );
160
+ // Publish the installations for our dependencies.
161
+ const installationEntries = entries(installations || {});
162
+ if (installationEntries.length > 0) {
163
+ const installAdmin = E(agoricNamesAdmin).lookupAdmin('installation');
164
+ await Promise.all(
165
+ installationEntries.map(([key, value]) => {
166
+ produceInstallations[key].resolve(value);
167
+ return E(installAdmin).update(key, value);
168
+ }),
169
+ );
170
+ }
128
171
 
129
- // Evaluate the manifest for our behaviors.
172
+ // Evaluate the manifest.
130
173
  return runModuleBehaviors({
131
- allPowers,
132
- behaviors: manifestNS,
133
- manifest: overrideManifest || manifest,
174
+ // Remember that `powers` may be arbitrarily broad.
175
+ allPowers: powers,
176
+ behaviors: proposalNS,
177
+ manifest: customManifest || manifest,
134
178
  makeConfig: (name, _permit) => {
135
179
  log('coreProposal:', name);
136
180
  return { options };
@@ -138,22 +182,31 @@ export const makeCoreProposalBehavior = ({
138
182
  });
139
183
  };
140
184
 
141
- // Make the behavior the completion value.
142
- return behavior;
185
+ return coreProposalBehavior;
143
186
  };
144
187
 
145
- export const makeEnactCoreProposalsFromBundleRef =
146
- ({ makeCoreProposalArgs, E }) =>
147
- async allPowers => {
188
+ /**
189
+ * @param {object} inputs
190
+ * @param {Array<{ ref: ManifestBundleRef, call: FlatMethargs, customManifest?: Manifest }>} inputs.metadataRecords
191
+ * @param {typeof import('@endo/far').E} inputs.E
192
+ */
193
+ export const makeEnactCoreProposalsFromBundleRef = ({ metadataRecords, E }) => {
194
+ /**
195
+ * @param {ChainBootstrapSpace & BootstrapPowers & { evaluateBundleCap: any }} powers
196
+ * @returns {Promise<void>}
197
+ */
198
+ const enactCoreProposals = async powers => {
148
199
  await Promise.all(
149
- makeCoreProposalArgs.map(async ({ ref, call, overrideManifest }) => {
150
- const subBehavior = makeCoreProposalBehavior({
200
+ metadataRecords.map(async ({ ref, call, customManifest }) => {
201
+ const coreProposalBehavior = makeCoreProposalBehavior({
151
202
  manifestBundleRef: ref,
152
203
  getManifestCall: call,
153
- overrideManifest,
204
+ customManifest,
154
205
  E,
155
206
  });
156
- return subBehavior(allPowers);
207
+ return coreProposalBehavior(powers);
157
208
  }),
158
209
  );
159
210
  };
211
+ return enactCoreProposals;
212
+ };
@@ -18,6 +18,9 @@ export const start = () => {
18
18
  });
19
19
  };
20
20
 
21
+ /**
22
+ * @param {{ zoe: ERef<ZoeService> }} opts
23
+ */
21
24
  const makeBundler = ({ zoe }) => {
22
25
  /** @type { Map<string, [string, Uint8Array]>} */
23
26
  const nameToContent = new Map();
@@ -16,30 +16,29 @@ export {};
16
16
  */
17
17
 
18
18
  /**
19
- * @typedef BundleHandle
20
- * @property {string} [bundleName]
19
+ * @typedef {{fileName?: string} & ({ bundleName: string } | { bundleID: string}) } ManifestBundleRef
21
20
  */
22
21
 
23
22
  /**
24
23
  * @callback PublishBundleRef
25
- * @param {ERef<BundleHandle>} bundle
26
- * @returns {Promise<BundleHandle>}
24
+ * @param {ERef<ManifestBundleRef>} bundle
25
+ * @returns {Promise<ManifestBundleRef>}
27
26
  */
28
27
 
29
28
  /**
30
- * @callback InstallBundle
29
+ * @callback InstallEntrypoint
31
30
  * @param {string} srcSpec
32
- * @param {string} bundlePath
33
- * @param {any} [opts]
34
- * @returns {BundleHandle}
31
+ * @param {string} [bundlePath]
32
+ * @param {unknown} [opts]
33
+ * @returns {Promise<ManifestBundleRef>}
35
34
  */
36
35
 
37
36
  /**
38
37
  * @callback ProposalBuilder
39
38
  * @param {{
40
39
  * publishRef: PublishBundleRef,
41
- * install: InstallBundle,
42
- * wrapInstall?: <T>(f: T) => T }
40
+ * install: InstallEntrypoint,
41
+ * wrapInstall?: <T extends InstallEntrypoint>(f: T) => T }
43
42
  * } powers
44
43
  * @param {...any} args
45
44
  * @returns {Promise<ProposalResult>}