@terraforge/terraform 0.0.13 → 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.
- package/dist/index.mjs +20 -7
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2240,7 +2240,12 @@ const retry = async (tries, cb) => {
|
|
|
2240
2240
|
|
|
2241
2241
|
//#endregion
|
|
2242
2242
|
//#region src/proxy.ts
|
|
2243
|
-
const
|
|
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(
|
|
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,10 +2355,13 @@ 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) => {
|
|
2364
|
+
const resource = createResourceProxy(getClass(type), (key) => {
|
|
2352
2365
|
if (typeof key === "string") {
|
|
2353
2366
|
if (key === "urn") return meta.urn;
|
|
2354
2367
|
return meta.output((data) => data[key]);
|
|
@@ -2360,7 +2373,7 @@ const createTerraformProxy = (props) => {
|
|
|
2360
2373
|
dataSource: (ns, parent, id, input, config) => {
|
|
2361
2374
|
const type = snakeCase([props.namespace, ...ns].join("_"));
|
|
2362
2375
|
const meta = createMeta("data", `terraform:${props.namespace}:${config?.provider ?? "default"}`, parent, type, id, input, config);
|
|
2363
|
-
const dataSource = createResourceProxy((key) => {
|
|
2376
|
+
const dataSource = createResourceProxy(getClass(type), (key) => {
|
|
2364
2377
|
if (typeof key === "string") {
|
|
2365
2378
|
if (key === "urn") return meta.urn;
|
|
2366
2379
|
return meta.output((data) => data[key]);
|