@usecontextlayer/cli 0.17.0 → 0.18.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,5 +1,5 @@
1
1
  import { t as DatabaseDialect } from "./database-dialect-BLWWgYGo.mjs";
2
- import { t as openLocalDatabase } from "./local-databases-DVI3ngFq.mjs";
2
+ import { t as openLocalDatabase } from "./local-databases-BeXOeSs-.mjs";
3
3
  import { resolve } from "node:path";
4
4
  import { Kysely } from "kysely";
5
5
  import { Logger, SqliteDialect, generate } from "kysely-codegen";
@@ -21,4 +21,4 @@ async function generateDatabaseTypes(slug) {
21
21
  //#endregion
22
22
  export { generateDatabaseTypes };
23
23
 
24
- //# sourceMappingURL=database-codegen-C5TEhR5_.mjs.map
24
+ //# sourceMappingURL=database-codegen-CxDtyvam.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"database-codegen-C5TEhR5_.mjs","names":[],"sources":["../database-codegen.ts"],"sourcesContent":["import { resolve } from \"node:path\"\nimport { DatabaseDialect } from \"@usecontextlayer/shared/database-dialect\"\nimport { Kysely } from \"kysely\"\nimport { generate, Logger, SqliteDialect } from \"kysely-codegen\"\nimport { openLocalDatabase } from \"@/local-databases\"\n\nexport async function generateDatabaseTypes(slug: string) {\n\tconst db = new Kysely({ dialect: new DatabaseDialect(() => openLocalDatabase(slug)) })\n\ttry {\n\t\tawait generate({\n\t\t\tdb,\n\t\t\tdialect: new SqliteDialect(),\n\t\t\texcludePattern: \"__miniflare_do_name\",\n\t\t\tlogger: new Logger(),\n\t\t\toutFile: resolve(\"databases\", slug, \"types.ts\"),\n\t\t})\n\t} finally {\n\t\tawait db.destroy()\n\t}\n}\n"],"mappings":";;;;;;AAMA,eAAsB,sBAAsB,MAAc;CACzD,MAAM,KAAK,IAAI,OAAO,EAAE,SAAS,IAAI,sBAAsB,kBAAkB,IAAI,CAAC,EAAE,CAAC;CACrF,IAAI;EACH,MAAM,SAAS;GACd;GACA,SAAS,IAAI,cAAc;GAC3B,gBAAgB;GAChB,QAAQ,IAAI,OAAO;GACnB,SAAS,QAAQ,aAAa,MAAM,UAAU;EAC/C,CAAC;CACF,UAAU;EACT,MAAM,GAAG,QAAQ;CAClB;AACD"}
1
+ {"version":3,"file":"database-codegen-CxDtyvam.mjs","names":[],"sources":["../database-codegen.ts"],"sourcesContent":["import { resolve } from \"node:path\"\nimport { DatabaseDialect } from \"@usecontextlayer/shared/database-dialect\"\nimport { Kysely } from \"kysely\"\nimport { generate, Logger, SqliteDialect } from \"kysely-codegen\"\nimport { openLocalDatabase } from \"@/local-databases\"\n\nexport async function generateDatabaseTypes(slug: string) {\n\tconst db = new Kysely({ dialect: new DatabaseDialect(() => openLocalDatabase(slug)) })\n\ttry {\n\t\tawait generate({\n\t\t\tdb,\n\t\t\tdialect: new SqliteDialect(),\n\t\t\texcludePattern: \"__miniflare_do_name\",\n\t\t\tlogger: new Logger(),\n\t\t\toutFile: resolve(\"databases\", slug, \"types.ts\"),\n\t\t})\n\t} finally {\n\t\tawait db.destroy()\n\t}\n}\n"],"mappings":";;;;;;AAMA,eAAsB,sBAAsB,MAAc;CACzD,MAAM,KAAK,IAAI,OAAO,EAAE,SAAS,IAAI,sBAAsB,kBAAkB,IAAI,CAAC,EAAE,CAAC;CACrF,IAAI;EACH,MAAM,SAAS;GACd;GACA,SAAS,IAAI,cAAc;GAC3B,gBAAgB;GAChB,QAAQ,IAAI,OAAO;GACnB,SAAS,QAAQ,aAAa,MAAM,UAAU;EAC/C,CAAC;CACF,UAAU;EACT,MAAM,GAAG,QAAQ;CAClB;AACD"}
package/dist/database.mjs CHANGED
@@ -8,7 +8,7 @@ function databaseDialect(slug) {
8
8
  return new DatabaseDialect(async () => {
9
9
  const url = databaseEnv.CTX_DATABASE_URL;
10
10
  if (!url) {
11
- const { openLocalDatabase } = await import("./local-databases-ChvVgJH6.mjs");
11
+ const { openLocalDatabase } = await import("./local-databases-C5qUZcUH.mjs");
12
12
  return openLocalDatabase(selected);
13
13
  }
14
14
  return { async query(sql, params) {
@@ -1,4 +1,4 @@
1
- import { n as prepareLocalResourceConfiguration, t as getLocalResourcesWorkerName } from "./resources-BhJbHzU0.mjs";
1
+ import { n as prepareLocalResourceConfiguration, t as getLocalResourcesWorkerName } from "./resources-0GJALfam.mjs";
2
2
  import { n as databaseResultSchema } from "./databases-SvX3IgqC.mjs";
3
3
  import { mkdir, writeFile } from "node:fs/promises";
4
4
  import { dirname, resolve } from "node:path";
@@ -50,4 +50,4 @@ async function openLocalDatabase(slug) {
50
50
  //#endregion
51
51
  export { openLocalDatabases as n, openLocalDatabase as t };
52
52
 
53
- //# sourceMappingURL=local-databases-DVI3ngFq.mjs.map
53
+ //# sourceMappingURL=local-databases-BeXOeSs-.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"local-databases-DVI3ngFq.mjs","names":[],"sources":["../local-databases.ts"],"sourcesContent":["import { mkdir, writeFile } from \"node:fs/promises\"\nimport { dirname, resolve } from \"node:path\"\nimport type { DatabaseSession } from \"@usecontextlayer/shared/database-dialect\"\nimport { type Databases, databaseResultSchema } from \"@usecontextlayer/shared/databases\"\nimport type { LocalResourceConfiguration } from \"@usecontextlayer/shared/slate-resources\"\nimport type { PlatformProxy } from \"wrangler\"\nimport {\n\tgetLocalResourcesWorkerName,\n\tprepareLocalResourceConfiguration,\n} from \"@/resources\"\n\nexport async function openLocalDatabases(\n\tworkerName: string,\n\tdatabases: LocalResourceConfiguration[\"databases\"],\n): Promise<{ databases: Databases; dispose: PlatformProxy[\"dispose\"] }> {\n\tconst configPath = resolve(\".contextlayer/database-proxy.json\")\n\tawait mkdir(dirname(configPath), { recursive: true })\n\tawait writeFile(\n\t\tconfigPath,\n\t\tJSON.stringify({\n\t\t\tcompatibility_date: \"2026-10-02\",\n\t\t\tname: `${workerName}-database-proxy`,\n\t\t\tservices: [\n\t\t\t\t{\n\t\t\t\t\tbinding: \"DATABASES\",\n\t\t\t\t\tentrypoint: \"Databases\",\n\t\t\t\t\tprops: { databases },\n\t\t\t\t\tservice: workerName,\n\t\t\t\t},\n\t\t\t],\n\t\t}),\n\t)\n\tconst { getPlatformProxy } = await import(\"wrangler\")\n\tconst proxy = await getPlatformProxy<{ DATABASES: Fetcher }>({\n\t\tconfigPath,\n\t\tpersist: false,\n\t\tremoteBindings: false,\n\t})\n\treturn {\n\t\tdatabases: {\n\t\t\tasync query(slug, sql, params = []) {\n\t\t\t\tconst response = await proxy.env.DATABASES.fetch(\n\t\t\t\t\tnew Request(\"http://local/databases/query\", {\n\t\t\t\t\t\tbody: JSON.stringify({ params, slug, sql }),\n\t\t\t\t\t\theaders: { \"content-type\": \"application/json\" },\n\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\tif (!response.ok)\n\t\t\t\t\tthrow new Error(`Local database query failed: ${await response.text()}`)\n\t\t\t\treturn databaseResultSchema.parse(await response.json())\n\t\t\t},\n\t\t},\n\t\tdispose: proxy.dispose,\n\t}\n}\n\nexport async function openLocalDatabase(slug: string): Promise<DatabaseSession> {\n\tconst configuration = await prepareLocalResourceConfiguration()\n\tconst connection = await openLocalDatabases(\n\t\tgetLocalResourcesWorkerName(),\n\t\tconfiguration.databases,\n\t)\n\treturn {\n\t\tdestroy: connection.dispose,\n\t\tquery: (sql, params) => connection.databases.query(slug, sql, params),\n\t}\n}\n"],"mappings":";;;;;AAWA,eAAsB,mBACrB,YACA,WACuE;CACvE,MAAM,aAAa,QAAQ,mCAAmC;CAC9D,MAAM,MAAM,QAAQ,UAAU,GAAG,EAAE,WAAW,KAAK,CAAC;CACpD,MAAM,UACL,YACA,KAAK,UAAU;EACd,oBAAoB;EACpB,MAAM,GAAG,WAAW;EACpB,UAAU,CACT;GACC,SAAS;GACT,YAAY;GACZ,OAAO,EAAE,UAAU;GACnB,SAAS;EACV,CACD;CACD,CAAC,CACF;CACA,MAAM,EAAE,qBAAqB,MAAM,OAAO;CAC1C,MAAM,QAAQ,MAAM,iBAAyC;EAC5D;EACA,SAAS;EACT,gBAAgB;CACjB,CAAC;CACD,OAAO;EACN,WAAW,EACV,MAAM,MAAM,MAAM,KAAK,SAAS,CAAC,GAAG;GACnC,MAAM,WAAW,MAAM,MAAM,IAAI,UAAU,MAC1C,IAAI,QAAQ,gCAAgC;IAC3C,MAAM,KAAK,UAAU;KAAE;KAAQ;KAAM;IAAI,CAAC;IAC1C,SAAS,EAAE,gBAAgB,mBAAmB;IAC9C,QAAQ;GACT,CAAC,CACF;GACA,IAAI,CAAC,SAAS,IACb,MAAM,IAAI,MAAM,gCAAgC,MAAM,SAAS,KAAK,GAAG;GACxE,OAAO,qBAAqB,MAAM,MAAM,SAAS,KAAK,CAAC;EACxD,EACD;EACA,SAAS,MAAM;CAChB;AACD;AAEA,eAAsB,kBAAkB,MAAwC;CAC/E,MAAM,gBAAgB,MAAM,kCAAkC;CAC9D,MAAM,aAAa,MAAM,mBACxB,4BAA4B,GAC5B,cAAc,SACf;CACA,OAAO;EACN,SAAS,WAAW;EACpB,QAAQ,KAAK,WAAW,WAAW,UAAU,MAAM,MAAM,KAAK,MAAM;CACrE;AACD"}
1
+ {"version":3,"file":"local-databases-BeXOeSs-.mjs","names":[],"sources":["../local-databases.ts"],"sourcesContent":["import { mkdir, writeFile } from \"node:fs/promises\"\nimport { dirname, resolve } from \"node:path\"\nimport type { DatabaseSession } from \"@usecontextlayer/shared/database-dialect\"\nimport { type Databases, databaseResultSchema } from \"@usecontextlayer/shared/databases\"\nimport type { LocalResourceConfiguration } from \"@usecontextlayer/shared/slate-resources\"\nimport type { PlatformProxy } from \"wrangler\"\nimport {\n\tgetLocalResourcesWorkerName,\n\tprepareLocalResourceConfiguration,\n} from \"@/resources\"\n\nexport async function openLocalDatabases(\n\tworkerName: string,\n\tdatabases: LocalResourceConfiguration[\"databases\"],\n): Promise<{ databases: Databases; dispose: PlatformProxy[\"dispose\"] }> {\n\tconst configPath = resolve(\".contextlayer/database-proxy.json\")\n\tawait mkdir(dirname(configPath), { recursive: true })\n\tawait writeFile(\n\t\tconfigPath,\n\t\tJSON.stringify({\n\t\t\tcompatibility_date: \"2026-10-02\",\n\t\t\tname: `${workerName}-database-proxy`,\n\t\t\tservices: [\n\t\t\t\t{\n\t\t\t\t\tbinding: \"DATABASES\",\n\t\t\t\t\tentrypoint: \"Databases\",\n\t\t\t\t\tprops: { databases },\n\t\t\t\t\tservice: workerName,\n\t\t\t\t},\n\t\t\t],\n\t\t}),\n\t)\n\tconst { getPlatformProxy } = await import(\"wrangler\")\n\tconst proxy = await getPlatformProxy<{ DATABASES: Fetcher }>({\n\t\tconfigPath,\n\t\tpersist: false,\n\t\tremoteBindings: false,\n\t})\n\treturn {\n\t\tdatabases: {\n\t\t\tasync query(slug, sql, params = []) {\n\t\t\t\tconst response = await proxy.env.DATABASES.fetch(\n\t\t\t\t\tnew Request(\"http://local/databases/query\", {\n\t\t\t\t\t\tbody: JSON.stringify({ params, slug, sql }),\n\t\t\t\t\t\theaders: { \"content-type\": \"application/json\" },\n\t\t\t\t\t\tmethod: \"POST\",\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\tif (!response.ok)\n\t\t\t\t\tthrow new Error(`Local database query failed: ${await response.text()}`)\n\t\t\t\treturn databaseResultSchema.parse(await response.json())\n\t\t\t},\n\t\t},\n\t\tdispose: proxy.dispose,\n\t}\n}\n\nexport async function openLocalDatabase(slug: string): Promise<DatabaseSession> {\n\tconst configuration = await prepareLocalResourceConfiguration()\n\tconst connection = await openLocalDatabases(\n\t\tgetLocalResourcesWorkerName(),\n\t\tconfiguration.databases,\n\t)\n\treturn {\n\t\tdestroy: connection.dispose,\n\t\tquery: (sql, params) => connection.databases.query(slug, sql, params),\n\t}\n}\n"],"mappings":";;;;;AAWA,eAAsB,mBACrB,YACA,WACuE;CACvE,MAAM,aAAa,QAAQ,mCAAmC;CAC9D,MAAM,MAAM,QAAQ,UAAU,GAAG,EAAE,WAAW,KAAK,CAAC;CACpD,MAAM,UACL,YACA,KAAK,UAAU;EACd,oBAAoB;EACpB,MAAM,GAAG,WAAW;EACpB,UAAU,CACT;GACC,SAAS;GACT,YAAY;GACZ,OAAO,EAAE,UAAU;GACnB,SAAS;EACV,CACD;CACD,CAAC,CACF;CACA,MAAM,EAAE,qBAAqB,MAAM,OAAO;CAC1C,MAAM,QAAQ,MAAM,iBAAyC;EAC5D;EACA,SAAS;EACT,gBAAgB;CACjB,CAAC;CACD,OAAO;EACN,WAAW,EACV,MAAM,MAAM,MAAM,KAAK,SAAS,CAAC,GAAG;GACnC,MAAM,WAAW,MAAM,MAAM,IAAI,UAAU,MAC1C,IAAI,QAAQ,gCAAgC;IAC3C,MAAM,KAAK,UAAU;KAAE;KAAQ;KAAM;IAAI,CAAC;IAC1C,SAAS,EAAE,gBAAgB,mBAAmB;IAC9C,QAAQ;GACT,CAAC,CACF;GACA,IAAI,CAAC,SAAS,IACb,MAAM,IAAI,MAAM,gCAAgC,MAAM,SAAS,KAAK,GAAG;GACxE,OAAO,qBAAqB,MAAM,MAAM,SAAS,KAAK,CAAC;EACxD,EACD;EACA,SAAS,MAAM;CAChB;AACD;AAEA,eAAsB,kBAAkB,MAAwC;CAC/E,MAAM,gBAAgB,MAAM,kCAAkC;CAC9D,MAAM,aAAa,MAAM,mBACxB,4BAA4B,GAC5B,cAAc,SACf;CACA,OAAO;EACN,SAAS,WAAW;EACpB,QAAQ,KAAK,WAAW,WAAW,UAAU,MAAM,MAAM,KAAK,MAAM;CACrE;AACD"}
@@ -1 +1 @@
1
- export { t as openLocalDatabase, n as openLocalDatabases } from "./local-databases-DVI3ngFq.mjs";
1
+ export { t as openLocalDatabase, n as openLocalDatabases } from "./local-databases-BeXOeSs-.mjs";
@@ -6369,7 +6369,7 @@ object({
6369
6369
  const noCommitSchema = object({ reason: literal("no-commit") });
6370
6370
  const slateResourceConfigurationSchema = resourcesSchema.extend({
6371
6371
  connections: record(resourcesSchema.shape.connections.keyType, resourcesSchema.shape.connections.valueType.extend({
6372
- connection_id: string().nullable(),
6372
+ account_id: string().nullable(),
6373
6373
  owner: ownerSchema
6374
6374
  })),
6375
6375
  databases: record(resourcesSchema.shape.databases.keyType, resourcesSchema.shape.databases.valueType.extend({
@@ -6387,7 +6387,7 @@ const slateResourceConfigurationSchema = resourcesSchema.extend({
6387
6387
  });
6388
6388
  object({ resources: slateResourceConfigurationSchema });
6389
6389
  const localResourceConfigurationSchema = resourcesSchema.extend({
6390
- connections: record(resourcesSchema.shape.connections.keyType, resourcesSchema.shape.connections.valueType.extend({ connection_id: string().min(1).nullable() })),
6390
+ connections: record(resourcesSchema.shape.connections.keyType, resourcesSchema.shape.connections.valueType.extend({ account_id: string().min(1).nullable() })),
6391
6391
  databases: record(resourcesSchema.shape.databases.keyType, resourcesSchema.shape.databases.valueType.extend({ instance_name: string().min(1) })),
6392
6392
  secrets: record(resourcesSchema.shape.secrets.keyType, resourcesSchema.shape.secrets.valueType.extend({ value: string().nullable() }))
6393
6393
  });
@@ -6440,7 +6440,7 @@ async function prepareLocalResourceConfiguration(directory = process.cwd()) {
6440
6440
  return localResourceConfigurationSchema.parse({
6441
6441
  connections: Object.fromEntries(Object.entries(resources.connections).map(([slug, requirement]) => [slug, {
6442
6442
  ...requirement,
6443
- connection_id: assignments.get(slug) ?? null
6443
+ account_id: assignments.get(slug) ?? null
6444
6444
  }])),
6445
6445
  databases: Object.fromEntries(Object.entries(resources.databases).map(([slug, requirement]) => [slug, {
6446
6446
  ...requirement,
@@ -6452,8 +6452,8 @@ async function prepareLocalResourceConfiguration(directory = process.cwd()) {
6452
6452
  }]))
6453
6453
  });
6454
6454
  }
6455
- async function saveLocalConnection(slug, connectionId, directory = process.cwd()) {
6456
- const assignment = localConnectionsSchema.parse({ [slug]: connectionId });
6455
+ async function saveLocalConnection(slug, accountId, directory = process.cwd()) {
6456
+ const assignment = localConnectionsSchema.parse({ [slug]: accountId });
6457
6457
  const connections = {
6458
6458
  ...await readLocalConnections(directory),
6459
6459
  ...assignment
@@ -6464,4 +6464,4 @@ async function saveLocalConnection(slug, connectionId, directory = process.cwd()
6464
6464
  //#endregion
6465
6465
  export { noCommitSchema as a, execa as c, getLocalSlateId as i, prepareLocalResourceConfiguration as n, slateResourceConfigurationSchema as o, saveLocalConnection as r, ownerSchema as s, getLocalResourcesWorkerName as t };
6466
6466
 
6467
- //# sourceMappingURL=resources-BhJbHzU0.mjs.map
6467
+ //# sourceMappingURL=resources-0GJALfam.mjs.map