@terraforge/terraform 0.0.12 → 0.0.14

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 +29 -12
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -309,7 +309,7 @@ var DiagnosticsError = class extends Error {
309
309
  const formatDiagnosticErrorMessage = (diagnostics) => {
310
310
  if (diagnostics.length === 0) return "Unknown diagnostic error";
311
311
  const diagnostic = diagnostics[0];
312
- if (diagnostic.detail) return `${diagnostic.summary}\n${diagnostic.detail}`;
312
+ if (diagnostic.detail) return `${diagnostic.summary}\n\n${diagnostic.detail}`;
313
313
  return diagnostic.summary;
314
314
  };
315
315
  const throwDiagnosticError = (response) => {
@@ -2240,7 +2240,12 @@ const retry = async (tries, cb) => {
2240
2240
 
2241
2241
  //#endregion
2242
2242
  //#region src/proxy.ts
2243
- const createResourceProxy = (cb) => {
2243
+ const classMap = /* @__PURE__ */ new Map();
2244
+ const getClass = (type) => {
2245
+ if (!classMap.has(type)) classMap.set(type, class {});
2246
+ return classMap.get(type);
2247
+ };
2248
+ const createResourceProxy = (klass, cb) => {
2244
2249
  return new Proxy({}, {
2245
2250
  get(_, key) {
2246
2251
  return cb(key);
@@ -2248,6 +2253,9 @@ const createResourceProxy = (cb) => {
2248
2253
  set(_, key) {
2249
2254
  if (typeof key === "string") throw new Error(`Cannot set property ${key} on read-only object.`);
2250
2255
  throw new Error(`This object is read-only.`);
2256
+ },
2257
+ getPrototypeOf() {
2258
+ return klass.prototype;
2251
2259
  }
2252
2260
  });
2253
2261
  };
@@ -2286,19 +2294,21 @@ const createRootProxy = (apply, get) => {
2286
2294
  }
2287
2295
  });
2288
2296
  };
2289
- const createClassProxy = (construct, get) => {
2290
- return new Proxy(class {}, {
2297
+ const createClassProxy = (name, target, construct, get) => {
2298
+ return new Proxy(target, {
2291
2299
  construct(_, args) {
2292
2300
  return construct(...args);
2293
2301
  },
2294
2302
  get(_, key) {
2303
+ if (key === "prototype") return target.prototype;
2304
+ if (key === "name") return name;
2295
2305
  if (key === "get") return (...args) => {
2296
2306
  return get(...args);
2297
2307
  };
2298
2308
  }
2299
2309
  });
2300
2310
  };
2301
- const createRecursiveProxy = ({ provider, install, uninstall, isInstalled, resource, dataSource }) => {
2311
+ const createRecursiveProxy = ({ provider, install, uninstall, isInstalled, class: klass, resource, dataSource }) => {
2302
2312
  const findNextProxy = (ns, name) => {
2303
2313
  if (name === name.toLowerCase()) return createNamespaceProxy((key) => {
2304
2314
  return findNextProxy([...ns, name], key);
@@ -2306,7 +2316,7 @@ const createRecursiveProxy = ({ provider, install, uninstall, isInstalled, resou
2306
2316
  else if (name.startsWith("get")) return (...args) => {
2307
2317
  return dataSource([...ns, name.substring(3)], ...args);
2308
2318
  };
2309
- else return createClassProxy((...args) => {
2319
+ else return createClassProxy(pascalCase([...ns, name].join("-")), klass([...ns, name]), (...args) => {
2310
2320
  return resource([...ns, name], ...args);
2311
2321
  }, (...args) => {
2312
2322
  return dataSource([...ns, name], ...args);
@@ -2345,12 +2355,17 @@ const createTerraformProxy = (props) => {
2345
2355
  ...installProps
2346
2356
  });
2347
2357
  },
2358
+ class: (ns) => {
2359
+ return getClass(snakeCase([props.namespace, ...ns].join("_")));
2360
+ },
2348
2361
  resource: (ns, parent, id, input, config) => {
2349
2362
  const type = snakeCase([props.namespace, ...ns].join("_"));
2350
2363
  const meta = createMeta("resource", `terraform:${props.namespace}:${config?.provider ?? "default"}`, parent, type, id, input, config);
2351
- const resource = createResourceProxy((key) => {
2352
- if (typeof key === "string") return meta.output((data) => data[key]);
2353
- else if (key === nodeMetaSymbol) return meta;
2364
+ const resource = createResourceProxy(getClass(type), (key) => {
2365
+ if (typeof key === "string") {
2366
+ if (key === "urn") return meta.urn;
2367
+ return meta.output((data) => data[key]);
2368
+ } else if (key === nodeMetaSymbol) return meta;
2354
2369
  });
2355
2370
  parent.add(resource);
2356
2371
  return resource;
@@ -2358,9 +2373,11 @@ const createTerraformProxy = (props) => {
2358
2373
  dataSource: (ns, parent, id, input, config) => {
2359
2374
  const type = snakeCase([props.namespace, ...ns].join("_"));
2360
2375
  const meta = createMeta("data", `terraform:${props.namespace}:${config?.provider ?? "default"}`, parent, type, id, input, config);
2361
- const dataSource = createResourceProxy((key) => {
2362
- if (typeof key === "string") return meta.output((data) => data[key]);
2363
- else if (key === nodeMetaSymbol) return meta;
2376
+ const dataSource = createResourceProxy(getClass(type), (key) => {
2377
+ if (typeof key === "string") {
2378
+ if (key === "urn") return meta.urn;
2379
+ return meta.output((data) => data[key]);
2380
+ } else if (key === nodeMetaSymbol) return meta;
2364
2381
  });
2365
2382
  parent.add(dataSource);
2366
2383
  return dataSource;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terraforge/terraform",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",