@k8ts/instruments 0.6.2 → 0.9.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.
Files changed (131) hide show
  1. package/dist/core/graph/origin/entity.d.ts +2 -2
  2. package/dist/core/graph/origin/entity.d.ts.map +1 -1
  3. package/dist/core/graph/origin/exporter.d.ts +3 -3
  4. package/dist/core/graph/origin/exporter.d.ts.map +1 -1
  5. package/dist/core/graph/origin/exporter.js +1 -1
  6. package/dist/core/graph/origin/exporter.js.map +1 -1
  7. package/dist/core/graph/origin/external.d.ts +10 -0
  8. package/dist/core/graph/origin/external.d.ts.map +1 -0
  9. package/dist/core/graph/origin/external.js +18 -0
  10. package/dist/core/graph/origin/external.js.map +1 -0
  11. package/dist/core/graph/origin/index.d.ts +1 -0
  12. package/dist/core/graph/origin/index.d.ts.map +1 -1
  13. package/dist/core/graph/origin/index.js +1 -0
  14. package/dist/core/graph/origin/index.js.map +1 -1
  15. package/dist/core/graph/origin/kind-map/index.d.ts +1 -2
  16. package/dist/core/graph/origin/kind-map/index.d.ts.map +1 -1
  17. package/dist/core/graph/origin/kind-map/index.js +3 -5
  18. package/dist/core/graph/origin/kind-map/index.js.map +1 -1
  19. package/dist/core/graph/origin/node.d.ts +3 -3
  20. package/dist/core/graph/origin/node.d.ts.map +1 -1
  21. package/dist/core/graph/origin/node.js.map +1 -1
  22. package/dist/core/graph/origin/tracker.d.ts +2 -0
  23. package/dist/core/graph/origin/tracker.d.ts.map +1 -1
  24. package/dist/core/graph/origin/tracker.js +10 -0
  25. package/dist/core/graph/origin/tracker.js.map +1 -1
  26. package/dist/core/graph/resource/api-kind/index.d.ts +4 -2
  27. package/dist/core/graph/resource/api-kind/index.d.ts.map +1 -1
  28. package/dist/core/graph/resource/api-kind/index.js +9 -2
  29. package/dist/core/graph/resource/api-kind/index.js.map +1 -1
  30. package/dist/core/graph/resource/entity.d.ts +3 -0
  31. package/dist/core/graph/resource/entity.d.ts.map +1 -1
  32. package/dist/core/graph/resource/entity.js +3 -0
  33. package/dist/core/graph/resource/entity.js.map +1 -1
  34. package/dist/core/graph/resource/external/base.d.ts +19 -0
  35. package/dist/core/graph/resource/external/base.d.ts.map +1 -0
  36. package/dist/core/graph/resource/external/base.js +44 -0
  37. package/dist/core/graph/resource/external/base.js.map +1 -0
  38. package/dist/core/graph/resource/external/features.d.ts +11 -0
  39. package/dist/core/graph/resource/external/features.d.ts.map +1 -0
  40. package/dist/core/graph/resource/external/features.js +3 -0
  41. package/dist/core/graph/resource/external/features.js.map +1 -0
  42. package/dist/core/graph/resource/external/index.d.ts +4 -0
  43. package/dist/core/graph/resource/external/index.d.ts.map +1 -0
  44. package/dist/core/graph/resource/external/index.js +20 -0
  45. package/dist/core/graph/resource/external/index.js.map +1 -0
  46. package/dist/core/graph/resource/external/props.d.ts +15 -0
  47. package/dist/core/graph/resource/external/props.d.ts.map +1 -0
  48. package/dist/core/graph/resource/external/props.js +3 -0
  49. package/dist/core/graph/resource/external/props.js.map +1 -0
  50. package/dist/core/graph/resource/field.d.ts +2 -0
  51. package/dist/core/graph/resource/field.d.ts.map +1 -0
  52. package/dist/core/graph/resource/field.js +3 -0
  53. package/dist/core/graph/resource/field.js.map +1 -0
  54. package/dist/core/graph/resource/index.d.ts +2 -0
  55. package/dist/core/graph/resource/index.d.ts.map +1 -1
  56. package/dist/core/graph/resource/index.js +2 -0
  57. package/dist/core/graph/resource/index.js.map +1 -1
  58. package/dist/core/graph/resource/node.d.ts +2 -1
  59. package/dist/core/graph/resource/node.d.ts.map +1 -1
  60. package/dist/core/graph/resource/node.js +14 -4
  61. package/dist/core/graph/resource/node.js.map +1 -1
  62. package/dist/core/graph/resource/ref-key/ref-key.d.ts +12 -2
  63. package/dist/core/graph/resource/ref-key/ref-key.d.ts.map +1 -1
  64. package/dist/core/graph/resource/ref-key/ref-key.js +15 -4
  65. package/dist/core/graph/resource/ref-key/ref-key.js.map +1 -1
  66. package/dist/core/graph/resource/reference/fw-ref-exports.d.ts +4 -4
  67. package/dist/core/graph/resource/reference/fw-ref-exports.d.ts.map +1 -1
  68. package/dist/core/graph/resource/reference/fw-ref.d.ts +5 -5
  69. package/dist/core/graph/resource/reference/fw-ref.d.ts.map +1 -1
  70. package/dist/core/graph/resource/reference/fw-ref.js.map +1 -1
  71. package/dist/core/graph/resource/reference/index.d.ts +1 -1
  72. package/dist/core/graph/resource/reference/index.d.ts.map +1 -1
  73. package/dist/core/graph/resource/reference/refable.d.ts +10 -5
  74. package/dist/core/graph/resource/reference/refable.d.ts.map +1 -1
  75. package/dist/core/graph/resource/top.d.ts +3 -1
  76. package/dist/core/graph/resource/top.d.ts.map +1 -1
  77. package/dist/core/graph/resource/top.js +11 -0
  78. package/dist/core/graph/resource/top.js.map +1 -1
  79. package/dist/expressions/data-sources/base.d.ts +7 -0
  80. package/dist/expressions/data-sources/base.d.ts.map +1 -0
  81. package/dist/expressions/data-sources/base.js +15 -0
  82. package/dist/expressions/data-sources/base.js.map +1 -0
  83. package/dist/expressions/data-sources/env-var.d.ts +7 -0
  84. package/dist/expressions/data-sources/env-var.d.ts.map +1 -0
  85. package/dist/expressions/data-sources/env-var.js +23 -0
  86. package/dist/expressions/data-sources/env-var.js.map +1 -0
  87. package/dist/expressions/data-sources/index.d.ts +4 -35
  88. package/dist/expressions/data-sources/index.d.ts.map +1 -1
  89. package/dist/expressions/data-sources/index.js +17 -119
  90. package/dist/expressions/data-sources/index.js.map +1 -1
  91. package/dist/expressions/data-sources/interface.d.ts +7 -0
  92. package/dist/expressions/data-sources/interface.d.ts.map +1 -0
  93. package/dist/expressions/data-sources/interface.js +3 -0
  94. package/dist/expressions/data-sources/interface.js.map +1 -0
  95. package/dist/expressions/data-sources/local-file.d.ts +13 -0
  96. package/dist/expressions/data-sources/local-file.d.ts.map +1 -0
  97. package/dist/expressions/data-sources/local-file.js +54 -0
  98. package/dist/expressions/data-sources/local-file.js.map +1 -0
  99. package/dist/utils/tagged-template.d.ts +2 -0
  100. package/dist/utils/tagged-template.d.ts.map +1 -0
  101. package/dist/utils/tagged-template.js +10 -0
  102. package/dist/utils/tagged-template.js.map +1 -0
  103. package/package.json +6 -4
  104. package/src/core/graph/origin/entity.ts +2 -2
  105. package/src/core/graph/origin/exporter.ts +5 -5
  106. package/src/core/graph/origin/external.ts +18 -0
  107. package/src/core/graph/origin/index.ts +1 -0
  108. package/src/core/graph/origin/kind-map/index.ts +6 -11
  109. package/src/core/graph/origin/node.ts +2 -2
  110. package/src/core/graph/origin/tracker.ts +12 -1
  111. package/src/core/graph/resource/api-kind/index.ts +16 -4
  112. package/src/core/graph/resource/entity.ts +3 -1
  113. package/src/core/graph/resource/external/base.ts +47 -0
  114. package/src/core/graph/resource/external/features.ts +16 -0
  115. package/src/core/graph/resource/external/index.ts +3 -0
  116. package/src/core/graph/resource/external/props.ts +16 -0
  117. package/src/core/graph/resource/field.ts +0 -0
  118. package/src/core/graph/resource/index.ts +2 -0
  119. package/src/core/graph/resource/node.ts +15 -4
  120. package/src/core/graph/resource/ref-key/ref-key.ts +32 -4
  121. package/src/core/graph/resource/reference/fw-ref-exports.ts +5 -5
  122. package/src/core/graph/resource/reference/fw-ref.ts +6 -7
  123. package/src/core/graph/resource/reference/index.ts +1 -6
  124. package/src/core/graph/resource/reference/refable.ts +15 -8
  125. package/src/core/graph/resource/top.ts +11 -1
  126. package/src/expressions/data-sources/base.ts +14 -0
  127. package/src/expressions/data-sources/env-var.ts +17 -0
  128. package/src/expressions/data-sources/index.ts +4 -147
  129. package/src/expressions/data-sources/interface.ts +13 -0
  130. package/src/expressions/data-sources/local-file.ts +49 -0
  131. package/src/utils/tagged-template.ts +6 -0
