@faable/deploy-sdk 2.17.1 → 2.18.1

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 (36) hide show
  1. package/dist/FaableDeployApi.d.ts +89 -0
  2. package/dist/FaableDeployApi.d.ts.map +1 -1
  3. package/dist/FaableDeployApi.js +10 -0
  4. package/dist/api/api-types.d.ts +19 -0
  5. package/dist/api/api-types.d.ts.map +1 -1
  6. package/dist/api/generated-client.d.ts +856 -3
  7. package/dist/api/generated-client.d.ts.map +1 -1
  8. package/dist/api/generated-client.js +510 -3
  9. package/dist/api/types.d.ts +4897 -819
  10. package/dist/api/types.d.ts.map +1 -1
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +1 -0
  14. package/dist/informers/Indexer.d.ts +28 -0
  15. package/dist/informers/Indexer.d.ts.map +1 -0
  16. package/dist/informers/Indexer.js +89 -0
  17. package/dist/informers/InformerFactory.d.ts +113 -0
  18. package/dist/informers/InformerFactory.d.ts.map +1 -0
  19. package/dist/informers/InformerFactory.js +343 -0
  20. package/dist/informers/WatchClient.d.ts +38 -0
  21. package/dist/informers/WatchClient.d.ts.map +1 -0
  22. package/dist/informers/WatchClient.js +9 -0
  23. package/dist/informers/deployApiWatchClient.d.ts +4 -0
  24. package/dist/informers/deployApiWatchClient.d.ts.map +1 -0
  25. package/dist/informers/deployApiWatchClient.js +36 -0
  26. package/dist/informers/index.d.ts +6 -0
  27. package/dist/informers/index.d.ts.map +1 -0
  28. package/dist/informers/index.js +5 -0
  29. package/dist/informers/ndjson.d.ts +2 -0
  30. package/dist/informers/ndjson.d.ts.map +1 -0
  31. package/dist/informers/ndjson.js +19 -0
  32. package/dist/informers/rv.d.ts +15 -0
  33. package/dist/informers/rv.d.ts.map +1 -0
  34. package/dist/informers/rv.js +33 -0
  35. package/package.json +1 -1
  36. package/spec/openapi.json +16505 -7626
