@usecontextlayer/cli 0.12.1 → 0.13.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.
@@ -1,7 +1,7 @@
1
1
  import { mkdir, readFile, writeFile } from "node:fs/promises";
2
+ import path, { join } from "node:path";
2
3
  import { EventEmitter, addAbortListener, on, once, setMaxListeners } from "node:events";
3
4
  import { ChildProcess, execFile, spawn, spawnSync } from "node:child_process";
4
- import path, { join } from "node:path";
5
5
  import fs, { appendFileSync, closeSync, createReadStream, createWriteStream, openSync, readFileSync, readSync, statSync, writeFileSync } from "node:fs";
6
6
  import process$1, { execArgv, execPath, hrtime, platform } from "node:process";
7
7
  import { aborted, callbackify, debuglog, inspect, promisify, stripVTControlCharacters } from "node:util";
@@ -6957,6 +6957,7 @@ const string$1 = (params) => {
6957
6957
  };
6958
6958
  const integer = /^-?\d+$/;
6959
6959
  const number$1 = /^-?\d+(?:\.\d+)?$/;
6960
+ const boolean$1 = /^(?:true|false)$/i;
6960
6961
  const lowercase = /^[^A-Z]*$/;
6961
6962
  const uppercase = /^[^a-z]*$/;
6962
6963
  //#endregion
@@ -7768,6 +7769,24 @@ const $ZodNumberFormat = /*@__PURE__*/ $constructor("$ZodNumberFormat", (inst, d
7768
7769
  $ZodCheckNumberFormat.init(inst, def);
7769
7770
  $ZodNumber.init(inst, def);
7770
7771
  });