@@ -1,123 +1,21 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DataSource_LocalFile = void 0;
7
- exports.localFile = localFile;
8
- exports.isTypedArray = isTypedArray;
9
- exports.isArrayBuffer = isArrayBuffer;
10
- exports.resolveText = resolveText;
11
- exports.resolveBinary = resolveBinary;
12
- const doddle_1 = require("doddle");
13
- const promises_1 = require("fs/promises");
14
- const path_1 = require("path");
15
- const stacktracey_1 = __importDefault(require("stacktracey"));
16
- const error_1 = require("../../error");
17
- class DataSource_LocalFile {
18
- _props;
19
- constructor(_props) {
20
- this._props = _props;
21
- }
22
- get cwd() {
23
- if (this._props.cwd) {
24
- return this._props.cwd;
25
- }
26
- const where = this._props.pointOfCall.at(0);
27
- return (0, path_1.dirname)(where.file);
28
- }
29
- get path() {
30
- const where = this._props.pointOfCall.at(0);
31
- const joined = (0, path_1.join)((0, path_1.dirname)(where.file), this._props.path);
32
- return (0, path_1.resolve)(joined);
33
- }
34
- contents = (0, doddle_1.doddle)(async () => {
35
- const mode = this._props.mode ?? "text";
36
- if (mode === "binary") {
37
- const data = await (0, promises_1.readFile)(this.path, null);
38
- return data;
39
- }
40
- return (0, promises_1.readFile)(this.path, "utf-8");
41
- });
42
- }
43
- exports.DataSource_LocalFile = DataSource_LocalFile;
44
- function localFile(args, ...params) {
45
- if (typeof args === "string") {
46
- const options = params[0] ?? {};
47
- return new DataSource_LocalFile({
48
- pointOfCall: new stacktracey_1.default().slice(1),
49
- path: args,
50
- ...(options ?? {})
51
- });
52
- }
53
- const path = String.raw(args, ...params);
54
- return new DataSource_LocalFile({
55
- pointOfCall: new stacktracey_1.default().slice(1),
56
- path
57
- });
58
- }
59
- function isTypedArray(data) {
60
- return (typeof data === "object" &&
61
- "buffer" in data &&
62
- "byteSize" in data &&
63
- typeof data.byteSize === "number");
64
- }
65
- function isArrayBuffer(data) {
66
- return data instanceof ArrayBuffer;
67
- }
68
- async function promiseAllMap(m) {
69
- const promises = (0, doddle_1.seq)(m)
70
- .map(async (x) => [x[0], await x[1].pull()])
71
- .toArray()
72
- .pull();
73
- const res = await Promise.all(promises);
74
- return new Map(res);
75
- }
76
- async function resolveText(record) {
77
- const mp = (0, doddle_1.seq)(Object.entries(record))
78
- .map(([k, v]) => {
79
- return [
80
- k,
81
- (0, doddle_1.doddle)(async () => {
82
- let resolved = v;
83
- if (v instanceof DataSource_LocalFile) {
84
- resolved = await v.contents.pull();
85
- }
86
- if (typeof resolved !== "string") {
87
- throw new error_1.InstrumentsError(`Got an invalid data value ${v} for key ${k}. Must be a string.`);
88
- }
89
- return resolved;
90
- })
91
- ];
92
- })
93
- .toMap(x => x)
94
- .pull();
95
- return promiseAllMap(mp);
96
- }
97
- async function resolveBinary(record) {
98
- const mp = (0, doddle_1.seq)(Object.entries(record))
99
- .map(([k, v]) => {
100
- return [
101
- k,
102
- (0, doddle_1.doddle)(async () => {
103
- let resolved = v;
104
- if (v instanceof DataSource_LocalFile) {
105
- resolved = await v.contents.pull();
106
- }
107
- if (isTypedArray(resolved)) {
108
- return new Uint8Array(resolved.buffer);
109
- }
110
- else if (isArrayBuffer(resolved)) {
111
- return new Uint8Array(resolved);
112
- }
113
- else {
114
- throw new error_1.InstrumentsError(`Got an invalid data value ${v} for key ${k}. Must be binary data.`);
115
- }
116
- })
117
- ];
118
- })
119
- .toMap(x => x)
120
- .pull();
121
- return promiseAllMap(mp);
122
- }
17
+ __exportStar(require("./base"), exports);
18
+ __exportStar(require("./env-var"), exports);
19
+ __exportStar(require("./interface"), exports);
20
+ __exportStar(require("./local-file"), exports);
123
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/expressions/data-sources/index.ts"],"names":[],"mappings":";;;;;;AAgDA,8BAcC;AAWD,oCAOC;AACD,sCAEC;AAcD,kCAsBC;AACD,sCA0BC;AAlJD,mCAA8D;AAC9D,0CAAsC;AACtC,+BAA6C;AAC7C,8DAAqC;AACrC,uCAA8C;AAS9C,MAAa,oBAAoB;IACA;IAA7B,YAA6B,MAAwC;QAAxC,WAAM,GAAN,MAAM,CAAkC;IAAG,CAAC;IAEzE,IAAI,GAAG;QACH,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAA;QAC1B,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAC3C,OAAO,IAAA,cAAO,EAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC9B,CAAC;IAED,IAAI,IAAI;QACJ,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAC3C,MAAM,MAAM,GAAG,IAAA,WAAI,EAAC,IAAA,cAAO,EAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAC1D,OAAO,IAAA,cAAO,EAAC,MAAM,CAAC,CAAA;IAC1B,CAAC;IAED,QAAQ,GAAG,IAAA,eAAM,EAAC,KAAK,IAAI,EAAE;QACzB,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAA;QACvC,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACpB,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,CAAC,IAAI,EA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E;gBACd,IAAI,QAAQ,GAAG,CAAQ,CAAA;gBACvB,IAAI,CAAC,YAAY,oBAAoB,EAAE,CAAC;oBACpC,QAAQ,GAAG,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;gBACtC,CAAC;gBACD,IAAI,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;oBACzB,OAAO,IAAI,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;gBAC1C,CAAC;qBAAM,IAAI,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;oBACjC,OAAO,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAA;gBACnC,CAAC;qBAAM,CAAC;oBACJ,MAAM,IAAI,wBAAgB,CACtB,6BAA6B,CAAC,YAAY,CAAC,wBAAwB,CACtE,CAAA;gBACL,CAAC;YACL,CAAC,CAAC;SACI,CAAA;IACd,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SACb,IAAI,EAAE,CAAA;IAEX,OAAO,aAAa,CAAC,EAAE,CAAC,CAAA;AAC5B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/expressions/data-sources/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAsB;AACtB,4CAAyB;AACzB,8CAA2B;AAC3B,+CAA4B"}
@@ -0,0 +1,7 @@
1
+ export type DataSource_Type_Name = "string" | "binary";
2
+ export type DataSource_Value<Name extends DataSource_Type_Name> = Name extends "string" ? string : Name extends "binary" ? Uint8Array : DataSource_Type_Name;
3
+ export interface DataSource_Object<TypeName extends DataSource_Type_Name = DataSource_Type_Name> {
4
+ get(): DataSource_Value<TypeName> | Promise<DataSource_Value<TypeName>>;
5
+ }
6
+ export type DataSource<Only extends DataSource_Type_Name = DataSource_Type_Name> = DataSource_Object<Only> | DataSource_Value<Only>;
7
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/expressions/data-sources/interface.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,QAAQ,CAAA;AACtD,MAAM,MAAM,gBAAgB,CAAC,IAAI,SAAS,oBAAoB,IAAI,IAAI,SAAS,QAAQ,GACjF,MAAM,GACN,IAAI,SAAS,QAAQ,GACnB,UAAU,GACV,oBAAoB,CAAA;AAC5B,MAAM,WAAW,iBAAiB,CAAC,QAAQ,SAAS,oBAAoB,GAAG,oBAAoB;IAC3F,GAAG,IAAI,gBAAgB,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAA;CAC1E;AAED,MAAM,MAAM,UAAU,CAAC,IAAI,SAAS,oBAAoB,GAAG,oBAAoB,IACzE,iBAAiB,CAAC,IAAI,CAAC,GACvB,gBAAgB,CAAC,IAAI,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../src/expressions/data-sources/interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import Path from "pathlib-js";
2
+ import type { TypedArray } from "what-are-you";
3
+ import { DataSource_Lazy } from "./base";
4
+ export type DataSource_Allowed = string | Uint8Array | TypedArray;
5
+ export declare class DataSource_LocalFile_Path {
6
+ private readonly _cwd;
7
+ readonly path: Path;
8
+ constructor(_cwd: Path, relPath: string);
9
+ as(mode: "text", encoding?: BufferEncoding): DataSource_Lazy<string>;
10
+ as(mode: "binary"): DataSource_Lazy<Uint8Array>;
11
+ }
12
+ export declare function localRefFile(path: string): DataSource_LocalFile_Path;
13
+ //# sourceMappingURL=local-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-file.d.ts","sourceRoot":"","sources":["../../../src/expressions/data-sources/local-file.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,YAAY,CAAA;AAE7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACxC,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAA;AACjE,qBAAa,yBAAyB;IAG9B,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFzB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;gBAEE,IAAI,EAAE,IAAI,EAC3B,OAAO,EAAE,MAAM;IAKnB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,cAAc,GAAG,eAAe,CAAC,MAAM,CAAC;IACpE,EAAE,CAAC,IAAI,EAAE,QAAQ,GAAG,eAAe,CAAC,UAAU,CAAC;CAQlD;AAqBD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,6BAIxC"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DataSource_LocalFile_Path = void 0;
7
+ exports.localRefFile = localRefFile;
8
+ const pathlib_js_1 = __importDefault(require("pathlib-js"));
9
+ const stacktracey_1 = __importDefault(require("stacktracey"));
10
+ const base_1 = require("./base");
11
+ class DataSource_LocalFile_Path {
12
+ _cwd;
13
+ path;
14
+ constructor(_cwd, relPath) {
15
+ this._cwd = _cwd;
16
+ this.path = this._cwd.join(relPath);
17
+ }
18
+ as(mode, encoding) {
19
+ if (mode === "text") {
20
+ return new DataSource_LocalFile_Text(this, encoding);
21
+ }
22
+ else {
23
+ return new DataSource_LocalFile_Binary(this);
24
+ }
25
+ }
26
+ }
27
+ exports.DataSource_LocalFile_Path = DataSource_LocalFile_Path;
28
+ class DataSource_LocalFile_Text extends base_1.DataSource_Lazy {
29
+ _parent;
30
+ encoding;
31
+ constructor(_parent, encoding = "utf-8") {
32
+ super(async () => {
33
+ return this._parent.path.readFile(this.encoding);
34
+ });
35
+ this._parent = _parent;
36
+ this.encoding = encoding;
37
+ }
38
+ }
39
+ class DataSource_LocalFile_Binary extends base_1.DataSource_Lazy {
40
+ _parent;
41
+ constructor(_parent) {
42
+ super(async () => {
43
+ const x = await this._parent.path.readFile();
44
+ return new Uint8Array(x);
45
+ });
46
+ this._parent = _parent;
47
+ }
48
+ }
49
+ function localRefFile(path) {
50
+ const trace = new stacktracey_1.default().slice(1);
51
+ const callerFile = trace.at(0).file;
52
+ return new DataSource_LocalFile_Path(new pathlib_js_1.default(callerFile).parent(), path);
53
+ }
54
+ //# sourceMappingURL=local-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-file.js","sourceRoot":"","sources":["../../../src/expressions/data-sources/local-file.ts"],"names":[],"mappings":";;;;;;AA4CA,oCAIC;AAhDD,4DAA6B;AAC7B,8DAAqC;AAErC,iCAAwC;AAExC,MAAa,yBAAyB;IAGb;IAFZ,IAAI,CAAM;IACnB,YACqB,IAAU,EAC3B,OAAe;QADE,SAAI,GAAJ,IAAI,CAAM;QAG3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC;IAID,EAAE,CAAC,IAAuB,EAAE,QAAyB;QACjD,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;YAClB,OAAO,IAAI,yBAAyB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QACxD,CAAC;aAAM,CAAC;YACJ,OAAO,IAAI,2BAA2B,CAAC,IAAI,CAAC,CAAA;QAChD,CAAC;IACL,CAAC;CACJ;AAlBD,8DAkBC;AACD,MAAM,yBAA0B,SAAQ,sBAAuB;IAEtC;IACR;IAFb,YACqB,OAAkC,EAC1C,WAA2B,OAAO;QAE3C,KAAK,CAAC,KAAK,IAAI,EAAE;YACb,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACpD,CAAC,CAAC,CAAA;QALe,YAAO,GAAP,OAAO,CAA2B;QAC1C,aAAQ,GAAR,QAAQ,CAA0B;IAK/C,CAAC;CACJ;AAED,MAAM,2BAA4B,SAAQ,sBAA2B;IACpC;IAA7B,YAA6B,OAAkC;QAC3D,KAAK,CAAC,KAAK,IAAI,EAAE;YACb,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAA;YAC5C,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;QAC5B,CAAC,CAAC,CAAA;QAJuB,YAAO,GAAP,OAAO,CAA2B;IAK/D,CAAC;CACJ;AAED,SAAgB,YAAY,CAAC,IAAY;IACrC,MAAM,KAAK,GAAG,IAAI,qBAAW,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACxC,MAAM,UAAU,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IACnC,OAAO,IAAI,yBAAyB,CAAC,IAAI,oBAAI,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,CAAA;AAC7E,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function createTaggedTemplate<DataSource_T>(f: (joined: string) => DataSource_T): (tArgs: TemplateStringsArray, ...params: any[]) => DataSource_T;
2
+ //# sourceMappingURL=tagged-template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tagged-template.d.ts","sourceRoot":"","sources":["../../src/utils/tagged-template.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,YAAY,IAC1E,OAAO,oBAAoB,EAAE,GAAG,QAAQ,GAAG,EAAE,kBAIxD"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTaggedTemplate = createTaggedTemplate;
4
+ function createTaggedTemplate(f) {
5
+ return (tArgs, ...params) => {
6
+ const joined = String.raw(tArgs, ...params);
7
+ return f(joined);
8
+ };
9
+ }
10
+ //# sourceMappingURL=tagged-template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tagged-template.js","sourceRoot":"","sources":["../../src/utils/tagged-template.ts"],"names":[],"mappings":";;AAAA,oDAKC;AALD,SAAgB,oBAAoB,CAAe,CAAmC;IAClF,OAAO,CAAC,KAA2B,EAAE,GAAG,MAAa,EAAE,EAAE;QACrD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC,CAAA;QAC3C,OAAO,CAAC,CAAC,MAAM,CAAC,CAAA;IACpB,CAAC,CAAA;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k8ts/instruments",
3
- "version": "0.6.2",
3
+ "version": "0.9.0",
4
4
  "description": "A collection of utilities and core components for k8ts.",
