instant-cli 1.0.55 → 1.0.56

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,4 +1,4 @@
1
1
 
2
- > instant-cli@1.0.55 build /home/runner/work/instant/instant/client/packages/cli
2
+ > instant-cli@1.0.56 build /home/runner/work/instant/instant/client/packages/cli
3
3
  > rm -rf dist; tsc -p tsconfig.build.json
4
4
 
@@ -2,5 +2,5 @@ import { Effect } from 'effect';
2
2
  import { explorerDef } from '../index.ts';
3
3
  import type { OptsFromCommand } from '../index.ts';
4
4
  import { CurrentApp } from '../context/currentApp.ts';
5
- export declare const explorerCmd: (_opts: OptsFromCommand<typeof explorerDef>) => Effect.Effect<void, import("effect/ConfigError").ConfigError, CurrentApp>;
5
+ export declare const explorerCmd: (_opts: OptsFromCommand<typeof explorerDef>) => Effect.Effect<void, import("../errors.ts").BadArgsError | import("effect/Cause").UnknownException | import("effect/ConfigError").ConfigError, CurrentApp>;
6
6
  //# sourceMappingURL=explorer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"explorer.d.ts","sourceRoot":"","sources":["../../src/commands/explorer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGtD,eAAO,MAAM,WAAW,GAAI,OAAO,eAAe,CAAC,OAAO,WAAW,CAAC,8EAalE,CAAC"}
1
+ {"version":3,"file":"explorer.d.ts","sourceRoot":"","sources":["../../src/commands/explorer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGtD,eAAO,MAAM,WAAW,GAAI,OAAO,eAAe,CAAC,OAAO,WAAW,CAAC,8JAalE,CAAC"}
@@ -5,5 +5,5 @@ export declare const loginCommand: (opts: {
5
5
  }) => Effect.Effect<{
6
6
  authToken: string;
7
7
  source: "file";
8
- }, import("effect/Cause").UnknownException | import("../lib/http.ts").InstantHttpError | import("effect/Cause").TimeoutException | import("@effect/platform/HttpClientError").RequestError | import("effect/ParseResult").ParseError | import("@effect/platform/HttpClientError").ResponseError | import("@effect/platform/Error").PlatformError | import("effect/ConfigError").ConfigError, import("../context/globalOpts.ts").GlobalOpts | import("../lib/http.ts").InstantHttp | import("@effect/platform/FileSystem").FileSystem>;
8
+ }, import("../errors.ts").BadArgsError | import("effect/Cause").UnknownException | import("../lib/http.ts").InstantHttpError | import("effect/Cause").TimeoutException | import("@effect/platform/HttpClientError").RequestError | import("effect/ParseResult").ParseError | import("@effect/platform/HttpClientError").ResponseError | import("@effect/platform/Error").PlatformError | import("effect/ConfigError").ConfigError, import("../context/globalOpts.ts").GlobalOpts | import("../lib/http.ts").InstantHttp | import("@effect/platform/FileSystem").FileSystem>;
9
9
  //# sourceMappingURL=login.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAgBhC,eAAO,MAAM,YAAY;;;;;;qgBA4CvB,CAAC"}
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAgBhC,eAAO,MAAM,YAAY;;;;;;2iBA4CvB,CAAC"}
@@ -25,6 +25,6 @@ export declare const authTokenGetEffect: (allowAdminToken?: boolean) => Effect.E
25
25
  export declare const AuthTokenLive: ({ coerce, allowAdminToken, }: {
26
26
  coerce: boolean;
27
27
  allowAdminToken: boolean;
28
- }) => Layer.Layer<AuthToken, import("effect/Cause").UnknownException | import("../lib/http.ts").InstantHttpError | import("effect/Cause").TimeoutException | import("@effect/platform/HttpClientError").RequestError | import("effect/ParseResult").ParseError | import("@effect/platform/HttpClientError").ResponseError | import("@effect/platform/Error").PlatformError | import("effect/ConfigError").ConfigError | NotAuthedError, import("./globalOpts.ts").GlobalOpts | import("../lib/http.ts").InstantHttp | FileSystem.FileSystem>;
28
+ }) => Layer.Layer<AuthToken, import("../errors.ts").BadArgsError | import("effect/Cause").UnknownException | import("../lib/http.ts").InstantHttpError | import("effect/Cause").TimeoutException | import("@effect/platform/HttpClientError").RequestError | import("effect/ParseResult").ParseError | import("@effect/platform/HttpClientError").ResponseError | import("@effect/platform/Error").PlatformError | import("effect/ConfigError").ConfigError | NotAuthedError, import("./globalOpts.ts").GlobalOpts | import("../lib/http.ts").InstantHttp | FileSystem.FileSystem>;
29
29
  export {};
