@supatype/shared 0.7.0 → 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.
@@ -0,0 +1,46 @@
1
+ import { isString, type FromShape } from "./json.js";
2
+ declare const FUNCTION_DEPLOY_ENTRY: {
3
+ readonly name: typeof isString;
4
+ readonly source: typeof isString;
5
+ readonly entrypoint: import("./json.js").Optional<string>;
6
+ readonly files: import("./json.js").Optional<Record<string, string>>;
7
+ };
8
+ declare const FUNCTION_DEPLOY_BODY: {
9
+ readonly functions: import("./json.js").Guard<FromShape<{
10
+ readonly name: typeof isString;
11
+ readonly source: typeof isString;
12
+ readonly entrypoint: import("./json.js").Optional<string>;
13
+ readonly files: import("./json.js").Optional<Record<string, string>>;
14
+ }>[]>;
15
+ readonly serviceRole: import("./json.js").Optional<string[]>;
16
+ };
17
+ /**
18
+ * One function in a deploy: its name; `source`, its entry module; `entrypoint`, that module's path
19
+ * as `<name>/index.ts`; and for a function of more than one file, `files`, every file by a `/` path
20
+ * under the function's directory. The reader still checks the name against the function-name rule
21
+ * and every path in `files` against its directory.
22
+ */
23
+ export declare const isFunctionDeployEntry: import("./json.js").Guard<FromShape<{
24
+ readonly name: typeof isString;
25
+ readonly source: typeof isString;
26
+ readonly entrypoint: import("./json.js").Optional<string>;
27
+ readonly files: import("./json.js").Optional<Record<string, string>>;
28
+ }>>;
29
+ export type FunctionDeployEntry = FromShape<typeof FUNCTION_DEPLOY_ENTRY>;
30
+ /**
31
+ * `POST /projects/:ref/functions/deploy`, on Cloud and on a self-hosted control plane: every
32
+ * function in one request, so a self-hosted worker restarts once a deploy; and `serviceRole`, the
33
+ * routes granted the service-role key, which the platform replaces wholesale when it is present.
34
+ */
35
+ export declare const isFunctionDeployBody: import("./json.js").Guard<FromShape<{
36
+ readonly functions: import("./json.js").Guard<FromShape<{
37
+ readonly name: typeof isString;
38
+ readonly source: typeof isString;
39
+ readonly entrypoint: import("./json.js").Optional<string>;
40
+ readonly files: import("./json.js").Optional<Record<string, string>>;
41
+ }>[]>;
42
+ readonly serviceRole: import("./json.js").Optional<string[]>;
43
+ }>>;
44
+ export type FunctionDeployBody = FromShape<typeof FUNCTION_DEPLOY_BODY>;
45
+ export {};
46
+ //# sourceMappingURL=function-deploy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-deploy.d.ts","sourceRoot":"","sources":["../src/function-deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,QAAQ,EAAY,KAAK,SAAS,EAAE,MAAM,WAAW,CAAA;AAE9F,QAAA,MAAM,qBAAqB;;;;;CAKjB,CAAA;AAEV,QAAA,MAAM,oBAAoB;;;;;;;;CAGhB,CAAA;AAEV;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB;;;;;GAAiC,CAAA;AACnE,MAAM,MAAM,mBAAmB,GAAG,SAAS,CAAC,OAAO,qBAAqB,CAAC,CAAA;AAEzE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;GAAgC,CAAA;AACjE,MAAM,MAAM,kBAAkB,GAAG,SAAS,CAAC,OAAO,oBAAoB,CAAC,CAAA"}
@@ -0,0 +1,25 @@
1
+ import { isArrayOf, isRecordOf, isShape, isString, optional } from "./json.js";
2
+ const FUNCTION_DEPLOY_ENTRY = {
3
+ name: isString,
4
+ source: isString,
5
+ entrypoint: optional(isString),
6
+ files: optional(isRecordOf(isString)),
7
+ };
8
+ const FUNCTION_DEPLOY_BODY = {
9
+ functions: isArrayOf(isShape(FUNCTION_DEPLOY_ENTRY)),
10
+ serviceRole: optional(isArrayOf(isString)),
11
+ };
12
+ /**
13
+ * One function in a deploy: its name; `source`, its entry module; `entrypoint`, that module's path
14
+ * as `<name>/index.ts`; and for a function of more than one file, `files`, every file by a `/` path
15
+ * under the function's directory. The reader still checks the name against the function-name rule
16
+ * and every path in `files` against its directory.
17
+ */
18
+ export const isFunctionDeployEntry = isShape(FUNCTION_DEPLOY_ENTRY);
19
+ /**
20
+ * `POST /projects/:ref/functions/deploy`, on Cloud and on a self-hosted control plane: every
21
+ * function in one request, so a self-hosted worker restarts once a deploy; and `serviceRole`, the
22
+ * routes granted the service-role key, which the platform replaces wholesale when it is present.
23
+ */
24
+ export const isFunctionDeployBody = isShape(FUNCTION_DEPLOY_BODY);
25
+ //# sourceMappingURL=function-deploy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-deploy.js","sourceRoot":"","sources":["../src/function-deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAkB,MAAM,WAAW,CAAA;AAE9F,MAAM,qBAAqB,GAAG;IAC5B,IAAI,EAAE,QAAQ;IACd,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC;IAC9B,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;CAC7B,CAAA;AAEV,MAAM,oBAAoB,GAAG;IAC3B,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACpD,WAAW,EAAE,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;CAClC,CAAA;AAEV;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAA;AAGnE;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA"}
@@ -9,4 +9,5 @@ export declare const FUNCTION_NAME: RegExp;
9
9
  export declare const FUNCTION_NAME_RULE = "use lowercase letters, digits, \"-\" and \"_\", starting with a letter or digit";
10
10
  /** Whether `name` passes the function-name rule. */
11
11
  export declare function isFunctionName(name: unknown): name is string;