7772
+ const $ZodBoolean = /*@__PURE__*/ $constructor("$ZodBoolean", (inst, def) => {
7773
+ $ZodType.init(inst, def);
7774
+ inst._zod.pattern = boolean$1;
7775
+ inst._zod.parse = (payload, _ctx) => {
7776
+ if (def.coerce) try {
7777
+ payload.value = Boolean(payload.value);
7778
+ } catch (_) {}
7779
+ const input = payload.value;
7780
+ if (typeof input === "boolean") return payload;
7781
+ payload.issues.push({
7782
+ expected: "boolean",
7783
+ code: "invalid_type",
7784
+ input,
7785
+ inst
7786
+ });
7787
+ return payload;
7788
+ };
7789
+ });
7771
7790
  const $ZodUnknown = /*@__PURE__*/ $constructor("$ZodUnknown", (inst, def) => {
7772
7791
  $ZodType.init(inst, def);
7773
7792
  inst._zod.parse = (payload) => payload;
@@ -8211,6 +8230,115 @@ function handleIntersectionResults(result, left, right) {
8211
8230
  result.value = merged.data;
8212
8231
  return result;
8213
8232
  }
8233
+ const $ZodRecord = /*@__PURE__*/ $constructor("$ZodRecord", (inst, def) => {
8234
+ $ZodType.init(inst, def);
8235
+ inst._zod.parse = (payload, ctx) => {
8236
+ const input = payload.value;
8237
+ if (!isPlainObject(input)) {
8238
+ payload.issues.push({
8239
+ expected: "record",
8240
+ code: "invalid_type",
8241
+ input,
8242
+ inst
8243
+ });
8244
+ return payload;
8245
+ }
8246
+ const proms = [];
8247
+ const values = def.keyType._zod.values;
8248
+ if (values) {
8249
+ payload.value = {};
8250
+ const recordKeys = /* @__PURE__ */ new Set();
8251
+ for (const key of values) if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
8252
+ recordKeys.add(typeof key === "number" ? key.toString() : key);
8253
+ const keyResult = def.keyType._zod.run({
8254
+ value: key,
8255
+ issues: []
8256
+ }, ctx);
8257
+ if (keyResult instanceof Promise) throw new Error("Async schemas not supported in object keys currently");
8258
+ if (keyResult.issues.length) {
8259
+ payload.issues.push({
8260
+ code: "invalid_key",
8261
+ origin: "record",
8262
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
8263
+ input: key,
8264
+ path: [key],
8265
+ inst
8266
+ });
8267
+ continue;
8268
+ }
8269
+ const outKey = keyResult.value;
8270
+ const result = def.valueType._zod.run({
8271
+ value: input[key],
8272
+ issues: []
8273
+ }, ctx);
8274
+ if (result instanceof Promise) proms.push(result.then((result) => {
8275
+ if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
8276
+ payload.value[outKey] = result.value;
8277
+ }));
8278
+ else {
8279
+ if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
8280
+ payload.value[outKey] = result.value;
8281
+ }
8282
+ }
8283
+ let unrecognized;
8284
+ for (const key in input) if (!recordKeys.has(key)) {
8285
+ unrecognized = unrecognized ?? [];
8286
+ unrecognized.push(key);
8287
+ }
8288
+ if (unrecognized && unrecognized.length > 0) payload.issues.push({
8289
+ code: "unrecognized_keys",
8290
+ input,
8291
+ inst,
8292
+ keys: unrecognized
8293
+ });
8294
+ } else {
8295
+ payload.value = {};
8296
+ for (const key of Reflect.ownKeys(input)) {
8297
+ if (key === "__proto__") continue;
8298
+ if (!Object.prototype.propertyIsEnumerable.call(input, key)) continue;
8299
+ let keyResult = def.keyType._zod.run({
8300
+ value: key,
8301
+ issues: []
8302
+ }, ctx);
8303
+ if (keyResult instanceof Promise) throw new Error("Async schemas not supported in object keys currently");
8304
+ if (typeof key === "string" && number$1.test(key) && keyResult.issues.length) {
8305
+ const retryResult = def.keyType._zod.run({
8306
+ value: Number(key),
8307
+ issues: []
8308
+ }, ctx);
8309
+ if (retryResult instanceof Promise) throw new Error("Async schemas not supported in object keys currently");
8310
+ if (retryResult.issues.length === 0) keyResult = retryResult;
8311
+ }
8312
+ if (keyResult.issues.length) {
8313
+ if (def.mode === "loose") payload.value[key] = input[key];
8314
+ else payload.issues.push({
8315
+ code: "invalid_key",
8316
+ origin: "record",
8317
+ issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
8318
+ input: key,
8319
+ path: [key],
8320
+ inst
8321
+ });
8322
+ continue;
8323
+ }
8324
+ const result = def.valueType._zod.run({
8325
+ value: input[key],
8326
+ issues: []
8327
+ }, ctx);
8328
+ if (result instanceof Promise) proms.push(result.then((result) => {
8329
+ if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
8330
+ payload.value[keyResult.value] = result.value;
8331
+ }));
8332
+ else {
8333
+ if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
8334
+ payload.value[keyResult.value] = result.value;
8335
+ }
8336
+ }
8337
+ }
8338
+ if (proms.length) return Promise.all(proms).then(() => payload);
8339
+ return payload;
8340
+ };
8341
+ });
8214
8342
  const $ZodEnum = /*@__PURE__*/ $constructor("$ZodEnum", (inst, def) => {
8215
8343
  $ZodType.init(inst, def);
8216
8344
  const values = getEnumValues(def.entries);
@@ -8229,6 +8357,24 @@ const $ZodEnum = /*@__PURE__*/ $constructor("$ZodEnum", (inst, def) => {
8229
8357
  return payload;
8230
8358
  };
8231
8359
  });
8360
+ const $ZodLiteral = /*@__PURE__*/ $constructor("$ZodLiteral", (inst, def) => {
8361
+ $ZodType.init(inst, def);
8362
+ if (def.values.length === 0) throw new Error("Cannot create literal schema with no valid values");
8363
+ const values = new Set(def.values);
8364
+ inst._zod.values = values;
8365
+ inst._zod.pattern = new RegExp(`^(${def.values.map((o) => typeof o === "string" ? escapeRegex(o) : o ? escapeRegex(o.toString()) : String(o)).join("|")})$`);
8366
+ inst._zod.parse = (payload, _ctx) => {
8367
+ const input = payload.value;
8368
+ if (values.has(input)) return payload;
8369
+ payload.issues.push({
8370
+ code: "invalid_value",
8371
+ values: def.values,
8372
+ input,
8373
+ inst
8374
+ });
8375
+ return payload;
8376
+ };
8377
+ });
8232
8378
  const $ZodTransform = /*@__PURE__*/ $constructor("$ZodTransform", (inst, def) => {
8233
8379
  $ZodType.init(inst, def);
8234
8380
  inst._zod.optin = "optional";
@@ -8800,6 +8946,13 @@ function _int(Class, params) {
8800
8946
  });
8801
8947
  }
8802
8948
  // @__NO_SIDE_EFFECTS__
8949
+ function _boolean(Class, params) {
8950
+ return new Class({
8951
+ type: "boolean",
8952
+ ...normalizeParams(params)
8953
+ });
8954
+ }
8955
+ // @__NO_SIDE_EFFECTS__
8803
8956
  function _unknown(Class) {
8804
8957
  return new Class({ type: "unknown" });
8805
8958
  }
@@ -9363,6 +9516,9 @@ const numberProcessor = (schema, ctx, _json, _params) => {
9363
9516
  } else if (typeof maximum === "number") json.maximum = maximum;
9364
9517
  if (typeof multipleOf === "number") json.multipleOf = multipleOf;
9365
9518
  };
9519
+ const booleanProcessor = (_schema, _ctx, json, _params) => {
9520
+ json.type = "boolean";
9521
+ };
9366
9522
  const neverProcessor = (_schema, _ctx, json, _params) => {
9367
9523
  json.not = {};
9368
9524
  };
@@ -9373,6 +9529,28 @@ const enumProcessor = (schema, _ctx, json, _params) => {
9373
9529
  if (values.every((v) => typeof v === "string")) json.type = "string";
9374
9530
  json.enum = values;
9375
9531
  };
9532
+ const literalProcessor = (schema, ctx, json, _params) => {
9533
+ const def = schema._zod.def;
9534
+ const vals = [];
9535
+ for (const val of def.values) if (val === void 0) {
9536
+ if (ctx.unrepresentable === "throw") throw new Error("Literal `undefined` cannot be represented in JSON Schema");
9537
+ } else if (typeof val === "bigint") {
9538
+ if (ctx.unrepresentable === "throw") throw new Error("BigInt literals cannot be represented in JSON Schema");
9539
+ else vals.push(Number(val));
9540
+ } else vals.push(val);
9541
+ if (vals.length === 0) {} else if (vals.length === 1) {
9542
+ const val = vals[0];
9543
+ json.type = val === null ? "null" : typeof val;
9544
+ if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") json.enum = [val];
9545
+ else json.const = val;
9546
+ } else {
9547
+ if (vals.every((v) => typeof v === "number")) json.type = "number";
9548
+ if (vals.every((v) => typeof v === "string")) json.type = "string";
9549
+ if (vals.every((v) => typeof v === "boolean")) json.type = "boolean";
9550
+ if (vals.every((v) => v === null)) json.type = "null";
9551
+ json.enum = vals;
9552
+ }
9553
+ };
9376
9554
  const customProcessor = (_schema, ctx, _json, _params) => {
9377
9555
  if (ctx.unrepresentable === "throw") throw new Error("Custom types cannot be represented in JSON Schema");
9378
9556
  };
@@ -9455,6 +9633,39 @@ const intersectionProcessor = (schema, ctx, json, params) => {
9455
9633
  const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
9456
9634
  json.allOf = [...isSimpleIntersection(a) ? a.allOf : [a], ...isSimpleIntersection(b) ? b.allOf : [b]];
9457
9635
  };
9636
+ const recordProcessor = (schema, ctx, _json, params) => {
9637
+ const json = _json;
9638
+ const def = schema._zod.def;
9639
+ json.type = "object";
9640
+ const keyType = def.keyType;
9641
+ const patterns = keyType._zod.bag?.patterns;
9642
+ if (def.mode === "loose" && patterns && patterns.size > 0) {
9643
+ const valueSchema = process$2(def.valueType, ctx, {
9644
+ ...params,
9645
+ path: [
9646
+ ...params.path,
9647
+ "patternProperties",
9648
+ "*"
9649
+ ]
9650
+ });
9651
+ json.patternProperties = {};
9652
+ for (const pattern of patterns) json.patternProperties[pattern.source] = valueSchema;
9653
+ } else {
9654
+ if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") json.propertyNames = process$2(def.keyType, ctx, {
9655
+ ...params,
9656
+ path: [...params.path, "propertyNames"]
9657
+ });
9658
+ json.additionalProperties = process$2(def.valueType, ctx, {
9659
+ ...params,
9660
+ path: [...params.path, "additionalProperties"]
9661
+ });
9662
+ }
9663
+ const keyValues = keyType._zod.values;
9664
+ if (keyValues) {
9665
+ const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
9666
+ if (validKeyValues.length > 0) json.required = validKeyValues;
9667
+ }
9668
+ };
9458
9669
  const nullableProcessor = (schema, ctx, json, params) => {
9459
9670
  const def = schema._zod.def;
9460
9671
  const inner = process$2(def.innerType, ctx, params);
@@ -10004,6 +10215,14 @@ const ZodNumberFormat = /*@__PURE__*/ $constructor("ZodNumberFormat", (inst, def
10004
10215
  function int$1(params) {
10005
10216
  return /* @__PURE__ */ _int(ZodNumberFormat, params);
10006
10217
  }
10218
+ const ZodBoolean = /*@__PURE__*/ $constructor("ZodBoolean", (inst, def) => {
10219
+ $ZodBoolean.init(inst, def);
10220
+ ZodType.init(inst, def);
10221
+ inst._zod.processJSONSchema = (ctx, json, params) => booleanProcessor(inst, ctx, json, params);
10222
+ });
10223
+ function boolean(params) {
10224
+ return /* @__PURE__ */ _boolean(ZodBoolean, params);
10225
+ }
10007
10226
  const ZodUnknown = /*@__PURE__*/ $constructor("ZodUnknown", (inst, def) => {
10008
10227
  $ZodUnknown.init(inst, def);
10009
10228
  ZodType.init(inst, def);
@@ -10118,6 +10337,14 @@ function object(shape, params) {
10118
10337
  };
10119
10338
  return new ZodObject(def);
10120
10339
  }
10340
+ function looseObject(shape, params) {
10341
+ return new ZodObject({
10342
+ type: "object",
10343
+ shape,
10344
+ catchall: unknown(),
10345
+ ...normalizeParams(params)
10346
+ });
10347
+ }
10121
10348
  const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
10122
10349
  $ZodUnion.init(inst, def);
10123
10350
  ZodType.init(inst, def);
@@ -10143,6 +10370,27 @@ function intersection(left, right) {
10143
10370
  right
10144
10371
  });
10145
10372
  }
10373
+ const ZodRecord = /*@__PURE__*/ $constructor("ZodRecord", (inst, def) => {
10374
+ $ZodRecord.init(inst, def);
10375
+ ZodType.init(inst, def);
10376
+ inst._zod.processJSONSchema = (ctx, json, params) => recordProcessor(inst, ctx, json, params);
10377
+ inst.keyType = def.keyType;
10378
+ inst.valueType = def.valueType;
10379
+ });
10380
+ function record(keyType, valueType, params) {
10381
+ if (!valueType || !valueType._zod) return new ZodRecord({
10382
+ type: "record",
10383
+ keyType: string(),
10384
+ valueType: keyType,
10385
+ ...normalizeParams(valueType)
10386
+ });
10387
+ return new ZodRecord({
10388
+ type: "record",
10389
+ keyType,
10390
+ valueType,
10391
+ ...normalizeParams(params)
10392
+ });
10393
+ }
10146
10394
  const ZodEnum = /*@__PURE__*/ $constructor("ZodEnum", (inst, def) => {
10147
10395
  $ZodEnum.init(inst, def);
10148
10396
  ZodType.init(inst, def);
@@ -10181,6 +10429,23 @@ function _enum(values, params) {
10181
10429
  ...normalizeParams(params)
10182
10430
  });
10183
10431
  }
10432
+ const ZodLiteral = /*@__PURE__*/ $constructor("ZodLiteral", (inst, def) => {
10433
+ $ZodLiteral.init(inst, def);
10434
+ ZodType.init(inst, def);
10435
+ inst._zod.processJSONSchema = (ctx, json, params) => literalProcessor(inst, ctx, json, params);
10436
+ inst.values = new Set(def.values);
10437
+ Object.defineProperty(inst, "value", { get() {
10438
+ if (def.values.length > 1) throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");
10439
+ return def.values[0];
10440
+ } });
10441
+ });
10442
+ function literal(value, params) {
10443
+ return new ZodLiteral({
10444
+ type: "literal",
10445
+ values: Array.isArray(value) ? value : [value],
10446
+ ...normalizeParams(params)
10447
+ });
10448
+ }
10184
10449
  const ZodTransform = /*@__PURE__*/ $constructor("ZodTransform", (inst, def) => {
10185
10450
  $ZodTransform.init(inst, def);
10186
10451
  ZodType.init(inst, def);
@@ -11525,10 +11790,13 @@ async function getAccessToken() {
11525
11790
  }
11526
11791
  return credentials.accessToken;
11527
11792
  }
11528
- async function whoami() {
11529
- const response = await fetch(new URL("/api/me", env.CTX_PLATFORM_URL), { headers: { authorization: `Bearer ${await getAccessToken()}` } });
11793
+ async function getCurrentUser(headers) {
11794
+ const response = await fetch(new URL("/api/me", env.CTX_AUTH_ISSUER), { headers });
11530
11795
  if (!response.ok) throw new Error(`Identity request failed: HTTP ${response.status}`);
11531
- const user = object({ id: string().min(1) }).parse(await response.json());
11796
+ return object({ id: string().min(1) }).parse(await response.json());
11797
+ }
11798
+ async function whoami() {
11799
+ const user = await getCurrentUser({ authorization: `Bearer ${await getAccessToken()}` });
11532
11800
  console.log(user.id);
11533
11801
  }
11534
11802
  //#endregion
@@ -11542,6 +11810,6 @@ async function getLocalAppId() {
11542
11810
  return uuid().parse(new URL(remote).pathname.replace(/^\/git\//, ""));
11543
11811
  }
11544
11812
  //#endregion
11545
- export { env as a, hostname as c, url as d, uuid as f, whoami as i, object as l, getAccessToken as n, _enum as o, execa as p, login as r, array as s, getLocalAppId as t, string as u };
11813
+ export { url as _, whoami as a, array as c, literal as d, looseObject as f, unknown as g, string as h, login as i, boolean as l, record as m, getAccessToken as n, env as o, object as p, getCurrentUser as r, _enum as s, getLocalAppId as t, hostname as u, uuid as v, execa as y };
11546
11814
 
11547
- //# sourceMappingURL=app-BqaczjqV.mjs.map
11815
+ //# sourceMappingURL=app-CRgSQabE.mjs.map