30
30
  //# sourceMappingURL=authToken.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authToken.d.ts","sourceRoot":"","sources":["../../src/context/authToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAU,OAAO,EAAE,MAAM,EAAE,KAAK,EAAe,MAAM,EAAE,MAAM,QAAQ,CAAC;AAM7E,KAAK,eAAe,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;;kBAUtC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;eACxB,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC;kBAC3B,CACZ,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,eAAe,KACrB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;;AAR5B,qBAAa,SAAU,SAAQ,cAU5B;CAAG;;;;;;AAEN,qBAAa,cAAe,SAAQ,mBAIlC;CAAG;AAEL,eAAO,MAAM,kBAAkB,GAAI,kBAAiB,OAAc;;YAMzC,KAAK,GAAG,KAAK,GAAG,MAAM;;;YAwBpB,OAAO;oFAoB9B,CAAC;AAEL,eAAO,MAAM,aAAa,GAAI,8BAG3B;IACD,MAAM,EAAE,OAAO,CAAC;IAChB,eAAe,EAAE,OAAO,CAAC;CAC1B,2gBAgDE,CAAC"}
1
+ {"version":3,"file":"authToken.d.ts","sourceRoot":"","sources":["../../src/context/authToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAU,OAAO,EAAE,MAAM,EAAE,KAAK,EAAe,MAAM,EAAE,MAAM,QAAQ,CAAC;AAM7E,KAAK,eAAe,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;;kBAUtC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;eACxB,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC;kBAC3B,CACZ,SAAS,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,eAAe,KACrB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;;AAR5B,qBAAa,SAAU,SAAQ,cAU5B;CAAG;;;;;;AAEN,qBAAa,cAAe,SAAQ,mBAIlC;CAAG;AAEL,eAAO,MAAM,kBAAkB,GAAI,kBAAiB,OAAc;;YAMzC,KAAK,GAAG,KAAK,GAAG,MAAM;;;YAwBpB,OAAO;oFAoB9B,CAAC;AAEL,eAAO,MAAM,aAAa,GAAI,8BAG3B;IACD,MAAM,EAAE,OAAO,CAAC;IAChB,eAAe,EAAE,OAAO,CAAC;CAC1B,ijBAgDE,CAAC"}
@@ -3,5 +3,5 @@ import type { CurrentAppInfo } from '../context/currentApp.ts';
3
3
  import { ProjectInfo } from '../context/projectInfo.ts';
4
4
  import { GlobalOpts } from '../context/globalOpts.ts';
5
5
  import { FileSystem, Path } from '@effect/platform';
6
- export declare const handleEnv: (app: CurrentAppInfo) => Effect.Effect<void, import("effect/Cause").UnknownException | import("@effect/platform/Error").PlatformError | import("effect/ConfigError").ConfigError, GlobalOpts | ProjectInfo | FileSystem.FileSystem | Path.Path>;
6
+ export declare const handleEnv: (app: CurrentAppInfo) => Effect.Effect<void, import("../errors.ts").BadArgsError | import("effect/Cause").UnknownException | import("@effect/platform/Error").PlatformError | import("effect/ConfigError").ConfigError, GlobalOpts | ProjectInfo | FileSystem.FileSystem | Path.Path>;
7
7
  //# sourceMappingURL=handleEnv.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handleEnv.d.ts","sourceRoot":"","sources":["../../src/lib/handleEnv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAoB,MAAM,2BAA2B,CAAC;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAOpD,eAAO,MAAM,SAAS,iPAuDpB,CAAC"}
1
+ {"version":3,"file":"handleEnv.d.ts","sourceRoot":"","sources":["../../src/lib/handleEnv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAoB,MAAM,2BAA2B,CAAC;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAOpD,eAAO,MAAM,SAAS,uRAuDpB,CAAC"}
@@ -28,6 +28,6 @@ declare class InstantTypicalHttpErrorResponse extends InstantTypicalHttpErrorRes
28
28
  export declare const InstantHttpLive: Layer.Layer<InstantHttp, BadArgsError | import("effect/Cause").UnknownException | import("effect/ConfigError").ConfigError, HttpClient.HttpClient>;
29
29
  export declare const InstantHttpAuthedLive: Layer.Layer<InstantHttpAuthed, never, InstantHttp | AuthToken>;
30
30
  export declare const getBaseUrl: Effect.Effect<string, BadArgsError | import("effect/Cause").UnknownException | import("effect/ConfigError").ConfigError, never>;
31
- export declare const getDashUrl: Effect.Effect<string, import("effect/ConfigError").ConfigError, never>;
31
+ export declare const getDashUrl: Effect.Effect<string, BadArgsError | import("effect/Cause").UnknownException | import("effect/ConfigError").ConfigError, never>;
32
32
  export {};
33
33
  //# sourceMappingURL=http.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/lib/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,kBAAkB,CAAC;AAEjE,OAAO,EAAU,OAAO,EAAQ,MAAM,EAAE,KAAK,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;;AAE5C,qBAAa,WAAY,SAAQ,gBAK9B;CAAG;;AAEN,qBAAa,iBAAkB,SAAQ,sBAKpC;CAAG;;;;AAEN,qBAAa,gBAAiB,SAAQ,sBACpC;IACE,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,+BAA+B,CAAC,IAAI,CAChD;CAAG;AAGJ,eAAO,MAAM,WAAW,GAAI,SAAS,MAAM,MAEvC,QAAQ,UAAU,CAAC,UAAU,CAAC,IAAI,CAChC,gBAAgB,GAAG,gBAAgB,GAAG,YAAY,CACnD,0FAOJ,CAAC;;;;;;AAEF,cAAM,+BAAgC,SAAQ,oCAM5C;CAAG;AAWL,eAAO,MAAM,eAAe,oJAwD3B,CAAC;AAEF,eAAO,MAAM,qBAAqB,gEAiBjC,CAAC;AAEF,eAAO,MAAM,UAAU,iIA0BrB,CAAC;AAEH,eAAO,MAAM,UAAU,wEAYrB,CAAC"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/lib/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,kBAAkB,CAAC;AAEjE,OAAO,EAAU,OAAO,EAAQ,MAAM,EAAE,KAAK,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;;AAE5C,qBAAa,WAAY,SAAQ,gBAK9B;CAAG;;AAEN,qBAAa,iBAAkB,SAAQ,sBAKpC;CAAG;;;;AAEN,qBAAa,gBAAiB,SAAQ,sBACpC;IACE,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,+BAA+B,CAAC,IAAI,CAChD;CAAG;AAGJ,eAAO,MAAM,WAAW,GAAI,SAAS,MAAM,MAEvC,QAAQ,UAAU,CAAC,UAAU,CAAC,IAAI,CAChC,gBAAgB,GAAG,gBAAgB,GAAG,YAAY,CACnD,0FAOJ,CAAC;;;;;;AAEF,cAAM,+BAAgC,SAAQ,oCAM5C;CAAG;AAWL,eAAO,MAAM,eAAe,oJAwD3B,CAAC;AAEF,eAAO,MAAM,qBAAqB,gEAiBjC,CAAC;AAEF,eAAO,MAAM,UAAU,iIA0BrB,CAAC;AAEH,eAAO,MAAM,UAAU,iIA0BrB,CAAC"}
package/dist/lib/http.js CHANGED
@@ -72,10 +72,17 @@ export const getBaseUrl = Effect.gen(function* () {
72
72
  });
73
73
  export const getDashUrl = Effect.gen(function* () {
74
74
  const setEnv = yield* Config.string('INSTANT_CLI_DASH_URI').pipe(Config.option);
75
- const dev = Option.getOrNull(yield* Config.boolean('INSTANT_CLI_DEV').pipe(Config.option));
76
- return Option.match(setEnv, {
77
- onSome: (url) => url,
78
- onNone: () => (dev ? 'http://localhost:3000' : 'https://instantdb.com'),
79
- });
75
+ const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(Config.withDefault(false));
76
+ if (Option.isSome(setEnv)) {
77
+ return setEnv.value;
78
+ }
79
+ const instantConfig = yield* Effect.tryPromise(readInstantConfigFile);
80
+ if (instantConfig?.dashURI !== undefined) {
81
+ yield* Schema.decodeUnknown(HttpUrl)(instantConfig.dashURI).pipe(Effect.mapError(() => BadArgsError.make({
82
+ message: 'Invalid dashURI in instant.config.ts. Expected a valid HTTP(S) URL.',
83
+ })));
84
+ return instantConfig.dashURI;
85
+ }
86
+ return dev ? 'http://localhost:3000' : 'https://instantdb.com';
80
87
  });
81
88
  //# sourceMappingURL=http.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/lib/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,OAAO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AM,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,uBAAuB,CAAC;KACxE,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { HttpClient, HttpClientRequest } from '@effect/platform';\nimport { version } from '@instantdb/version';\nimport { Config, Context, Data, Effect, Layer, Option, Schema } from 'effect';\nimport { AuthToken } from '../context/authToken.ts';\nimport { TimeoutException } from 'effect/Cause';\nimport { RequestError } from '@effect/platform/HttpClientError';\nimport { readInstantConfigFile } from '../util/instantConfig.ts';\nimport { BadArgsError } from '../errors.ts';\n\nexport class InstantHttp extends Context.Tag(\n 'instant-cli/new/lib/http/InstantHttp',\n)<\n InstantHttp,\n HttpClient.HttpClient.With<InstantHttpError | TimeoutException | RequestError>\n>() {}\n\nexport class InstantHttpAuthed extends Context.Tag(\n 'instant-cli/new/lib/http/InstantHttpAuthed',\n)<\n InstantHttpAuthed,\n HttpClient.HttpClient.With<InstantHttpError | TimeoutException | RequestError>\n>() {}\n\nexport class InstantHttpError extends Data.TaggedError('InstantHttpError')<\n {\n methodAndUrl: string;\n } & typeof InstantTypicalHttpErrorResponse.Type\n> {}\n\n// Pipe on an http client to set the command header\nexport const withCommand = (command: string) => {\n return (\n client: HttpClient.HttpClient.With<\n InstantHttpError | TimeoutException | RequestError\n >,\n ) =>\n client.pipe(\n HttpClient.mapRequest((r) =>\n r.pipe(HttpClientRequest.setHeader(`X-Instant-Command`, command)),\n ),\n );\n};\n\nclass InstantTypicalHttpErrorResponse extends Schema.Struct({\n message: Schema.String,\n type: Schema.String.pipe(Schema.optional),\n hint: Schema.Record({ key: Schema.String, value: Schema.Any }).pipe(\n Schema.optional,\n ),\n}) {}\n\nconst HttpUrl = Schema.URL.pipe(\n Schema.filter(\n (url) =>\n url.protocol === 'http:' ||\n url.protocol === 'https:' ||\n 'Expected an HTTP(S) URL',\n ),\n);\n\nexport const InstantHttpLive = Layer.effect(\n InstantHttp,\n Effect.gen(function* () {\n const client = yield* HttpClient.HttpClient;\n const baseUrl = yield* getBaseUrl;\n return client.pipe(\n HttpClient.mapRequest((r) =>\n r.pipe(\n HttpClientRequest.prependUrl(baseUrl),\n HttpClientRequest.setHeader('X-Instant-Source', 'instant-cli'),\n HttpClientRequest.setHeader('X-Instant-Version', version),\n ),\n ),\n HttpClient.transformResponse((r) => r.pipe(Effect.timeout('5 minutes'))),\n HttpClient.filterStatusOk, // makes non 2xx http codes error\n // parses the non 2xx errors into known instant error shape\n HttpClient.transformResponse((r) =>\n r.pipe(\n Effect.catchTag('ResponseError', (requestError) =>\n Effect.gen(function* () {\n const jsonBody = yield* requestError.response.json.pipe(\n Effect.andThen(\n Schema.decodeUnknown(InstantTypicalHttpErrorResponse),\n ),\n Effect.mapError(\n (e) =>\n new InstantHttpError({\n message:\n 'Error making request to ' + requestError.methodAndUrl,\n type: e._tag,\n methodAndUrl: requestError.methodAndUrl,\n }),\n ),\n );\n\n // The hint.message is usually better error message\n let message = jsonBody.message;\n if (\n jsonBody.hint?.message &&\n typeof jsonBody.hint.message === 'string'\n ) {\n message = jsonBody.hint.message;\n }\n\n return yield* new InstantHttpError({\n message: message,\n methodAndUrl: requestError.methodAndUrl,\n hint: jsonBody.hint,\n type: jsonBody.type || 'Unknown type',\n });\n }),\n ),\n ),\n ),\n );\n }),\n);\n\nexport const InstantHttpAuthedLive = Layer.effect(\n InstantHttpAuthed,\n Effect.gen(function* () {\n const http = yield* InstantHttp;\n const authToken = yield* AuthToken;\n return http.pipe(\n HttpClient.mapRequestEffect((r) =>\n authToken.getAuthToken.pipe(\n Effect.map((token) =>\n r.pipe(\n HttpClientRequest.setHeader('Authorization', `Bearer ${token}`),\n ),\n ),\n ),\n ),\n );\n }),\n);\n\nexport const getBaseUrl = Effect.gen(function* () {\n const setEnv = yield* Config.string('INSTANT_CLI_API_URI').pipe(\n Config.option,\n );\n const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(\n Config.withDefault(false),\n );\n\n if (Option.isSome(setEnv)) {\n return setEnv.value;\n }\n\n const instantConfig = yield* Effect.tryPromise(readInstantConfigFile);\n if (instantConfig?.apiURI !== undefined) {\n yield* Schema.decodeUnknown(HttpUrl)(instantConfig.apiURI).pipe(\n Effect.mapError(() =>\n BadArgsError.make({\n message:\n 'Invalid apiURI in instant.config.ts. Expected a valid HTTP(S) URL.',\n }),\n ),\n );\n return instantConfig.apiURI;\n }\n\n return dev ? 'http://localhost:8888' : 'https://api.instantdb.com';\n});\n\nexport const getDashUrl = Effect.gen(function* () {\n const setEnv = yield* Config.string('INSTANT_CLI_DASH_URI').pipe(\n Config.option,\n );\n const dev = Option.getOrNull(\n yield* Config.boolean('INSTANT_CLI_DEV').pipe(Config.option),\n );\n\n return Option.match(setEnv, {\n onSome: (url) => url,\n onNone: () => (dev ? 'http://localhost:3000' : 'https://instantdb.com'),\n });\n});\n"]}
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/lib/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,OAAO,WAAY,SAAQ,OAAO,CAAC,GAAG,CAC1C,sCAAsC,CACvC,EAGE;CAAG;AAEN,MAAM,OAAO,iBAAkB,SAAQ,OA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AK,SAAS,EAAE,CAAC;QACzC,KAAK,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,CAC9D,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,CACnB,YAAY,CAAC,IAAI,CAAC;YAChB,OAAO,EACL,qEAAqE;SACxE,CAAC,CACH,CACF,CAAC;QACF,OAAO,aAAa,CAAC,OAAO,CAAC;IAC/B,CAAC;IAED,OAAO,GAAG,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,uBAAuB,CAAC;AACjE,CAAC,CAAC,CAAC","sourcesContent":["import { HttpClient, HttpClientRequest } from '@effect/platform';\nimport { version } from '@instantdb/version';\nimport { Config, Context, Data, Effect, Layer, Option, Schema } from 'effect';\nimport { AuthToken } from '../context/authToken.ts';\nimport { TimeoutException } from 'effect/Cause';\nimport { RequestError } from '@effect/platform/HttpClientError';\nimport { readInstantConfigFile } from '../util/instantConfig.ts';\nimport { BadArgsError } from '../errors.ts';\n\nexport class InstantHttp extends Context.Tag(\n 'instant-cli/new/lib/http/InstantHttp',\n)<\n InstantHttp,\n HttpClient.HttpClient.With<InstantHttpError | TimeoutException | RequestError>\n>() {}\n\nexport class InstantHttpAuthed extends Context.Tag(\n 'instant-cli/new/lib/http/InstantHttpAuthed',\n)<\n InstantHttpAuthed,\n HttpClient.HttpClient.With<InstantHttpError | TimeoutException | RequestError>\n>() {}\n\nexport class InstantHttpError extends Data.TaggedError('InstantHttpError')<\n {\n methodAndUrl: string;\n } & typeof InstantTypicalHttpErrorResponse.Type\n> {}\n\n// Pipe on an http client to set the command header\nexport const withCommand = (command: string) => {\n return (\n client: HttpClient.HttpClient.With<\n InstantHttpError | TimeoutException | RequestError\n >,\n ) =>\n client.pipe(\n HttpClient.mapRequest((r) =>\n r.pipe(HttpClientRequest.setHeader(`X-Instant-Command`, command)),\n ),\n );\n};\n\nclass InstantTypicalHttpErrorResponse extends Schema.Struct({\n message: Schema.String,\n type: Schema.String.pipe(Schema.optional),\n hint: Schema.Record({ key: Schema.String, value: Schema.Any }).pipe(\n Schema.optional,\n ),\n}) {}\n\nconst HttpUrl = Schema.URL.pipe(\n Schema.filter(\n (url) =>\n url.protocol === 'http:' ||\n url.protocol === 'https:' ||\n 'Expected an HTTP(S) URL',\n ),\n);\n\nexport const InstantHttpLive = Layer.effect(\n InstantHttp,\n Effect.gen(function* () {\n const client = yield* HttpClient.HttpClient;\n const baseUrl = yield* getBaseUrl;\n return client.pipe(\n HttpClient.mapRequest((r) =>\n r.pipe(\n HttpClientRequest.prependUrl(baseUrl),\n HttpClientRequest.setHeader('X-Instant-Source', 'instant-cli'),\n HttpClientRequest.setHeader('X-Instant-Version', version),\n ),\n ),\n HttpClient.transformResponse((r) => r.pipe(Effect.timeout('5 minutes'))),\n HttpClient.filterStatusOk, // makes non 2xx http codes error\n // parses the non 2xx errors into known instant error shape\n HttpClient.transformResponse((r) =>\n r.pipe(\n Effect.catchTag('ResponseError', (requestError) =>\n Effect.gen(function* () {\n const jsonBody = yield* requestError.response.json.pipe(\n Effect.andThen(\n Schema.decodeUnknown(InstantTypicalHttpErrorResponse),\n ),\n Effect.mapError(\n (e) =>\n new InstantHttpError({\n message:\n 'Error making request to ' + requestError.methodAndUrl,\n type: e._tag,\n methodAndUrl: requestError.methodAndUrl,\n }),\n ),\n );\n\n // The hint.message is usually better error message\n let message = jsonBody.message;\n if (\n jsonBody.hint?.message &&\n typeof jsonBody.hint.message === 'string'\n ) {\n message = jsonBody.hint.message;\n }\n\n return yield* new InstantHttpError({\n message: message,\n methodAndUrl: requestError.methodAndUrl,\n hint: jsonBody.hint,\n type: jsonBody.type || 'Unknown type',\n });\n }),\n ),\n ),\n ),\n );\n }),\n);\n\nexport const InstantHttpAuthedLive = Layer.effect(\n InstantHttpAuthed,\n Effect.gen(function* () {\n const http = yield* InstantHttp;\n const authToken = yield* AuthToken;\n return http.pipe(\n HttpClient.mapRequestEffect((r) =>\n authToken.getAuthToken.pipe(\n Effect.map((token) =>\n r.pipe(\n HttpClientRequest.setHeader('Authorization', `Bearer ${token}`),\n ),\n ),\n ),\n ),\n );\n }),\n);\n\nexport const getBaseUrl = Effect.gen(function* () {\n const setEnv = yield* Config.string('INSTANT_CLI_API_URI').pipe(\n Config.option,\n );\n const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(\n Config.withDefault(false),\n );\n\n if (Option.isSome(setEnv)) {\n return setEnv.value;\n }\n\n const instantConfig = yield* Effect.tryPromise(readInstantConfigFile);\n if (instantConfig?.apiURI !== undefined) {\n yield* Schema.decodeUnknown(HttpUrl)(instantConfig.apiURI).pipe(\n Effect.mapError(() =>\n BadArgsError.make({\n message:\n 'Invalid apiURI in instant.config.ts. Expected a valid HTTP(S) URL.',\n }),\n ),\n );\n return instantConfig.apiURI;\n }\n\n return dev ? 'http://localhost:8888' : 'https://api.instantdb.com';\n});\n\nexport const getDashUrl = Effect.gen(function* () {\n const setEnv = yield* Config.string('INSTANT_CLI_DASH_URI').pipe(\n Config.option,\n );\n const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(\n Config.withDefault(false),\n );\n\n if (Option.isSome(setEnv)) {\n return setEnv.value;\n }\n\n const instantConfig = yield* Effect.tryPromise(readInstantConfigFile);\n if (instantConfig?.dashURI !== undefined) {\n yield* Schema.decodeUnknown(HttpUrl)(instantConfig.dashURI).pipe(\n Effect.mapError(() =>\n BadArgsError.make({\n message:\n 'Invalid dashURI in instant.config.ts. Expected a valid HTTP(S) URL.',\n }),\n ),\n );\n return instantConfig.dashURI;\n }\n\n return dev ? 'http://localhost:3000' : 'https://instantdb.com';\n});\n"]}
@@ -1,5 +1,6 @@
1
1
  export type InstantConfig = {
2
2
  apiURI?: string;
3
+ dashURI?: string;
3
4
  apps?: Record<string, {
4
5
  id: string;
5
6
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"instantConfig.d.ts","sourceRoot":"","sources":["../../src/util/instantConfig.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACvC,CAAC;AAEF,wBAAsB,qBAAqB,2BAY1C"}
1
+ {"version":3,"file":"instantConfig.d.ts","sourceRoot":"","sources":["../../src/util/instantConfig.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACvC,CAAC;AAEF,wBAAsB,qBAAqB,2BAY1C"}
@@ -1 +1 @@
1
- {"version":3,"file":"instantConfig.js","sourceRoot":"","sources":["../../src/util/instantConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAO7C,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACzC,OAAO,CACL,MAAM,UAAU,CAAgB;QAC9B,OAAO,EAAE;YACP;gBACE,KAAK,EAAE,gBAAgB;gBACvB,UAAU,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC;aAC7D;SACF;QACD,KAAK,EAAE,KAAK;KACb,CAAC,CACH,CAAC,MAAM,CAAC;AACX,CAAC","sourcesContent":["import { loadConfig } from './loadConfig.ts';\n\nexport type InstantConfig = {\n apiURI?: string;\n apps?: Record<string, { id: string }>;\n};\n\nexport async function readInstantConfigFile() {\n return (\n await loadConfig<InstantConfig>({\n sources: [\n {\n files: 'instant.config',\n extensions: ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs', 'json'],\n },\n ],\n merge: false,\n })\n ).config;\n}\n"]}
1
+ {"version":3,"file":"instantConfig.js","sourceRoot":"","sources":["../../src/util/instantConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAQ7C,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACzC,OAAO,CACL,MAAM,UAAU,CAAgB;QAC9B,OAAO,EAAE;YACP;gBACE,KAAK,EAAE,gBAAgB;gBACvB,UAAU,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC;aAC7D;SACF;QACD,KAAK,EAAE,KAAK;KACb,CAAC,CACH,CAAC,MAAM,CAAC;AACX,CAAC","sourcesContent":["import { loadConfig } from './loadConfig.ts';\n\nexport type InstantConfig = {\n apiURI?: string;\n dashURI?: string;\n apps?: Record<string, { id: string }>;\n};\n\nexport async function readInstantConfigFile() {\n return (\n await loadConfig<InstantConfig>({\n sources: [\n {\n files: 'instant.config',\n extensions: ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs', 'json'],\n },\n ],\n merge: false,\n })\n ).config;\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "instant-cli",
3
3
  "type": "module",
4
- "version": "1.0.55",
4
+ "version": "1.0.56",
5
5
  "description": "Instant's CLI",
6
6
  "license": "Apache-2.0",
7
7
  "homepage": "https://github.com/instantdb/instant/tree/main/client/packages/cli",
@@ -50,9 +50,9 @@
50
50
  "strip-ansi": "^7.1.2",
51
51
  "supports-hyperlinks": "^4.4.0",
52
52
  "unconfig": "^7.5.0",
53
- "@instantdb/core": "1.0.55",
54
- "@instantdb/platform": "1.0.55",
55
- "@instantdb/version": "1.0.55"
53
+ "@instantdb/core": "1.0.56",
54
+ "@instantdb/platform": "1.0.56",
55
+ "@instantdb/version": "1.0.56"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@babel/core": "^7.17.9",
package/src/lib/http.ts CHANGED
@@ -167,12 +167,26 @@ export const getDashUrl = Effect.gen(function* () {
167
167
  const setEnv = yield* Config.string('INSTANT_CLI_DASH_URI').pipe(
168
168
  Config.option,
169
169
  );
170
- const dev = Option.getOrNull(
171
- yield* Config.boolean('INSTANT_CLI_DEV').pipe(Config.option),
170
+ const dev = yield* Config.boolean('INSTANT_CLI_DEV').pipe(
171
+ Config.withDefault(false),
172
172
  );
173
173
 
174
- return Option.match(setEnv, {
175
- onSome: (url) => url,
176
- onNone: () => (dev ? 'http://localhost:3000' : 'https://instantdb.com'),
177
- });
174
+ if (Option.isSome(setEnv)) {
175
+ return setEnv.value;
176
+ }
177
+
178
+ const instantConfig = yield* Effect.tryPromise(readInstantConfigFile);
179
+ if (instantConfig?.dashURI !== undefined) {
180
+ yield* Schema.decodeUnknown(HttpUrl)(instantConfig.dashURI).pipe(
181
+ Effect.mapError(() =>
182
+ BadArgsError.make({
183
+ message:
184
+ 'Invalid dashURI in instant.config.ts. Expected a valid HTTP(S) URL.',
185
+ }),
186
+ ),
187
+ );
188
+ return instantConfig.dashURI;
189
+ }
190
+
191
+ return dev ? 'http://localhost:3000' : 'https://instantdb.com';
178
192
  });
@@ -2,6 +2,7 @@ import { loadConfig } from './loadConfig.ts';
2
2
 
3
3
  export type InstantConfig = {
4
4
  apiURI?: string;
5
+ dashURI?: string;
5
6
  apps?: Record<string, { id: string }>;
6
7
  };
7
8