12
+ export { HOOK_NAME, HOOK_NAME_RULE, isHookName } from "./function-routes.js";
12
13
  //# sourceMappingURL=function-name.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"function-name.d.ts","sourceRoot":"","sources":["../src/function-name.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,aAAa,QAA0B,CAAA;AAEpD,mCAAmC;AACnC,eAAO,MAAM,kBAAkB,oFAAgF,CAAA;AAE/G,oDAAoD;AACpD,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAE5D"}
1
+ {"version":3,"file":"function-name.d.ts","sourceRoot":"","sources":["../src/function-name.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,aAAa,QAA0B,CAAA;AAEpD,mCAAmC;AACnC,eAAO,MAAM,kBAAkB,oFAAgF,CAAA;AAE/G,oDAAoD;AACpD,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAE5D;AAID,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA"}
@@ -11,4 +11,7 @@ export const FUNCTION_NAME_RULE = 'use lowercase letters, digits, "-" and "_", s
11
11
  export function isFunctionName(name) {
12
12
  return typeof name === "string" && FUNCTION_NAME.test(name);
13
13
  }
14
+ // The hook rule lives with the route rule, which the functions worker gets a copy of, so the worker
15
+ // judges a hook name as the control plane does.
16
+ export { HOOK_NAME, HOOK_NAME_RULE, isHookName } from "./function-routes.js";
14
17
  //# sourceMappingURL=function-name.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"function-name.js","sourceRoot":"","sources":["../src/function-name.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,uBAAuB,CAAA;AAEpD,mCAAmC;AACnC,MAAM,CAAC,MAAM,kBAAkB,GAAG,6EAA6E,CAAA;AAE/G,oDAAoD;AACpD,MAAM,UAAU,cAAc,CAAC,IAAa;IAC1C,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC7D,CAAC"}
1
+ {"version":3,"file":"function-name.js","sourceRoot":"","sources":["../src/function-name.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,uBAAuB,CAAA;AAEpD,mCAAmC;AACnC,MAAM,CAAC,MAAM,kBAAkB,GAAG,6EAA6E,CAAA;AAE/G,oDAAoD;AACpD,MAAM,UAAU,cAAc,CAAC,IAAa;IAC1C,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC7D,CAAC;AAED,oGAAoG;AACpG,gDAAgD;AAChD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Which entries of a functions or hooks directory the functions worker serves, and by what route
3
+ * name. The worker discovers its routes by this rule and a self-hosted control plane lists them by
4
+ * it, so the list names exactly what answers. The worker cannot import this package: the generator
5
+ * (scripts/functions-worker-source.mjs) copies this file into it as routes.ts, so it must import
6
+ * nothing.
7
+ */
8
+ /** The module a directory route runs; a directory without one is not a route. */
9
+ export declare const FUNCTION_ENTRY_FILE = "index.ts";
10
+ /**
11
+ * The route the worker serves for `entry`, or undefined for an entry it skips. `_` and `.` prefixed
12
+ * entries are never routes (`_shared`, `.git`). A directory is the route of its name, when it holds
13
+ * {@link FUNCTION_ENTRY_FILE}, which the caller checks. A file is the route of its name without
14
+ * `.ts`; a declaration file (`.d.ts`) and anything else is not one.
15
+ */
16
+ export declare function functionRouteName(entry: string, kind: "directory" | "file"): string | undefined;
17
+ /**
18
+ * A hook name: letters of either case, digits, `-` and `_`, starting with a letter or digit. Wider
19
+ * than a function name, because the CLI and Cloud take a hook's name from the schema and its folder
20
+ * as written (`onUserCreate`): Cloud stores it as a ConfigMap key, and the worker skips a name that
21
+ * starts with `_` or `.`. Still one path segment: nothing in it can name a parent, a separator or a
22
+ * hidden entry.
23
+ */
24
+ export declare const HOOK_NAME: RegExp;
25
+ /** The hook rule, said for a person. */
26
+ export declare const HOOK_NAME_RULE = "use letters, digits, \"-\" and \"_\", starting with a letter or digit";
27
+ /** Whether `name` passes the hook-name rule. */
28
+ export declare function isHookName(name: unknown): name is string;
29
+ //# sourceMappingURL=function-routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-routes.d.ts","sourceRoot":"","sources":["../src/function-routes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iFAAiF;AACjF,eAAO,MAAM,mBAAmB,aAAa,CAAA;AAE7C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAI/F;AAED;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,QAAgC,CAAA;AAEtD,wCAAwC;AACxC,eAAO,MAAM,cAAc,0EAAsE,CAAA;AAEjG,gDAAgD;AAChD,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAExD"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Which entries of a functions or hooks directory the functions worker serves, and by what route
3
+ * name. The worker discovers its routes by this rule and a self-hosted control plane lists them by
4
+ * it, so the list names exactly what answers. The worker cannot import this package: the generator
5
+ * (scripts/functions-worker-source.mjs) copies this file into it as routes.ts, so it must import
6
+ * nothing.
7
+ */
8
+ /** The module a directory route runs; a directory without one is not a route. */
9
+ export const FUNCTION_ENTRY_FILE = "index.ts";
10
+ /**
11
+ * The route the worker serves for `entry`, or undefined for an entry it skips. `_` and `.` prefixed
12
+ * entries are never routes (`_shared`, `.git`). A directory is the route of its name, when it holds
13
+ * {@link FUNCTION_ENTRY_FILE}, which the caller checks. A file is the route of its name without
14
+ * `.ts`; a declaration file (`.d.ts`) and anything else is not one.
15
+ */
16
+ export function functionRouteName(entry, kind) {
17
+ if (entry.startsWith("_") || entry.startsWith("."))
18
+ return undefined;
19
+ if (kind === "directory")
20
+ return entry;
21
+ return entry.endsWith(".ts") && !entry.endsWith(".d.ts") ? entry.slice(0, -".ts".length) : undefined;
22
+ }
23
+ /**
24
+ * A hook name: letters of either case, digits, `-` and `_`, starting with a letter or digit. Wider
25
+ * than a function name, because the CLI and Cloud take a hook's name from the schema and its folder
26
+ * as written (`onUserCreate`): Cloud stores it as a ConfigMap key, and the worker skips a name that
27
+ * starts with `_` or `.`. Still one path segment: nothing in it can name a parent, a separator or a
28
+ * hidden entry.
29
+ */
30
+ export const HOOK_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
31
+ /** The hook rule, said for a person. */
32
+ export const HOOK_NAME_RULE = 'use letters, digits, "-" and "_", starting with a letter or digit';
33
+ /** Whether `name` passes the hook-name rule. */
34
+ export function isHookName(name) {
35
+ return typeof name === "string" && HOOK_NAME.test(name);
36
+ }
37
+ //# sourceMappingURL=function-routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"function-routes.js","sourceRoot":"","sources":["../src/function-routes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iFAAiF;AACjF,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAA;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAa,EAAE,IAA0B;IACzE,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAA;IACpE,IAAI,IAAI,KAAK,WAAW;QAAE,OAAO,KAAK,CAAA;IACtC,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AACtG,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,6BAA6B,CAAA;AAEtD,wCAAwC;AACxC,MAAM,CAAC,MAAM,cAAc,GAAG,mEAAmE,CAAA;AAEjG,gDAAgD;AAChD,MAAM,UAAU,UAAU,CAAC,IAAa;IACtC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzD,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * How long Docker gives the functions worker to stop before it kills it, in seconds: the compose
3
+ * file's `stop_grace_period` and the control plane's `docker restart -t`. One Docker killed it 3 s
4
+ * after SIGTERM (round 6, N29), cutting off the drain that lets requests in flight finish.
5
+ */
6
+ export declare const FUNCTIONS_WORKER_STOP_GRACE_SECONDS = 10;
7
+ /**
8
+ * How long the worker in a compose stack lets requests in flight finish when it is stopped
9
+ * (`SUPATYPE_FUNCTIONS_DRAIN_MS`, functions-worker stop.ts): a second under its stop grace, so it
10
+ * exits by itself before Docker kills it. Its own default, 4 s, is for dev, where the process
11
+ * manager kills it after 5 s; in a stack it cut off every function with more left (round 6b, N29).
12
+ */
13
+ export declare const FUNCTIONS_WORKER_DRAIN_MS: number;
14
+ /**
15
+ * The file in a stack's .supatype that names the public functions given the service-role key,
16
+ * comma-separated. A self-hosted control plane writes it on every deploy from the `serviceRole` the
17
+ * deploy carries, replacing the list wholesale as Cloud does, and the worker reads it on every call
18
+ * (`SUPATYPE_SERVICE_ROLE_ROUTES_FILE`, which compose points here), so a route taken off the list
19
+ * loses the key on its next call.
20
+ */
21
+ export declare const SERVICE_ROLE_ROUTES_FILE = "service-role-routes";
22
+ //# sourceMappingURL=functions-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions-worker.d.ts","sourceRoot":"","sources":["../src/functions-worker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,mCAAmC,KAAK,CAAA;AAErD;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,QAAmD,CAAA;AAEzF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,wBAAwB,CAAA"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * How long Docker gives the functions worker to stop before it kills it, in seconds: the compose
3
+ * file's `stop_grace_period` and the control plane's `docker restart -t`. One Docker killed it 3 s
4
+ * after SIGTERM (round 6, N29), cutting off the drain that lets requests in flight finish.
5
+ */
6
+ export const FUNCTIONS_WORKER_STOP_GRACE_SECONDS = 10;
7
+ /**
8
+ * How long the worker in a compose stack lets requests in flight finish when it is stopped
9
+ * (`SUPATYPE_FUNCTIONS_DRAIN_MS`, functions-worker stop.ts): a second under its stop grace, so it
10
+ * exits by itself before Docker kills it. Its own default, 4 s, is for dev, where the process
11
+ * manager kills it after 5 s; in a stack it cut off every function with more left (round 6b, N29).
12
+ */
13
+ export const FUNCTIONS_WORKER_DRAIN_MS = (FUNCTIONS_WORKER_STOP_GRACE_SECONDS - 1) * 1000;
14
+ /**
15
+ * The file in a stack's .supatype that names the public functions given the service-role key,
16
+ * comma-separated. A self-hosted control plane writes it on every deploy from the `serviceRole` the
17
+ * deploy carries, replacing the list wholesale as Cloud does, and the worker reads it on every call
18
+ * (`SUPATYPE_SERVICE_ROLE_ROUTES_FILE`, which compose points here), so a route taken off the list
19
+ * loses the key on its next call.
20
+ */
21
+ export const SERVICE_ROLE_ROUTES_FILE = "service-role-routes";
22
+ //# sourceMappingURL=functions-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functions-worker.js","sourceRoot":"","sources":["../src/functions-worker.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,EAAE,CAAA;AAErD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,mCAAmC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAA;AAEzF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,qBAAqB,CAAA"}
package/dist/index.d.ts CHANGED
@@ -5,7 +5,13 @@
5
5
  */
6
6
  export { ENGINE_BUSY, ENGINE_BUSY_WORDING, engineBusySentence } from "./engine-busy.js";
7
7
  export { CAPABILITIES_TTL_MS, capabilitiesCache, rememberCapabilities, rememberCapabilitiesSync, type CapabilitiesCache, } from "./capabilities-cache.js";
8
- export { FUNCTION_NAME, FUNCTION_NAME_RULE, isFunctionName } from "./function-name.js";
8
+ export { FUNCTION_NAME, FUNCTION_NAME_RULE, HOOK_NAME, HOOK_NAME_RULE, isFunctionName, isHookName } from "./function-name.js";
9
+ export { FUNCTION_ENTRY_FILE, functionRouteName } from "./function-routes.js";
10
+ export { isFunctionDeployBody, isFunctionDeployEntry, type FunctionDeployBody, type FunctionDeployEntry, } from "./function-deploy.js";
11
+ export { FUNCTIONS_WORKER_DRAIN_MS, FUNCTIONS_WORKER_STOP_GRACE_SECONDS, SERVICE_ROLE_ROUTES_FILE } from "./functions-worker.js";
12
+ export { workerLoadsFile } from "./worker-files.js";
9
13
  export { MAX_IDENTIFIER_BYTES, keptName, makeObjectName, utf8ByteLength, versionsTableName, } from "./identifier-names.js";
14
+ export { pathInside, resolveInside, toPosixPath } from "./path-inside.js";
10
15
  export { isArrayOf, isBoolean, isJsonObject, isNumber, isOneOf, isRecordOf, isShape, isString, isUnknown, nullable, optional, parseJsonObject, readJson, type FromShape, type Guard, type JsonResponse, type Optional, type ParsedJsonObject, } from "./json.js";
16
+ export { ADAPTER_IMPORT, ADAPTER_NAME, HOOK_FILES_FEATURE, HOOK_KEEP_FEATURE, isHookDeployAnswer, type HookDeployAnswer, FLATTENED_ADAPTER_IMPORT, applyManifestMaps, flattenHookSource, isCacheMap, isHookDeployBody, isHookMap, isTableMap, unflattenHookSource, type CacheMap, type HookDeployBody, type HookMap, type ManifestCacheEntry, type ManifestHookEntry, type ManifestMaps, type ManifestTableEntry, type TableMap, type AfterHookColumns, } from "./manifest-maps.js";
11
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACvF,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,KAAK,iBAAiB,GACvB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACtF,OAAO,EACL,oBAAoB,EACpB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,iBAAiB,GAClB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,SAAS,EACT,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,UAAU,EACV,OAAO,EACP,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,gBAAgB,GACtB,MAAM,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACvF,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,KAAK,iBAAiB,GACvB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,SAAS,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC7H,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,yBAAyB,EAAE,mCAAmC,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAChI,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EACL,oBAAoB,EACpB,QAAQ,EACR,cAAc,EACd,cAAc,EACd,iBAAiB,GAClB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACzE,OAAO,EACL,SAAS,EACT,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,UAAU,EACV,OAAO,EACP,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,gBAAgB,GACtB,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,wBAAwB,EACxB,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,mBAAmB,EACnB,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,QAAQ,EACb,KAAK,gBAAgB,GACtB,MAAM,oBAAoB,CAAA"}
package/dist/index.js CHANGED
@@ -5,7 +5,13 @@
5
5
  */
6
6
  export { ENGINE_BUSY, ENGINE_BUSY_WORDING, engineBusySentence } from "./engine-busy.js";
7
7
  export { CAPABILITIES_TTL_MS, capabilitiesCache, rememberCapabilities, rememberCapabilitiesSync, } from "./capabilities-cache.js";
8
- export { FUNCTION_NAME, FUNCTION_NAME_RULE, isFunctionName } from "./function-name.js";
8
+ export { FUNCTION_NAME, FUNCTION_NAME_RULE, HOOK_NAME, HOOK_NAME_RULE, isFunctionName, isHookName } from "./function-name.js";
9
+ export { FUNCTION_ENTRY_FILE, functionRouteName } from "./function-routes.js";
10
+ export { isFunctionDeployBody, isFunctionDeployEntry, } from "./function-deploy.js";
11
+ export { FUNCTIONS_WORKER_DRAIN_MS, FUNCTIONS_WORKER_STOP_GRACE_SECONDS, SERVICE_ROLE_ROUTES_FILE } from "./functions-worker.js";
12
+ export { workerLoadsFile } from "./worker-files.js";
9
13
  export { MAX_IDENTIFIER_BYTES, keptName, makeObjectName, utf8ByteLength, versionsTableName, } from "./identifier-names.js";
14
+ export { pathInside, resolveInside, toPosixPath } from "./path-inside.js";
10
15
  export { isArrayOf, isBoolean, isJsonObject, isNumber, isOneOf, isRecordOf, isShape, isString, isUnknown, nullable, optional, parseJsonObject, readJson, } from "./json.js";
16
+ export { ADAPTER_IMPORT, ADAPTER_NAME, HOOK_FILES_FEATURE, HOOK_KEEP_FEATURE, isHookDeployAnswer, FLATTENED_ADAPTER_IMPORT, applyManifestMaps, flattenHookSource, isCacheMap, isHookDeployBody, isHookMap, isTableMap, unflattenHookSource, } from "./manifest-maps.js";
11
17
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACvF,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,GAEzB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACtF,OAAO,E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,EACf,QAAQ,GAMT,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAElB,wBAAwB,EACxB,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,mBAAmB,GAUpB,MAAM,oBAAoB,CAAA"}
@@ -0,0 +1,177 @@
1
+ /**
2
+ * The route manifest's maps (`hooks`, `validators`, `cache`, `tables`), the hook deploy body that
3
+ * carries them to a stack, and how a hook handler is flattened for that body and put back. The CLI writes the
4
+ * maps for a local stack and sends the body to a linked one; the self-host control plane reads the
5
+ * body and writes the same maps. Each kept its own copy of these until both drew them from here.
6
+ */
7
+ import { isString, isUnknown, type FromShape } from "./json.js";
8
+ /** One hook or validator entry, in the shape the server's `proxy.RouteManifest` reads. */
9
+ export interface ManifestHookEntry {
10
+ function: string;
11
+ timeout?: number;
12
+ onUnavailable?: "reject" | "log";
13
+ }
14
+ /** One table's cache declaration, as the manifest carries it. */
15
+ export interface ManifestCacheEntry {
16
+ enabled?: boolean;
17
+ maxTtl?: number;
18
+ public?: boolean;
19
+ rows?: boolean;
20
+ }
21
+ /** Table to event (hooks) or column (validators) to the entry. */
22
+ export type HookMap = Record<string, Record<string, ManifestHookEntry>>;
23
+ /** Table to its cache declaration. */
24
+ export type CacheMap = Record<string, ManifestCacheEntry>;
25
+ /** Which columns an after-hook's rows carry: `"safe"` leaves out restricted columns, `"all"` keeps them. */
26
+ export type AfterHookColumns = "safe" | "all";
27
+ /**
28
+ * One hooked table, as the after-hook listener reads it: what each after-hook's rows carry (a
29
+ * missing event means `"safe"`), the columns with a field `read` rule, and the key columns in order.
30
+ *
31
+ * A map of its own beside `hooks` rather than keys inside a `hooks` table entry, because a released
32
+ * server reads every key of such an entry as a hook event and would refuse the whole manifest.
33
+ */
34
+ export interface ManifestTableEntry {
35
+ columns: {
36
+ afterChange?: AfterHookColumns;
37
+ afterDelete?: AfterHookColumns;
38
+ };
39
+ restrictedColumns: string[];
40
+ primaryKey: string[];
41
+ }
42
+ /** Table to its after-hook column settings and key. */
43
+ export type TableMap = Record<string, ManifestTableEntry>;
44
+ /** The manifest's maps, keyed as the manifest keys them. */
45
+ export interface ManifestMaps {
46
+ hooks: HookMap;
47
+ validators: HookMap;
48
+ cache: CacheMap;
49
+ tables: TableMap;
50
+ }
51
+ /** A hook or validator map: every entry names its function. */
52
+ export declare const isHookMap: import("./json.js").Guard<Record<string, Record<string, FromShape<{
53
+ function: typeof isString;
54
+ timeout: import("./json.js").Optional<number>;
55
+ onUnavailable: import("./json.js").Optional<"reject" | "log">;
56
+ }>>>>;
57
+ /** A cache map: each entry carries only what the manifest reads, each of its type. */
58
+ export declare const isCacheMap: import("./json.js").Guard<Record<string, FromShape<{
59
+ enabled: import("./json.js").Optional<boolean>;
60
+ public: import("./json.js").Optional<boolean>;
61
+ rows: import("./json.js").Optional<boolean>;
62
+ maxTtl: import("./json.js").Optional<number>;
63
+ }>>>;
64
+ /** A table map: each entry's columns per after-hook, restricted columns and key, each of its type. */
65
+ export declare const isTableMap: import("./json.js").Guard<Record<string, FromShape<{
66
+ columns: import("./json.js").Guard<FromShape<{
67
+ afterChange: import("./json.js").Optional<"safe" | "all">;
68
+ afterDelete: import("./json.js").Optional<"safe" | "all">;
69
+ }>>;
70
+ restrictedColumns: import("./json.js").Guard<string[]>;
71
+ primaryKey: import("./json.js").Guard<string[]>;
72
+ }>>>;
73
+ declare const HOOK_DEPLOY_BODY: {
74
+ readonly handlers: import("./json.js").Optional<FromShape<{
75
+ name: typeof isUnknown;
76
+ source: typeof isString;
77
+ files: import("./json.js").Optional<Record<string, string>>;
78
+ }>[]>;
79
+ readonly map: import("./json.js").Optional<unknown>;
80
+ readonly validators: import("./json.js").Optional<unknown>;
81
+ readonly cache: import("./json.js").Optional<unknown>;
82
+ readonly tables: import("./json.js").Optional<unknown>;
83
+ readonly keep: import("./json.js").Optional<string[]>;
84
+ };
85
+ /**
86
+ * `POST /projects/:ref/hooks/deploy`: `handlers`, each a name and its flattened source, the adapter
87
+ * among them as {@link ADAPTER_NAME}, and for a hook of more than one file sent to a target that
88
+ * takes them, `files`: every file of its directory by `/` path, as written; `map`, the hook map;
89
+ * `validators`, `cache` and `tables`, the manifest's other maps; and `keep`, the hooks the sender
90
+ * could not deploy (they failed its checks), whose code on the target stays exactly as it is. The
91
+ * maps are checked with {@link isHookMap}, {@link isCacheMap} and {@link isTableMap} by the reader,
92
+ * which says which is wrong.
93
+ *
94
+ * Each hook passes or fails on its own: a hook that fails keeps its last good version where it has
95
+ * one, and a new one leaves the tables that map it refusing writes until it deploys. A write never
96
+ * skips a hook.
97
+ */
98
+ export declare const isHookDeployBody: import("./json.js").Guard<FromShape<{
99
+ readonly handlers: import("./json.js").Optional<FromShape<{
100
+ name: typeof isUnknown;
101
+ source: typeof isString;
102
+ files: import("./json.js").Optional<Record<string, string>>;
103
+ }>[]>;
104
+ readonly map: import("./json.js").Optional<unknown>;
105
+ readonly validators: import("./json.js").Optional<unknown>;
106
+ readonly cache: import("./json.js").Optional<unknown>;
107
+ readonly tables: import("./json.js").Optional<unknown>;
108
+ readonly keep: import("./json.js").Optional<string[]>;
109
+ }>>;
110
+ export type HookDeployBody = FromShape<typeof HOOK_DEPLOY_BODY>;
111
+ declare const HOOK_DEPLOY_ANSWER: {
112
+ readonly handlers: import("./json.js").Guard<string[]>;
113
+ readonly tables: import("./json.js").Guard<string[]>;
114
+ readonly refused: import("./json.js").Optional<FromShape<{
115
+ name: typeof isString;
116
+ reason: typeof isString;
117
+ }>[]>;
118
+ readonly kept: import("./json.js").Optional<string[]>;
119
+ readonly locked: import("./json.js").Optional<string[]>;
120
+ readonly restarted: import("./json.js").Optional<boolean>;
121
+ readonly warning: import("./json.js").Optional<string>;
122
+ };
123
+ /**
124
+ * The answer's `data` to a hooks deploy. `handlers`: the hooks deployed; `tables`: the tables the
125
+ * hook map names. `refused`: hooks the target itself refused, each with why. Every hook not deployed,
126
+ * whether the sender kept it (`keep`) or the target refused it, is in exactly one of `kept` (its
127
+ * previous version stays and still runs) or `locked` (it had none: writes to the tables that map it
128
+ * are refused until it deploys). `restarted` and `warning` are a self-hosted stack's, about its
129
+ * worker. Cloud mirrors this shape (it cannot import this package).
130
+ */
131
+ export declare const isHookDeployAnswer: import("./json.js").Guard<FromShape<{
132
+ readonly handlers: import("./json.js").Guard<string[]>;
133
+ readonly tables: import("./json.js").Guard<string[]>;
134
+ readonly refused: import("./json.js").Optional<FromShape<{
135
+ name: typeof isString;
136
+ reason: typeof isString;
137
+ }>[]>;
138
+ readonly kept: import("./json.js").Optional<string[]>;
139
+ readonly locked: import("./json.js").Optional<string[]>;
140
+ readonly restarted: import("./json.js").Optional<boolean>;
141
+ readonly warning: import("./json.js").Optional<string>;
142
+ }>>;
143
+ export type HookDeployAnswer = FromShape<typeof HOOK_DEPLOY_ANSWER>;
144
+ /**
145
+ * Sets each manifest key `maps` names to its map, removing the key when the map is empty; a key whose
146
+ * map is undefined is left as it is. Removing rather than writing `{}` matters: the server tells "no
147
+ * map" from "an empty map" when it decides whether the manifest predates the feature. True when the
148
+ * manifest changed.
149
+ */
150
+ export declare function applyManifestMaps(manifest: Record<string, unknown>, maps: {
151
+ [K in keyof ManifestMaps]?: ManifestMaps[K] | undefined;
152
+ }): boolean;
153
+ /** The generated adapter's name among the uploaded handlers; `_`-prefixed, so no worker routes to it. */
154
+ export declare const ADAPTER_NAME = "_supatype-hooks";
155
+ /** What a project's handler imports the adapter as, and what that import is flattened to. */
156
+ export declare const ADAPTER_IMPORT = "../_supatype/hooks.ts";
157
+ export declare const FLATTENED_ADAPTER_IMPORT = "./_supatype-hooks.ts";
158
+ /** A handler's source with its adapter import flattened, for a stack that serves handlers side by side. */
159
+ export declare function flattenHookSource(source: string): string;
160
+ /** A flattened handler's source put back into a project's layout (`<name>/index.ts`). */
161
+ export declare function unflattenHookSource(source: string): string;
162
+ /**
163
+ * The feature a target lists in `GET /projects/:ref/schema/capabilities` (`data.features`) when its
164
+ * hooks deploy takes `handlers[].files`, a hook of more than one file written as sent. A self-hosted
165
+ * control plane lists it; one from before it, and Cloud, do not, and a CLI sends such a hook only
166
+ * where it is listed.
167
+ */
168
+ export declare const HOOK_FILES_FEATURE = "hook_files";
169
+ /**
170
+ * The feature a target lists in its capabilities (`data.features`) when its hooks deploy takes
171
+ * `keep` and deploys hook by hook (HookDeployAnswer: refused, kept, locked). A CLI deploys per hook
172
+ * only where it is listed; anywhere else a failed hook means no hook is sent, and the hooks deployed
173
+ * before stay as they were.
174
+ */
175
+ export declare const HOOK_KEEP_FEATURE = "hook_keep";
176
+ export {};
177
+ //# sourceMappingURL=manifest-maps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest-maps.d.ts","sourceRoot":"","sources":["../src/manifest-maps.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAgE,QAAQ,EAAE,SAAS,EAAY,KAAK,SAAS,EAAE,MAAM,WAAW,CAAA;AAEvI,0FAA0F;AAC1F,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,aAAa,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAA;CACjC;AAED,iEAAiE;AACjE,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED,kEAAkE;AAClE,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAA;AAEvE,sCAAsC;AACtC,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAA;AAEzD,4GAA4G;AAC5G,MAAM,MA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,YAAY,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS;CAAE,GAChE,OAAO,CAUT;AAED,yGAAyG;AACzG,eAAO,MAAM,YAAY,oBAAoB,CAAA;AAE7C,6FAA6F;AAC7F,eAAO,MAAM,cAAc,0BAA0B,CAAA;AACrD,eAAO,MAAM,wBAAwB,yBAAyB,CAAA;AAE9D,2GAA2G;AAC3G,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,yFAAyF;AACzF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,eAAe,CAAA;AAE9C;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,cAAc,CAAA"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * The route manifest's maps (`hooks`, `validators`, `cache`, `tables`), the hook deploy body that
3
+ * carries them to a stack, and how a hook handler is flattened for that body and put back. The CLI writes the
4
+ * maps for a local stack and sends the body to a linked one; the self-host control plane reads the
5
+ * body and writes the same maps. Each kept its own copy of these until both drew them from here.
6
+ */
7
+ import { isArrayOf, isBoolean, isNumber, isOneOf, isRecordOf, isShape, isString, isUnknown, optional } from "./json.js";
8
+ const isHookEntry = isShape({
9
+ function: isString,
10
+ timeout: optional(isNumber),
11
+ onUnavailable: optional(isOneOf(["reject", "log"])),
12
+ });
13
+ /** A hook or validator map: every entry names its function. */
14
+ export const isHookMap = isRecordOf(isRecordOf(isHookEntry));
15
+ /** A cache map: each entry carries only what the manifest reads, each of its type. */
16
+ export const isCacheMap = isRecordOf(isShape({ enabled: optional(isBoolean), public: optional(isBoolean), rows: optional(isBoolean), maxTtl: optional(isNumber) }));
17
+ const isAfterHookColumns = optional(isOneOf(["safe", "all"]));
18
+ /** A table map: each entry's columns per after-hook, restricted columns and key, each of its type. */
19
+ export const isTableMap = isRecordOf(isShape({
20
+ columns: isShape({ afterChange: isAfterHookColumns, afterDelete: isAfterHookColumns }),
21
+ restrictedColumns: isArrayOf(isString),
22
+ primaryKey: isArrayOf(isString),
23
+ }));
24
+ const HOOK_DEPLOY_BODY = {
25
+ handlers: optional(isArrayOf(isShape({ name: isUnknown, source: isString, files: optional(isRecordOf(isString)) }))),
26
+ map: optional(isUnknown),
27
+ validators: optional(isUnknown),
28
+ cache: optional(isUnknown),
29
+ tables: optional(isUnknown),
30
+ keep: optional(isArrayOf(isString)),
31
+ };
32
+ /**
33
+ * `POST /projects/:ref/hooks/deploy`: `handlers`, each a name and its flattened source, the adapter
34
+ * among them as {@link ADAPTER_NAME}, and for a hook of more than one file sent to a target that
35
+ * takes them, `files`: every file of its directory by `/` path, as written; `map`, the hook map;
36
+ * `validators`, `cache` and `tables`, the manifest's other maps; and `keep`, the hooks the sender
37
+ * could not deploy (they failed its checks), whose code on the target stays exactly as it is. The
38
+ * maps are checked with {@link isHookMap}, {@link isCacheMap} and {@link isTableMap} by the reader,
39
+ * which says which is wrong.
40
+ *
41
+ * Each hook passes or fails on its own: a hook that fails keeps its last good version where it has
42
+ * one, and a new one leaves the tables that map it refusing writes until it deploys. A write never
43
+ * skips a hook.
44
+ */
45
+ export const isHookDeployBody = isShape(HOOK_DEPLOY_BODY);
46
+ const HOOK_DEPLOY_ANSWER = {
47
+ handlers: isArrayOf(isString),
48
+ tables: isArrayOf(isString),
49
+ refused: optional(isArrayOf(isShape({ name: isString, reason: isString }))),
50
+ kept: optional(isArrayOf(isString)),
51
+ locked: optional(isArrayOf(isString)),
52
+ restarted: optional(isBoolean),
53
+ warning: optional(isString),
54
+ };
55
+ /**
56
+ * The answer's `data` to a hooks deploy. `handlers`: the hooks deployed; `tables`: the tables the
57
+ * hook map names. `refused`: hooks the target itself refused, each with why. Every hook not deployed,
58
+ * whether the sender kept it (`keep`) or the target refused it, is in exactly one of `kept` (its
59
+ * previous version stays and still runs) or `locked` (it had none: writes to the tables that map it
60
+ * are refused until it deploys). `restarted` and `warning` are a self-hosted stack's, about its
61
+ * worker. Cloud mirrors this shape (it cannot import this package).
62
+ */
63
+ export const isHookDeployAnswer = isShape(HOOK_DEPLOY_ANSWER);
64
+ /**
65
+ * Sets each manifest key `maps` names to its map, removing the key when the map is empty; a key whose
66
+ * map is undefined is left as it is. Removing rather than writing `{}` matters: the server tells "no
67
+ * map" from "an empty map" when it decides whether the manifest predates the feature. True when the
68
+ * manifest changed.
69
+ */
70
+ export function applyManifestMaps(manifest, maps) {
71
+ let changed = false;
72
+ for (const [key, map] of Object.entries(maps)) {
73
+ if (map === undefined)
74
+ continue;
75
+ if (JSON.stringify(map) === JSON.stringify(manifest[key] ?? {}))
76
+ continue;
77
+ if (Object.keys(map).length === 0)
78
+ delete manifest[key];
79
+ else
80
+ manifest[key] = map;
81
+ changed = true;
82
+ }
83
+ return changed;
84
+ }
85
+ /** The generated adapter's name among the uploaded handlers; `_`-prefixed, so no worker routes to it. */
86
+ export const ADAPTER_NAME = "_supatype-hooks";
87
+ /** What a project's handler imports the adapter as, and what that import is flattened to. */
88
+ export const ADAPTER_IMPORT = "../_supatype/hooks.ts";
89
+ export const FLATTENED_ADAPTER_IMPORT = `./${ADAPTER_NAME}.ts`;
90
+ /** A handler's source with its adapter import flattened, for a stack that serves handlers side by side. */
91
+ export function flattenHookSource(source) {
92
+ return source.split(ADAPTER_IMPORT).join(FLATTENED_ADAPTER_IMPORT);
93
+ }
94
+ /** A flattened handler's source put back into a project's layout (`<name>/index.ts`). */
95
+ export function unflattenHookSource(source) {
96
+ return source.split(FLATTENED_ADAPTER_IMPORT).join(ADAPTER_IMPORT);
97
+ }
98
+ /**
99
+ * The feature a target lists in `GET /projects/:ref/schema/capabilities` (`data.features`) when its
100
+ * hooks deploy takes `handlers[].files`, a hook of more than one file written as sent. A self-hosted
101
+ * control plane lists it; one from before it, and Cloud, do not, and a CLI sends such a hook only
102
+ * where it is listed.
103
+ */
104
+ export const HOOK_FILES_FEATURE = "hook_files";
105
+ /**
106
+ * The feature a target lists in its capabilities (`data.features`) when its hooks deploy takes
107
+ * `keep` and deploys hook by hook (HookDeployAnswer: refused, kept, locked). A CLI deploys per hook
108
+ * only where it is listed; anywhere else a failed hook means no hook is sent, and the hooks deployed
109
+ * before stay as they were.
110
+ */
111
+ export const HOOK_KEEP_FEATURE = "hook_keep";
112
+ //# sourceMappingURL=manifest-maps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest-maps.js","sourceRoot":"","sources":["../src/manifest-maps.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAkB,MAAM,WAAW,CAAA;AAkDvI,MAAM,WAAW,GAAG,OAAO,CAAC;IAC1B,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC;IAC3B,aAAa,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;CACpD,CAAC,CAAA;AAEF,+DAA+D;AAC/D,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAA;AAE5D,sFAAsF;AACtF,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAClC,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAC9H,CAAA;AAED,MAAM,kBAAkB,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;AAE7D,sGAAsG;AACtG,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAClC,OA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A;AACpE,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,YAAY,CAAA;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAA"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Whether `path` lands inside `root`, both resolved on this platform as `path.relative` does. The
3
+ * root itself is not inside it: a file cannot be written to its own folder's path.
4
+ *
5
+ * The answer comes from the relative path, never a string prefix: `/srv/app2` starts with
6
+ * `/srv/app` and is beside it, and `..notes` is a name inside it however it starts. On another
7
+ * drive `relative` answers an absolute path, which is outside.
8
+ */
9
+ export declare function pathInside(root: string, path: string): boolean;
10
+ /** `path` resolved against `root` when it lands inside it ({@link pathInside}), otherwise undefined. */
11
+ export declare function resolveInside(root: string, path: string): string | undefined;
12
+ /** `path` with this platform's separator written as `/`, so it reads the same on every platform. */
13
+ export declare function toPosixPath(path: string): string;
14
+ //# sourceMappingURL=path-inside.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-inside.d.ts","sourceRoot":"","sources":["../src/path-inside.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAG9D;AAED,wGAAwG;AACxG,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG5E;AAED,oGAAoG;AACpG,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD"}
@@ -0,0 +1,23 @@
1
+ import { isAbsolute, relative, resolve, sep } from "node:path";
2
+ /**
3
+ * Whether `path` lands inside `root`, both resolved on this platform as `path.relative` does. The
4
+ * root itself is not inside it: a file cannot be written to its own folder's path.
5
+ *
6
+ * The answer comes from the relative path, never a string prefix: `/srv/app2` starts with
7
+ * `/srv/app` and is beside it, and `..notes` is a name inside it however it starts. On another
8
+ * drive `relative` answers an absolute path, which is outside.
9
+ */
10
+ export function pathInside(root, path) {
11
+ const rel = relative(root, path);
12
+ return rel !== "" && rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
13
+ }
14
+ /** `path` resolved against `root` when it lands inside it ({@link pathInside}), otherwise undefined. */
15
+ export function resolveInside(root, path) {
16
+ const target = resolve(root, path);
17
+ return pathInside(root, target) ? target : undefined;
18
+ }
19
+ /** `path` with this platform's separator written as `/`, so it reads the same on every platform. */
20
+ export function toPosixPath(path) {
21
+ return path.split(sep).join("/");
22
+ }
23
+ //# sourceMappingURL=path-inside.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-inside.js","sourceRoot":"","sources":["../src/path-inside.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAE9D;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,IAAY;IACnD,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAChC,OAAO,GAAG,KAAK,EAAE,IAAI,GAAG,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;AACtF,CAAC;AAED,wGAAwG;AACxG,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,IAAY;IACtD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAClC,OAAO,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;AACtD,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAClC,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Whether the functions worker loads the file at `path`, relative to a functions or hooks
3
+ * directory, with `/` or `\` between its parts: a source file, never a dotfile, and never inside a
4
+ * dot directory (.git, an editor's). The env files beside the functions are dotfiles, which the
5
+ * worker reads on each call instead.
6
+ *
7
+ * One rule for both sides: a deploy sends exactly these files, and a self-hosted control plane
8
+ * hashes exactly these to tell whether its worker is stale. The deploy used to send only .ts and
9
+ * .js, so a function importing its JSON or an .mjs module was deployed without them.
10
+ */
11
+ export declare function workerLoadsFile(path: string): boolean;
12
+ //# sourceMappingURL=worker-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-files.d.ts","sourceRoot":"","sources":["../src/worker-files.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIrD"}
@@ -0,0 +1,18 @@
1
+ /** Sources the functions worker imports: a handler and the modules and JSON it imports. */
2
+ const WORKER_SOURCE_FILE = /\.(?:ts|tsx|mts|js|jsx|mjs|json)$/;
3
+ /**
4
+ * Whether the functions worker loads the file at `path`, relative to a functions or hooks
5
+ * directory, with `/` or `\` between its parts: a source file, never a dotfile, and never inside a
6
+ * dot directory (.git, an editor's). The env files beside the functions are dotfiles, which the
7
+ * worker reads on each call instead.
8
+ *
9
+ * One rule for both sides: a deploy sends exactly these files, and a self-hosted control plane
10
+ * hashes exactly these to tell whether its worker is stale. The deploy used to send only .ts and
11
+ * .js, so a function importing its JSON or an .mjs module was deployed without them.
12
+ */
13
+ export function workerLoadsFile(path) {
14
+ const parts = path.split(/[\\/]/);
15
+ const name = parts.at(-1) ?? "";
16
+ return parts.every((part) => !part.startsWith(".")) && WORKER_SOURCE_FILE.test(name);
17
+ }
18
+ //# sourceMappingURL=worker-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-files.js","sourceRoot":"","sources":["../src/worker-files.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,MAAM,kBAAkB,GAAG,mCAAmC,CAAA;AAE9D;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACjC,MAAM,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACtF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supatype/shared",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Rules the Supatype CLI and the self-host control plane must agree on",
6
6
  "type": "module",
@@ -12,8 +12,8 @@
12
12
  ],
13
13
  "exports": {
14
14
  ".": {
15
- "import": "./dist/index.js",
16
- "types": "./dist/index.d.ts"
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.js"
17
17
  }
18
18
  },
19
19
  "devDependencies": {
@@ -23,7 +23,7 @@
23
23
  "scripts": {
24
24
  "build": "tsc --project tsconfig.json",
25
25
  "typecheck": "tsc --project tests/tsconfig.json --noEmit",
26
- "test": "vitest run",
26
+ "test": "vitest run --maxWorkers=50%",
27
27
  "clean": "rm -rf dist *.tsbuildinfo"
28
28
  }
29
29
  }