@alienplatform/bindings 1.0.0 → 1.14.1-dev.e74fae6cd01b61e77a285276f264b5480977f41a

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 (55) hide show
  1. package/README.md +59 -0
  2. package/dist/errors.d.ts +56 -0
  3. package/dist/errors.d.ts.map +1 -0
  4. package/dist/factories.d.ts +26 -0
  5. package/dist/factories.d.ts.map +1 -0
  6. package/dist/index.d.ts +19 -1768
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +23 -44772
  9. package/dist/loader.d.ts +171 -0
  10. package/dist/loader.d.ts.map +1 -0
  11. package/dist/loader.js +3712 -0
  12. package/dist/native.d.ts +41 -0
  13. package/dist/native.d.ts.map +1 -0
  14. package/dist/native.js +46 -0
  15. package/dist/types.d.ts +150 -0
  16. package/dist/types.d.ts.map +1 -0
  17. package/package.json +46 -27
  18. package/AGENTS.md +0 -70
  19. package/dist/index.js.map +0 -1
  20. package/scripts/generate-proto.sh +0 -46
  21. package/src/bindings/AGENTS.md +0 -105
  22. package/src/bindings/artifact-registry.ts +0 -314
  23. package/src/bindings/build.ts +0 -195
  24. package/src/bindings/function.ts +0 -164
  25. package/src/bindings/index.ts +0 -12
  26. package/src/bindings/kv.ts +0 -240
  27. package/src/bindings/queue.ts +0 -191
  28. package/src/bindings/service-account.ts +0 -113
  29. package/src/bindings/storage.ts +0 -535
  30. package/src/bindings/vault.ts +0 -133
  31. package/src/channel.ts +0 -94
  32. package/src/commands.ts +0 -76
  33. package/src/context.ts +0 -368
  34. package/src/errors.ts +0 -259
  35. package/src/events.ts +0 -463
  36. package/src/generated/artifact_registry.ts +0 -1934
  37. package/src/generated/build.ts +0 -1263
  38. package/src/generated/container.ts +0 -485
  39. package/src/generated/control.ts +0 -1574
  40. package/src/generated/function.ts +0 -741
  41. package/src/generated/google/protobuf/duration.ts +0 -196
  42. package/src/generated/google/protobuf/timestamp.ts +0 -225
  43. package/src/generated/kv.ts +0 -1137
  44. package/src/generated/queue.ts +0 -729
  45. package/src/generated/service_account.ts +0 -766
  46. package/src/generated/storage.ts +0 -3653
  47. package/src/generated/vault.ts +0 -519
  48. package/src/generated/wait_until.ts +0 -781
  49. package/src/global.ts +0 -316
  50. package/src/grpc-utils.ts +0 -159
  51. package/src/index.ts +0 -156
  52. package/src/types.ts +0 -384
  53. package/src/wait-until.ts +0 -257
  54. package/tsconfig.json +0 -8
  55. package/tsdown.config.ts +0 -14
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # `@alienplatform/bindings`
2
+
3
+ Direct TypeScript bindings for Alien storage, kv, queue, and vault over an
4
+ in-process [napi-rs](https://napi.rs) addon. The addon itself lives in the Rust
5
+ crate `crates/alien-bindings-node`; this package is the published JavaScript
6
+ wrapper that loads it.
7
+
8
+ ## Native addon resolution
9
+
10
+ The addon is loaded lazily on the first binding operation (never at import — the
11
+ package is `sideEffects: false`). `src/loader.ts` resolves it in order:
12
+
13
+ 1. `ALIEN_BINDINGS_ADDON_PATH` — an explicit path to a `.node` file. A dev/test
14
+ escape hatch only; never set in a published install.
15
+ 2. The per-platform prebuild package `@alienplatform/bindings-<triple>`, pulled
16
+ in as an `optionalDependency`. This is how end users get the addon: `npm`/`bun`
17
+ installs only the package matching the host `os`/`cpu`/`libc`. The
18
+ `optionalDependencies` block exists **only in the published manifest** — it is
19
+ injected at publish time by the release pipeline, so a workspace checkout
20
+ carries none.
21
+ 3. Dev fallback: a locally-built addon at
22
+ `crates/alien-bindings-node/alien-bindings-node.<triple>.node`, found by
23
+ walking up from the installed package. Loaded only if its `version()` matches
24
+ this package's version (a stale build is warned about and rejected).
25
+
26
+ ## Local development
27
+
28
+ Build the addon for your host once, then run anything that imports the package:
29
+
30
+ ```sh
31
+ bun run build:addon # or: pnpm -C packages/bindings run build:addon
32
+ ```
33
+
34
+ `build:addon` runs `napi build --platform --release` against
35
+ `crates/alien-bindings-node` and drops the `.node` next to the crate, where the
36
+ loader's dev fallback (step 3 above) finds it. Rebuild after changing any Rust
37
+ in `alien-bindings` or `alien-bindings-node`. The built `.node` is gitignored.
38
+ `build:addon` only builds for the host triple; on a Mac, cross-building the
39
+ other mac triple (e.g. `darwin-x64` from an `arm64` host) needs an explicit
40
+ `napi build --release --target x86_64-apple-darwin --cwd
41
+ ../../crates/alien-bindings-node`.
42
+
43
+ To point the loader at an addon somewhere else, set `ALIEN_BINDINGS_ADDON_PATH`
44
+ to its path (step 1).
45
+
46
+ ## Prebuild packages (`npm/`)
47
+
48
+ `npm/<triple>/` holds the skeleton for each published per-platform package
49
+ (`darwin-arm64`, `darwin-x64`, `linux-x64-gnu`, `linux-arm64-gnu`). Each carries
50
+ a `package.json` (`name`/`os`/`cpu`/`libc`/`main`/`files`) and a README; the
51
+ `.node` is staged in at build time and is never committed. There is no musl
52
+ target: the deployment base images are glibc (chainguard/wolfi-base), not Alpine.
53
+
54
+ The release pipeline builds each addon on its native runner, stages it into the
55
+ matching `npm/<triple>/` dir, rewrites the placeholder `0.0.0` versions to the
56
+ release version, injects the exact-version `optionalDependencies` into this
57
+ package's published manifest, and publishes the platform packages before the
58
+ wrapper. Pinning the exact version is what guarantees a published wrapper only
59
+ ever loads the matching-version platform addon.
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Error definitions and napi error recovery for `@alienplatform/bindings`.
3
+ *
4
+ * The native addon runs every binding operation as an async napi method. napi
5
+ * constrains async errors to a fixed `Status` string, so `err.code` is always
6
+ * `"GenericFailure"` and carries no information. The addon instead serializes a
7
+ * structured envelope into the JS `err.message`:
8
+ *
9
+ * { code, message, context?, retryable }
10
+ *
11
+ * where `context` keys are snake_case (e.g. `binding_name`, `env_var`).
12
+ * `unwrapNapiError` recovers that envelope with a single `JSON.parse` — never by
13
+ * scraping the human message — and maps it to a typed {@link AlienError}.
14
+ */
15
+ import { AlienError, defineError } from "@alienplatform/core";
16
+ import * as z from "zod/v4";
17
+ export { AlienError, defineError };
18
+ /**
19
+ * Thrown on the first operation against a binding that has no
20
+ * `ALIEN_<NAME>_BINDING` entry in the environment.
21
+ *
22
+ * `binding` is the binding name; `envVar` is the missing `ALIEN_<NAME>_BINDING`
23
+ * variable. Both are mapped from the addon envelope's snake_case
24
+ * `binding_name` / `env_var` context keys.
25
+ */
26
+ export declare const BindingNotConfiguredError: {
27
+ metadata: import("@alienplatform/core").AlienErrorMetadata<z.ZodObject<{
28
+ binding: z.ZodString;
29
+ envVar: z.ZodString;
30
+ }, z.core.$strip>>;
31
+ contextSchema: z.ZodObject<{
32
+ binding: z.ZodString;
33
+ envVar: z.ZodString;
34
+ }, z.core.$strip>;
35
+ create: (context: {
36
+ binding: string;
37
+ envVar: string;
38
+ }) => import("@alienplatform/core").AlienErrorDefinition<z.ZodObject<{
39
+ binding: z.ZodString;
40
+ envVar: z.ZodString;
41
+ }, z.core.$strip>>;
42
+ };
43
+ /**
44
+ * Recover a typed {@link AlienError} from an error thrown by the native addon.
45
+ *
46
+ * - An error that is already an {@link AlienError} passes through unchanged.
47
+ * - A message carrying the addon envelope is decoded: `BINDING_NOT_CONFIGURED`
48
+ * becomes {@link BindingNotConfiguredError} (with `binding` / `envVar` mapped
49
+ * from the envelope's snake_case context); every other envelope code becomes a
50
+ * generic `AlienError` that preserves the `code`, `message`, `context`, and
51
+ * `retryable` flag.
52
+ * - A non-envelope message (napi-internal error) is wrapped as a generic
53
+ * `BINDINGS_ERROR`, preserving the original message.
54
+ */
55
+ export declare function unwrapNapiError(err: unknown): AlienError;
56
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAA;AAI3B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,CAAA;AAElC;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;CAWpC,CAAA;AAwCF;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,CAsCxD"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The four binding factories, parameterized over how the native addon is
3
+ * obtained. `index.ts` binds them to the lazy {@link loadAddon}; `native.ts`
4
+ * binds them to a statically-embedded addon.
5
+ *
6
+ * Laziness contract: constructing a factory result performs no work. The first
7
+ * operation on a handle materializes the `BindingsHandle` and the resource
8
+ * handle exactly once, caches both, and every operation translates thrown napi
9
+ * errors through {@link unwrapNapiError}. A failed materialization is not
10
+ * cached, so a later call retries.
11
+ *
12
+ * Handle methods are closures (not `this`-bound class methods), so they behave
13
+ * correctly even when destructured off the handle (`const { get } = storage(x)`).
14
+ */
15
+ import type { NativeAddon } from "./loader.js";
16
+ import type { Kv, Queue, Storage, Vault } from "./types.js";
17
+ /** The public factory surface. */
18
+ export interface Factories {
19
+ storage(name: string): Storage;
20
+ kv(name: string): Kv;
21
+ queue(name: string): Queue;
22
+ vault(name: string): Vault;
23
+ }
24
+ /** Build the four factories bound to a given addon provider. */
25
+ export declare function createFactories(getAddon: () => NativeAddon): Factories;
26
+ //# sourceMappingURL=factories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factories.d.ts","sourceRoot":"","sources":["../src/factories.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EACV,WAAW,EAMZ,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EACV,EAAE,EAIF,KAAK,EAGL,OAAO,EACP,KAAK,EACN,MAAM,YAAY,CAAA;AA+HnB,kCAAkC;AAClC,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IAC9B,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAAA;IACpB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAA;IAC1B,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAA;CAC3B;AAED,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,WAAW,GAAG,SAAS,CAWtE"}