5
5
  "keywords": [
6
6
  "k8ts",
@@ -66,13 +66,15 @@
66
66
  "ip-address": "^10.0.1",
67
67
  "lodash": "^4.17.21",
68
68
  "parjs": "^1.3.9",
69
+ "pathlib-js": "^1.5.0",
70
+ "pathlib-ts": "^0.1.2",
69
71
  "simple-git": "^3.27.0",
70
72
  "stacktracey": "^2.1.8",
71
73
  "timezone-enum": "^1.0.4",
72
- "what-are-you": "^0.1.12"
74
+ "what-are-you": "^0.2.0"
73
75
  },
74
76
  "devDependencies": {
75
- "@k8ts/metadata": "0.5.2",
77
+ "@k8ts/metadata": "^0.7.0",
76
78
  "@types/jest": "^30.0.0",
77
79
  "@types/lodash": "^4.17.16",
78
80
  "@types/node": "20.9.1",
@@ -86,7 +88,7 @@
86
88
  "yamprint": "^0.8.4"
87
89
  },
88
90
  "peerDependencies": {
89
- "@k8ts/metadata": "^0.5.2"
91
+ "@k8ts/metadata": "^0.7.0"
90
92
  },
91
93
  "engines": {
92
94
  "node": ">=16.0.0"
@@ -5,7 +5,7 @@ import { mapValues } from "lodash"
5
5
  import { displayers } from "../../../utils/displayers"
6
6
  import { Entity } from "../entity"
7
7
  import type { Resource_Entity } from "../resource/entity"
8
- import type { Resource_Core_Ref } from "../resource/reference/refable"
8
+ import type { Ref2_Of } from "../resource/reference/refable"
9
9
  import { OriginEventsEmitter, type Origin_EventMap } from "./events"
10
10
  import { KindMap } from "./kind-map"
11
11
  import { OriginNode, type Origin_Props } from "./node"
@@ -104,7 +104,7 @@ export abstract class Origin_Entity<Props extends Origin_Props = Origin_Props> e
104
104
  }