@@ -0,0 +1,36 @@
1
+ import { ndjson } from "./ndjson.js";
2
+ import { WatchExpiredError, } from "./WatchClient.js";
3
+ // The WatchClient over the deploy API's fetcher (auth, identity headers and
4
+ // baseURL included): GET /watch/list and the NDJSON stream of GET /watch.
5
+ //
6
+ // ⚠️ The client must not have `etagCache` on: the ETag path would treat the
7
+ // stream as a cacheable body. Build a separate DeployApi for informers.
8
+ const isGone = (err) => err?.response?.status === 410 || err?.status === 410 || err?.statusCode === 410;
9
+ export const deployApiWatchClient = (fetcher) => ({
10
+ list: async (resource) => fetcher.request({
11
+ method: "GET",
12
+ url: "/watch/list",
13
+ params: { resource },
14
+ }),
15
+ watch: (resources, rv, signal) => ({
16
+ async *[Symbol.asyncIterator]() {
17
+ let stream;
18
+ try {
19
+ stream = await fetcher.request({
20
+ method: "GET",
21
+ url: "/watch",
22
+ params: { resources: resources.join(","), rv },
23
+ responseType: "stream",
24
+ timeout: 0,
25
+ signal,
26
+ });
27
+ }
28
+ catch (err) {
29
+ if (isGone(err))
30
+ throw new WatchExpiredError();
31
+ throw err;
32
+ }
33
+ yield* ndjson(stream);
34
+ },
35
+ }),
36
+ });
@@ -0,0 +1,6 @@
1
+ export { Indexer, type IndexFn } from "./Indexer.js";
2
+ export { InformerFactory, SharedInformer, WatchIdleError, type InformerEvent, type InformerFactoryOptions, } from "./InformerFactory.js";
3
+ export { compareRv, minRv, rvGeneration, rvTimeMs } from "./rv.js";
4
+ export { WatchExpiredError, type ListResult, type WatchClient, type WatchEvent, type WatchResource, } from "./WatchClient.js";
5
+ export { deployApiWatchClient } from "./deployApiWatchClient.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/informers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EACL,eAAe,EACf,cAAc,EACd,cAAc,EACd,KAAK,aAAa,EAClB,KAAK,sBAAsB,GAC5B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClE,OAAO,EACL,iBAAiB,EACjB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,aAAa,GACnB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA"}
@@ -0,0 +1,5 @@
1
+ export { Indexer } from "./Indexer.js";
2
+ export { InformerFactory, SharedInformer, WatchIdleError, } from "./InformerFactory.js";
3
+ export { compareRv, minRv, rvGeneration, rvTimeMs } from "./rv.js";
4
+ export { WatchExpiredError, } from "./WatchClient.js";
5
+ export { deployApiWatchClient } from "./deployApiWatchClient.js";
@@ -0,0 +1,2 @@
1
+ export declare function ndjson(chunks: AsyncIterable<Uint8Array | string>): AsyncGenerator<any>;
2
+ //# sourceMappingURL=ndjson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ndjson.d.ts","sourceRoot":"","sources":["../../src/informers/ndjson.ts"],"names":[],"mappings":"AAEA,wBAAuB,MAAM,CAC3B,MAAM,EAAE,aAAa,CAAC,UAAU,GAAG,MAAM,CAAC,GACzC,cAAc,CAAC,GAAG,CAAC,CAcrB"}
@@ -0,0 +1,19 @@
1
+ // Lines of an NDJSON byte stream (Node Readable or any async iterable of
2
+ // chunks), parsed. A partial last line is kept until it completes.
3
+ export async function* ndjson(chunks) {
4
+ const decoder = new TextDecoder();
5
+ let buf = "";
6
+ for await (const chunk of chunks) {
7
+ buf += typeof chunk === "string" ? chunk : decoder.decode(chunk, { stream: true });
8
+ let i;
9
+ while ((i = buf.indexOf("\n")) >= 0) {
10
+ const line = buf.slice(0, i).trim();
11
+ buf = buf.slice(i + 1);
12
+ if (line)
13
+ yield JSON.parse(line);
14
+ }
15
+ }
16
+ const last = buf.trim();
17
+ if (last)
18
+ yield JSON.parse(last);
19
+ }
@@ -0,0 +1,15 @@
1
+ /** <0, 0, >0 like a comparator; an unparsable rv sorts first. */
2
+ export declare const compareRv: (a: string, b: string) => number;
3
+ /**
4
+ * When the change entered the cache's stream (ms since epoch), from the
5
+ * stream position in an rv. `now - rvTimeMs(rv)` is how long the event took
6
+ * to reach this process — the informer's freshness. null if unparsable.
7
+ */
8
+ export declare const rvTimeMs: (rv: string) => number | null;
9
+ /**
10
+ * The generation of an rv (it changes when the server's stream is reset).
11
+ * rvs of different generations are not comparable. null if unparsable.
12
+ */
13
+ export declare const rvGeneration: (rv: string) => number | null;
14
+ export declare const minRv: (rvs: string[]) => string;
15
+ //# sourceMappingURL=rv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rv.d.ts","sourceRoot":"","sources":["../../src/informers/rv.ts"],"names":[],"mappings":"AASA,iEAAiE;AACjE,eAAO,MAAM,SAAS,MAAO,MAAM,KAAK,MAAM,KAAG,MAKhD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,OAAQ,MAAM,KAAG,MAAM,GAAG,IAG9C,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,OAAQ,MAAM,KAAG,MAAM,GAAG,IAGlD,CAAA;AAED,eAAO,MAAM,KAAK,QAAS,MAAM,EAAE,KAAG,MACe,CAAA"}
@@ -0,0 +1,33 @@
1
+ // A resourceVersion from the watch API: `<generation>.<streamMs>-<seq>`
2
+ // (arch/api/informers.md § 1). Ordered by generation, then stream position.
3
+ // Opaque to callers; only compared here.
4
+ const parse = (rv) => {
5
+ const m = /^(\d+)\.(\d+)-(\d+)$/.exec(rv);
6
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
7
+ };
8
+ /** <0, 0, >0 like a comparator; an unparsable rv sorts first. */
9
+ export const compareRv = (a, b) => {
10
+ const pa = parse(a);
11
+ const pb = parse(b);
12
+ if (!pa || !pb)
13
+ return pa ? 1 : pb ? -1 : 0;
14
+ return pa[0] - pb[0] || pa[1] - pb[1] || pa[2] - pb[2];
15
+ };
16
+ /**
17
+ * When the change entered the cache's stream (ms since epoch), from the
18
+ * stream position in an rv. `now - rvTimeMs(rv)` is how long the event took
19
+ * to reach this process — the informer's freshness. null if unparsable.
20
+ */
21
+ export const rvTimeMs = (rv) => {
22
+ const p = parse(rv);
23
+ return p ? p[1] : null;
24
+ };
25
+ /**
26
+ * The generation of an rv (it changes when the server's stream is reset).
27
+ * rvs of different generations are not comparable. null if unparsable.
28
+ */
29
+ export const rvGeneration = (rv) => {
30
+ const p = parse(rv);
31
+ return p ? p[0] : null;
32
+ };
33
+ export const minRv = (rvs) => rvs.reduce((m, r) => (compareRv(r, m) < 0 ? r : m));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@faable/deploy-sdk",
3
3
  "description": "Codebase for SDK building",
4
- "version": "2.17.1",
4
+ "version": "2.18.1",
5
5
  "author": "Marc Pomar <marc@faable.com>",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",