@terraforge/terraform 0.0.13 → 0.0.15

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 (2) hide show
  1. package/dist/index.mjs +44 -15
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -2103,12 +2103,16 @@ const createPlugin5 = async ({ server, client }) => {
2103
2103
  async planResourceChange(type, priorState, proposedState) {
2104
2104
  const schema$1 = getResourceSchema(resources, type);
2105
2105
  const preparedPriorState = formatInputState(schema$1, priorState);
2106
- const preparedProposedState = formatInputState(schema$1, proposedState);
2106
+ const preparedProposedState = formatInputState(schema$1, {
2107
+ ...priorState,
2108
+ ...proposedState
2109
+ });
2110
+ const configState = formatInputState(schema$1, proposedState);
2107
2111
  const plan = await client.call("PlanResourceChange", {
2108
2112
  typeName: type,
2109
2113
  priorState: encodeDynamicValue(preparedPriorState),
2110
2114
  proposedNewState: encodeDynamicValue(preparedProposedState),
2111
- config: encodeDynamicValue(preparedProposedState)
2115
+ config: encodeDynamicValue(configState)
2112
2116
  });
2113
2117
  const plannedState = decodeDynamicValue(plan.plannedState);
2114
2118
  return {
@@ -2119,12 +2123,16 @@ const createPlugin5 = async ({ server, client }) => {
2119
2123
  async applyResourceChange(type, priorState, proposedState) {
2120
2124
  const schema$1 = getResourceSchema(resources, type);
2121
2125
  const preparedPriorState = formatInputState(schema$1, priorState);
2122
- const preparedProposedState = formatInputState(schema$1, proposedState);
2126
+ const preparedProposedState = formatInputState(schema$1, {
2127
+ ...priorState,
2128
+ ...proposedState
2129
+ });
2130
+ const configState = formatInputState(schema$1, proposedState);
2123
2131
  return formatOutputState(schema$1, decodeDynamicValue((await client.call("ApplyResourceChange", {
2124
2132
  typeName: type,
2125
2133
  priorState: encodeDynamicValue(preparedPriorState),
2126
2134
  plannedState: encodeDynamicValue(preparedProposedState),
2127
- config: encodeDynamicValue(preparedProposedState)
2135
+ config: encodeDynamicValue(configState)
2128
2136
  })).newState));
2129
2137
  }
2130
2138
  };
@@ -2177,12 +2185,16 @@ const createPlugin6 = async ({ server, client }) => {
2177
2185
  async planResourceChange(type, priorState, proposedState) {
2178
2186
  const schema$1 = getResourceSchema(resources, type);
2179
2187
  const preparedPriorState = formatInputState(schema$1, priorState);
2180
- const preparedProposedState = formatInputState(schema$1, proposedState);
2188
+ const preparedProposedState = formatInputState(schema$1, {
2189
+ ...priorState,
2190
+ ...proposedState
2191
+ });
2192
+ const configState = formatInputState(schema$1, proposedState);
2181
2193
  const plan = await client.call("PlanResourceChange", {
2182
2194
  typeName: type,
2183
2195
  priorState: encodeDynamicValue(preparedPriorState),
2184
2196
  proposedNewState: encodeDynamicValue(preparedProposedState),
2185
- config: encodeDynamicValue(preparedProposedState)
2197
+ config: encodeDynamicValue(configState)
2186
2198
  });
2187
2199
  const plannedState = decodeDynamicValue(plan.plannedState);
2188
2200
  return {
@@ -2193,12 +2205,16 @@ const createPlugin6 = async ({ server, client }) => {
2193
2205
  async applyResourceChange(type, priorState, proposedState) {
2194
2206
  const schema$1 = getResourceSchema(resources, type);
2195
2207
  const preparedPriorState = formatInputState(schema$1, priorState);
2196
- const preparedProposedState = formatInputState(schema$1, proposedState);
2208
+ const preparedProposedState = formatInputState(schema$1, {
2209
+ ...priorState,
2210
+ ...proposedState
2211
+ });
2212
+ const configState = formatInputState(schema$1, proposedState);
2197
2213
  return formatOutputState(schema$1, decodeDynamicValue((await client.call("ApplyResourceChange", {
2198
2214
  typeName: type,
2199
2215
  priorState: encodeDynamicValue(preparedPriorState),
2200
2216
  plannedState: encodeDynamicValue(preparedProposedState),
2201
- config: encodeDynamicValue(preparedProposedState)
2217
+ config: encodeDynamicValue(configState)
2202
2218
  })).newState));
2203
2219
  }
2204
2220
  };
@@ -2240,7 +2256,12 @@ const retry = async (tries, cb) => {
2240
2256
 
2241
2257
  //#endregion
2242
2258
  //#region src/proxy.ts
2243
- const createResourceProxy = (cb) => {
2259
+ const classMap = /* @__PURE__ */ new Map();
2260
+ const getClass = (type) => {
2261
+ if (!classMap.has(type)) classMap.set(type, class {});
2262
+ return classMap.get(type);
2263
+ };
2264
+ const createResourceProxy = (klass, cb) => {
2244
2265
  return new Proxy({}, {
2245
2266
  get(_, key) {
2246
2267
  return cb(key);
@@ -2248,6 +2269,9 @@ const createResourceProxy = (cb) => {
2248
2269
  set(_, key) {
2249
2270
  if (typeof key === "string") throw new Error(`Cannot set property ${key} on read-only object.`);
2250
2271
  throw new Error(`This object is read-only.`);
2272
+ },
2273
+ getPrototypeOf() {
2274
+ return klass.prototype;
2251
2275
  }
2252
2276
  });
2253
2277
  };
@@ -2286,19 +2310,21 @@ const createRootProxy = (apply, get) => {
2286
2310
  }
2287
2311
  });
2288
2312
  };
2289
- const createClassProxy = (construct, get) => {
2290
- return new Proxy(class {}, {
2313
+ const createClassProxy = (name, target, construct, get) => {
2314
+ return new Proxy(target, {
2291
2315
  construct(_, args) {
2292
2316
  return construct(...args);
2293
2317
  },
2294
2318
  get(_, key) {
2319
+ if (key === "prototype") return target.prototype;
2320
+ if (key === "name") return name;
2295
2321
  if (key === "get") return (...args) => {
2296
2322
  return get(...args);
2297
2323
  };
2298
2324
  }
2299
2325
  });
2300
2326
  };
2301
- const createRecursiveProxy = ({ provider, install, uninstall, isInstalled, resource, dataSource }) => {
2327
+ const createRecursiveProxy = ({ provider, install, uninstall, isInstalled, class: klass, resource, dataSource }) => {
2302
2328
  const findNextProxy = (ns, name) => {
2303
2329
  if (name === name.toLowerCase()) return createNamespaceProxy((key) => {
2304
2330
  return findNextProxy([...ns, name], key);
@@ -2306,7 +2332,7 @@ const createRecursiveProxy = ({ provider, install, uninstall, isInstalled, resou
2306
2332
  else if (name.startsWith("get")) return (...args) => {
2307
2333
  return dataSource([...ns, name.substring(3)], ...args);
2308
2334
  };
2309
- else return createClassProxy((...args) => {
2335
+ else return createClassProxy(pascalCase([...ns, name].join("-")), klass([...ns, name]), (...args) => {
2310
2336
  return resource([...ns, name], ...args);
2311
2337
  }, (...args) => {
2312
2338
  return dataSource([...ns, name], ...args);
@@ -2345,10 +2371,13 @@ const createTerraformProxy = (props) => {
2345
2371
  ...installProps
2346
2372
  });
2347
2373
  },
2374
+ class: (ns) => {
2375
+ return getClass(snakeCase([props.namespace, ...ns].join("_")));
2376
+ },
2348
2377
  resource: (ns, parent, id, input, config) => {
2349
2378
  const type = snakeCase([props.namespace, ...ns].join("_"));
2350
2379
  const meta = createMeta("resource", `terraform:${props.namespace}:${config?.provider ?? "default"}`, parent, type, id, input, config);
2351
- const resource = createResourceProxy((key) => {
2380
+ const resource = createResourceProxy(getClass(type), (key) => {
2352
2381
  if (typeof key === "string") {
2353
2382
  if (key === "urn") return meta.urn;
2354
2383
  return meta.output((data) => data[key]);
@@ -2360,7 +2389,7 @@ const createTerraformProxy = (props) => {
2360
2389
  dataSource: (ns, parent, id, input, config) => {
2361
2390
  const type = snakeCase([props.namespace, ...ns].join("_"));
2362
2391
  const meta = createMeta("data", `terraform:${props.namespace}:${config?.provider ?? "default"}`, parent, type, id, input, config);
2363
- const dataSource = createResourceProxy((key) => {
2392
+ const dataSource = createResourceProxy(getClass(type), (key) => {
2364
2393
  if (typeof key === "string") {
2365
2394
  if (key === "urn") return meta.urn;
2366
2395
  return meta.output((data) => data[key]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terraforge/terraform",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,7 +26,7 @@
26
26
  "test": "bun test"
27
27
  },
28
28
  "peerDependencies": {
29
- "@terraforge/core": "0.0.11"
29
+ "@terraforge/core": "0.0.19"
30
30
  },
31
31
  "dependencies": {
32
32
  "@grpc/grpc-js": "1.12.6",