105
105
 
106
106
  // We don't cache this because resources can be added dynamically
107
- get resources(): Iterable<Resource_Core_Ref> {
107
+ get resources(): Iterable<Ref2_Of> {
108
108
  const self = this
109
109
  return seq(function* () {
110
110
  for (const resource of self._ownResources) {
@@ -1,6 +1,6 @@
1
1
  import { doddlify, seq } from "doddle"
2
2
  import type { Resource_Top } from "../resource"
3
- import { FwReference, type Resource_Core_Ref } from "../resource"
3
+ import { FwReference, type Ref2_Of } from "../resource"
4
4
  import { Origin_Entity } from "./entity"
5
5
  import type { Origin_Props } from "./node"
6
6
 
@@ -19,17 +19,17 @@ export abstract class Origin_Exporter<
19
19
  this._parent["__attach_kid__"](this)
20
20
  }
21
21
 
22
- protected abstract __exports__(): Iterable<Resource_Core_Ref>
22
+ protected abstract __exports__(): Iterable<Ref2_Of>
23
23
 
24
24
  protected __parent__() {
25
25
  return this._parent
26
26
  }
27
27
 
28
28
  @doddlify
29
- get resources(): Iterable<Resource_Core_Ref> {
29
+ get resources(): Iterable<Ref2_Of> {
30
30
  const self = this
31
31
  const boundExports = self.__binder__().bind(self.__exports__.bind(self))
32
- const allEmitted = new Set<Resource_Core_Ref>()
32
+ const allEmitted = new Set<Ref2_Of>()
33
33
  const normalResources = seq(() => super.resources).cache()
34
34
  return seq(function* () {
35
35
  for (const em of boundExports() as Resource_Top[]) {
@@ -43,7 +43,7 @@ export abstract class Origin_Exporter<
43
43
  }
44
44
 
45
45
  allEmitted.add(em)
46
- if (em._origin.equals(self)) {
46
+ if (em["__origin__"]().equals(self)) {
47
47
  // Means it's being exported for the first time
48
48
  self.__emit__("resource/exported", {
49
49
  origin: self,
@@ -0,0 +1,18 @@
1
+ import type { Resource_Ctor_Of } from "../resource"
2
+ import { Origin_Entity } from "./entity"
3
+ import type { Origin_Props } from "./node"
4
+
5
+ export class Origin_External extends Origin_Entity {
6
+ get kind() {
7
+ return "[k8ts] External"
8
+ }
9
+ private constructor() {
10
+ super("External", {})
11
+ }
12
+
13
+ protected __parent__(): Origin_Entity<Origin_Props<Resource_Ctor_Of>> | undefined {
14
+ return undefined
15
+ }
16
+
17
+ static instance = new Origin_External()
18
+ }
@@ -1,6 +1,7 @@
1
1
  export * from "./entity"
2
2
  export * from "./events"
3
3
  export * from "./exporter"
4
+ export * from "./external"
4
5
  export * from "./kind-map"
5
6
  export * from "./node"
6
7
  export * from "./tracker"
@@ -53,14 +53,6 @@ export class KindMap<Kinds extends Resource_Ctor_Of = Resource_Ctor_Of> {
53
53
  .pull()
54
54
  }
55
55
 
56
- refKey<Kind extends Kind.IdentParent, Name extends string>(
57
- kind: Kind,
58
- name: Name
59
- ): RefKey<Kind, Name> {
60
- const trueKind = this.getKind(kind)
61
- return new RefKey(trueKind, name) as any
62
- }
63
-
64
56
  parse(ref: string | RefKey<this["__KINDS__"]>): RefKey<this["__KINDS__"]> {
65
57
  const result = this.tryParse(ref)
66
58
  if (!result) {
@@ -90,7 +82,10 @@ export class KindMap<Kinds extends Resource_Ctor_Of = Resource_Ctor_Of> {
90
82
  if (!ident) {
91
83
  return undefined
92
84
  }
93
- return this.refKey(ident, name)
85
+
86
+ return (ident as Kind.Kind).refKey({
87
+ name
88
+ })
94
89
  }
95
90
 
96
91
  get kinds(): Set<string> {
@@ -142,8 +137,8 @@ export class KindMap<Kinds extends Resource_Ctor_Of = Resource_Ctor_Of> {
142
137
  return this._entriesMap.get(converted)
143
138
  }
144
139
 
145
- tryGetKind(kindOrIdent: LookupKey): any {
146
- return this._tryGetEntry(kindOrIdent)?.ident as Kinds | undefined
140
+ tryGetKind(kindOrIdent: LookupKey): this["__KINDS__"] | undefined {
141
+ return this._tryGetEntry(kindOrIdent)?.ident as this["__KINDS__"] | undefined
147
142
  }
148
143
 
149
144
  getKind(kindOrClass: LookupKey): this["__KINDS__"] {
@@ -3,7 +3,7 @@ import chalk from "chalk"
3
3
  import { seq, Seq } from "doddle"
4
4
  import { displayers } from "../../../utils/displayers"
5
5
  import { Node } from "../node"
6
- import type { Resource_Core_Ref, Resource_Ctor_Of } from "../resource"
6
+ import type { Ref2_Of, Resource_Ctor_Of } from "../resource"
7
7
  import type { Origin_Entity } from "./entity"
8
8
  import { type KindMapInput } from "./kind-map"
9
9
 
@@ -54,7 +54,7 @@ export class OriginNode extends Node<OriginNode, Origin_Entity> {
54
54
  get resources() {
55
55
  return this.entity.resources
56
56
  }
57
- readonly attachedTree: Seq<Resource_Core_Ref> = seq(() => {
57
+ readonly attachedTree: Seq<Ref2_Of> = seq(() => {
58
58
  const self = this
59
59
  const desc = self.descendants
60
60
  .concatTo([this])
@@ -1,6 +1,6 @@
1
1
  import { AsyncLocalStorage } from "async_hooks"
2
2
  import { doddle, pull, type Doddle, type MaybeDoddle } from "doddle"
3
- import { isIterable } from "what-are-you"
3
+ import { isIterable, type AnyCtor } from "what-are-you"
4
4
  import type { Origin_Entity } from "./entity"
5
5
 
6
6
  export interface OriginStackBinder {
@@ -18,6 +18,17 @@ export class _OriginContextTracker {
18
18
  return this._store.getStore()
19
19
  }
20
20
 
21
+ firstOfType<X extends Origin_Entity>(t: AnyCtor<X>): X {
22
+ let current = this._store.getStore()
23
+ while (current) {
24
+ if (current instanceof t) {
25
+ return current
26
+ }
27
+ current = current["__parent__"]()
28
+ }
29
+ throw new Error(`No origin of type ${t.name} found in the current origin stack`)
30
+ }
31
+
21
32
  disposableOriginModifier(origin: Origin_Entity): Disposable {
22
33
  const curOrigin = this._store.getStore()
23
34
  this._store.enterWith(origin)
@@ -1,7 +1,8 @@
1
1
  import { InstrumentsError } from "../../../../error"
2
2
  import { bind_own_methods } from "../../../../utils"
3
3
  import { displayers } from "../../../../utils/displayers"
4
- import { RefKey } from "../ref-key"
4
+ import { External_Base, type External_Props, type External_WithFeatures } from "../external"
5
+ import { RefKey, type RefKey_Options } from "../ref-key"
5
6
  import { pluralize } from "./pluralize"
6
7
 
7
8
  export type Kind<
@@ -119,10 +120,21 @@ export namespace Kind {
119
120
  super(name, parent)
120
121
  }
121
122
 
122
- refKey<Name extends string>(name: Name) {
123
- return new RefKey<this, Name>(this as any, name)
123
+ refKey<Name extends string>(options: RefKey_Options<Name>) {
124
+ return new RefKey<this, Name>(this as any, options)
125
+ }
126
+ External<
127
+ N extends string = string,
128
+ const P extends External_Props<this> = External_Props<this>
129
+ >(options: P & RefKey_Options<N>): External_WithFeatures<this, P> {
130
+ return new External_Base(
131
+ this.refKey({
132
+ name: options.name,
133
+ namespace: options.namespace
134
+ }),
135
+ options ?? {}
136
+ ) as any
124
137
  }
125
-
126
138
  get plural() {
127
139
  return pluralize(this.name.toLowerCase())
128
140
  }
@@ -20,7 +20,9 @@ export abstract class Resource_Entity<
20
20
  callback(this)
21
21
  return this
22
22
  }
23
-
23
+ is<K extends Kind.IdentParent>(kind: K): this is { kind: K } {
24
+ return this.kind.equals(kind)
25
+ }
24
26
  abstract readonly namespace: string | undefined
25
27
 
26
28
  ref() {
@@ -0,0 +1,47 @@
1
+ import { Meta } from "@k8ts/metadata"
2
+ import { Origin_External } from "../../origin"
3
+ import type { Kind } from "../api-kind"
4
+ import { Resource_Entity } from "../entity"
5
+ import type { RefKey } from "../ref-key"
6
+ export class External_Base<K extends Kind.IdentParent> extends Resource_Entity<string, any> {
7
+ readonly meta = Meta.make()
8
+ constructor(
9
+ readonly key: RefKey<K>,
10
+ props: any
11
+ ) {
12
+ super(key.name, props)
13
+
14
+ this.meta.add({
15
+ name: key.name,
16
+ namespace: key.namespace,
17
+ "#k8ts.org/is-external": "true"
18
+ })
19
+
20
+ if (props.keys) {
21
+ Object.defineProperties(this, {
22
+ keys: {
23
+ get: () => props.keys
24
+ }
25
+ })
26
+ }
27
+ }
28
+
29
+ protected __origin__() {
30
+ return Origin_External.instance
31
+ }
32
+ get namespace() {
33
+ return this.meta.tryGet("namespace")
34
+ }
35
+
36
+ get kind() {
37
+ return this.key.kind
38
+ }
39
+
40
+ ref() {
41
+ return {
42
+ kind: this.kind.name,
43
+ name: this.name,
44
+ namespace: this.namespace
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,16 @@
1
+ import type { Kind } from "../api-kind"
2
+ import type { External_Base } from "./base"
3
+ import type { External_Props } from "./props"
4
+
5
+ export type External_WithFeatures<
6
+ Kind extends Kind.IdentParent,
7
+ F extends External_Props<Kind>
8
+ > = External_Base<Kind> & {
9
+ kind: Kind
10
+ } & (F extends {
11
+ readonly keys: infer Ks extends string[]
12
+ }
13
+ ? {
14
+ readonly keys: Ks
15
+ }
16
+ : {})
@@ -0,0 +1,3 @@
1
+ export * from "./base"
2
+ export * from "./features"
3
+ export * from "./props"
@@ -0,0 +1,16 @@
1
+ import type { Kind } from "../api-kind"
2
+
3
+ export interface External_Features {
4
+ keys?: string[]
5
+ }
6
+ export interface External_KindToFeatures {
7
+ ConfigMap: {
8
+ keys?: string[]
9
+ }
10
+ Secret: {
11
+ keys?: string[]
12
+ }
13
+ [s: string]: {}
14
+ }
15
+
16
+ export type External_Props<K extends Kind.IdentParent> = External_KindToFeatures[K["name"]]
File without changes
@@ -1,6 +1,8 @@
1
1
  export * from "./api-kind"
2
2
  export * from "./child"
3
3
  export * from "./entity"
4
+ export * from "./external"
5
+ export * from "./field"
4
6
  export * from "./node"
5
7
  export * from "./ref-key"
6
8
  export * from "./reference"