@superlayer/cli 1.0.67
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.
- package/LICENSE.md +202 -0
- package/NOTICE +4 -0
- package/README.md +67 -0
- package/bin/index.js +3 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +103 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/commands/app/delete.d.ts +7 -0
- package/dist/commands/app/delete.d.ts.map +1 -0
- package/dist/commands/app/delete.js +57 -0
- package/dist/commands/app/delete.js.map +1 -0
- package/dist/commands/app/list.d.ts +6 -0
- package/dist/commands/app/list.d.ts.map +1 -0
- package/dist/commands/app/list.js +29 -0
- package/dist/commands/app/list.js.map +1 -0
- package/dist/commands/auth/client/add.d.ts +9 -0
- package/dist/commands/auth/client/add.d.ts.map +1 -0
- package/dist/commands/auth/client/add.js +409 -0
- package/dist/commands/auth/client/add.js.map +1 -0
- package/dist/commands/auth/client/delete.d.ts +11 -0
- package/dist/commands/auth/client/delete.d.ts.map +1 -0
- package/dist/commands/auth/client/delete.js +48 -0
- package/dist/commands/auth/client/delete.js.map +1 -0
- package/dist/commands/auth/client/list.d.ts +6 -0
- package/dist/commands/auth/client/list.d.ts.map +1 -0
- package/dist/commands/auth/client/list.js +38 -0
- package/dist/commands/auth/client/list.js.map +1 -0
- package/dist/commands/auth/client/shared.d.ts +70 -0
- package/dist/commands/auth/client/shared.d.ts.map +1 -0
- package/dist/commands/auth/client/shared.js +140 -0
- package/dist/commands/auth/client/shared.js.map +1 -0
- package/dist/commands/auth/client/update.d.ts +8 -0
- package/dist/commands/auth/client/update.d.ts.map +1 -0
- package/dist/commands/auth/client/update.js +445 -0
- package/dist/commands/auth/client/update.js.map +1 -0
- package/dist/commands/auth/email/pull.d.ts +24 -0
- package/dist/commands/auth/email/pull.d.ts.map +1 -0
- package/dist/commands/auth/email/pull.js +100 -0
- package/dist/commands/auth/email/pull.js.map +1 -0
- package/dist/commands/auth/email/push.d.ts +8 -0
- package/dist/commands/auth/email/push.d.ts.map +1 -0
- package/dist/commands/auth/email/push.js +58 -0
- package/dist/commands/auth/email/push.js.map +1 -0
- package/dist/commands/auth/email/resend.d.ts +3 -0
- package/dist/commands/auth/email/resend.d.ts.map +1 -0
- package/dist/commands/auth/email/resend.js +7 -0
- package/dist/commands/auth/email/resend.js.map +1 -0
- package/dist/commands/auth/email/reset.d.ts +5 -0
- package/dist/commands/auth/email/reset.d.ts.map +1 -0
- package/dist/commands/auth/email/reset.js +25 -0
- package/dist/commands/auth/email/reset.js.map +1 -0
- package/dist/commands/auth/email/status.d.ts +57 -0
- package/dist/commands/auth/email/status.d.ts.map +1 -0
- package/dist/commands/auth/email/status.js +96 -0
- package/dist/commands/auth/email/status.js.map +1 -0
- package/dist/commands/auth/email/verify.d.ts +5 -0
- package/dist/commands/auth/email/verify.d.ts.map +1 -0
- package/dist/commands/auth/email/verify.js +12 -0
- package/dist/commands/auth/email/verify.js.map +1 -0
- package/dist/commands/auth/origin/add.d.ts +12 -0
- package/dist/commands/auth/origin/add.d.ts.map +1 -0
- package/dist/commands/auth/origin/add.js +153 -0
- package/dist/commands/auth/origin/add.js.map +1 -0
- package/dist/commands/auth/origin/delete.d.ts +8 -0
- package/dist/commands/auth/origin/delete.d.ts.map +1 -0
- package/dist/commands/auth/origin/delete.js +38 -0
- package/dist/commands/auth/origin/delete.js.map +1 -0
- package/dist/commands/auth/origin/list.d.ts +9 -0
- package/dist/commands/auth/origin/list.d.ts.map +1 -0
- package/dist/commands/auth/origin/list.js +52 -0
- package/dist/commands/auth/origin/list.js.map +1 -0
- package/dist/commands/backup/download.d.ts +10 -0
- package/dist/commands/backup/download.d.ts.map +1 -0
- package/dist/commands/backup/download.js +174 -0
- package/dist/commands/backup/download.js.map +1 -0
- package/dist/commands/backup/list.d.ts +11 -0
- package/dist/commands/backup/list.d.ts.map +1 -0
- package/dist/commands/backup/list.js +74 -0
- package/dist/commands/backup/list.js.map +1 -0
- package/dist/commands/claim.d.ts +6 -0
- package/dist/commands/claim.d.ts.map +1 -0
- package/dist/commands/claim.js +22 -0
- package/dist/commands/claim.js.map +1 -0
- package/dist/commands/explorer.d.ts +6 -0
- package/dist/commands/explorer.d.ts.map +1 -0
- package/dist/commands/explorer.js +13 -0
- package/dist/commands/explorer.js.map +1 -0
- package/dist/commands/info.d.ts +9 -0
- package/dist/commands/info.d.ts.map +1 -0
- package/dist/commands/info.js +41 -0
- package/dist/commands/info.js.map +1 -0
- package/dist/commands/init.d.ts +5 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +41 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/initWithoutFiles.d.ts +6 -0
- package/dist/commands/initWithoutFiles.d.ts.map +1 -0
- package/dist/commands/initWithoutFiles.js +64 -0
- package/dist/commands/initWithoutFiles.js.map +1 -0
- package/dist/commands/login.d.ts +9 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +44 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +3 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +14 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/pull.d.ts +5 -0
- package/dist/commands/pull.d.ts.map +1 -0
- package/dist/commands/pull.js +15 -0
- package/dist/commands/pull.js.map +1 -0
- package/dist/commands/push.d.ts +6 -0
- package/dist/commands/push.d.ts.map +1 -0
- package/dist/commands/push.js +20 -0
- package/dist/commands/push.js.map +1 -0
- package/dist/commands/query.d.ts +7 -0
- package/dist/commands/query.d.ts.map +1 -0
- package/dist/commands/query.js +52 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/webhooks/add.d.ts +9 -0
- package/dist/commands/webhooks/add.d.ts.map +1 -0
- package/dist/commands/webhooks/add.js +75 -0
- package/dist/commands/webhooks/add.js.map +1 -0
- package/dist/commands/webhooks/delete.d.ts +6 -0
- package/dist/commands/webhooks/delete.d.ts.map +1 -0
- package/dist/commands/webhooks/delete.js +17 -0
- package/dist/commands/webhooks/delete.js.map +1 -0
- package/dist/commands/webhooks/disable.d.ts +7 -0
- package/dist/commands/webhooks/disable.d.ts.map +1 -0
- package/dist/commands/webhooks/disable.js +18 -0
- package/dist/commands/webhooks/disable.js.map +1 -0
- package/dist/commands/webhooks/enable.d.ts +6 -0
- package/dist/commands/webhooks/enable.d.ts.map +1 -0
- package/dist/commands/webhooks/enable.js +18 -0
- package/dist/commands/webhooks/enable.js.map +1 -0
- package/dist/commands/webhooks/events/list.d.ts +7 -0
- package/dist/commands/webhooks/events/list.d.ts.map +1 -0
- package/dist/commands/webhooks/events/list.js +31 -0
- package/dist/commands/webhooks/events/list.js.map +1 -0
- package/dist/commands/webhooks/events/payload.d.ts +8 -0
- package/dist/commands/webhooks/events/payload.d.ts.map +1 -0
- package/dist/commands/webhooks/events/payload.js +39 -0
- package/dist/commands/webhooks/events/payload.js.map +1 -0
- package/dist/commands/webhooks/events/resend.d.ts +8 -0
- package/dist/commands/webhooks/events/resend.d.ts.map +1 -0
- package/dist/commands/webhooks/events/resend.js +43 -0
- package/dist/commands/webhooks/events/resend.js.map +1 -0
- package/dist/commands/webhooks/list.d.ts +8 -0
- package/dist/commands/webhooks/list.d.ts.map +1 -0
- package/dist/commands/webhooks/list.js +29 -0
- package/dist/commands/webhooks/list.js.map +1 -0
- package/dist/commands/webhooks/shared.d.ts +40 -0
- package/dist/commands/webhooks/shared.d.ts.map +1 -0
- package/dist/commands/webhooks/shared.js +248 -0
- package/dist/commands/webhooks/shared.js.map +1 -0
- package/dist/commands/webhooks/update.d.ts +10 -0
- package/dist/commands/webhooks/update.d.ts.map +1 -0
- package/dist/commands/webhooks/update.js +189 -0
- package/dist/commands/webhooks/update.js.map +1 -0
- package/dist/context/authToken.d.ts +29 -0
- package/dist/context/authToken.d.ts.map +1 -0
- package/dist/context/authToken.js +73 -0
- package/dist/context/authToken.js.map +1 -0
- package/dist/context/currentApp.d.ts +38 -0
- package/dist/context/currentApp.d.ts.map +1 -0
- package/dist/context/currentApp.js +222 -0
- package/dist/context/currentApp.js.map +1 -0
- package/dist/context/globalOpts.d.ts +11 -0
- package/dist/context/globalOpts.d.ts.map +1 -0
- package/dist/context/globalOpts.js +13 -0
- package/dist/context/globalOpts.js.map +1 -0
- package/dist/context/platformApi.d.ts +19 -0
- package/dist/context/platformApi.d.ts.map +1 -0
- package/dist/context/platformApi.js +24 -0
- package/dist/context/platformApi.js.map +1 -0
- package/dist/context/projectInfo.d.ts +30 -0
- package/dist/context/projectInfo.d.ts.map +1 -0
- package/dist/context/projectInfo.js +152 -0
- package/dist/context/projectInfo.js.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +6 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +159 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +714 -0
- package/dist/index.js.map +1 -0
- package/dist/layer.d.ts +25 -0
- package/dist/layer.d.ts.map +1 -0
- package/dist/layer.js +119 -0
- package/dist/layer.js.map +1 -0
- package/dist/lib/args.d.ts +212 -0
- package/dist/lib/args.d.ts.map +1 -0
- package/dist/lib/args.js +313 -0
- package/dist/lib/args.js.map +1 -0
- package/dist/lib/backupDownload.d.ts +21 -0
- package/dist/lib/backupDownload.d.ts.map +1 -0
- package/dist/lib/backupDownload.js +151 -0
- package/dist/lib/backupDownload.js.map +1 -0
- package/dist/lib/backups.d.ts +12 -0
- package/dist/lib/backups.d.ts.map +1 -0
- package/dist/lib/backups.js +26 -0
- package/dist/lib/backups.js.map +1 -0
- package/dist/lib/config.d.ts +6 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +39 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/createApp.d.ts +12 -0
- package/dist/lib/createApp.d.ts.map +1 -0
- package/dist/lib/createApp.js +15 -0
- package/dist/lib/createApp.js.map +1 -0
- package/dist/lib/email.d.ts +47 -0
- package/dist/lib/email.d.ts.map +1 -0
- package/dist/lib/email.js +71 -0
- package/dist/lib/email.js.map +1 -0
- package/dist/lib/handleEnv.d.ts +7 -0
- package/dist/lib/handleEnv.d.ts.map +1 -0
- package/dist/lib/handleEnv.js +99 -0
- package/dist/lib/handleEnv.js.map +1 -0
- package/dist/lib/http.d.ts +30 -0
- package/dist/lib/http.d.ts.map +1 -0
- package/dist/lib/http.js +55 -0
- package/dist/lib/http.js.map +1 -0
- package/dist/lib/login.d.ts +12 -0
- package/dist/lib/login.d.ts.map +1 -0
- package/dist/lib/login.js +38 -0
- package/dist/lib/login.js.map +1 -0
- package/dist/lib/oauth.d.ts +306 -0
- package/dist/lib/oauth.d.ts.map +1 -0
- package/dist/lib/oauth.js +195 -0
- package/dist/lib/oauth.js.map +1 -0
- package/dist/lib/platformApi.d.ts +5 -0
- package/dist/lib/platformApi.d.ts.map +1 -0
- package/dist/lib/platformApi.js +11 -0
- package/dist/lib/platformApi.js.map +1 -0
- package/dist/lib/pullPerms.d.ts +7 -0
- package/dist/lib/pullPerms.d.ts.map +1 -0
- package/dist/lib/pullPerms.js +41 -0
- package/dist/lib/pullPerms.js.map +1 -0
- package/dist/lib/pullSchema.d.ts +12 -0
- package/dist/lib/pullSchema.d.ts.map +1 -0
- package/dist/lib/pullSchema.js +62 -0
- package/dist/lib/pullSchema.js.map +1 -0
- package/dist/lib/pushPerms.d.ts +13 -0
- package/dist/lib/pushPerms.d.ts.map +1 -0
- package/dist/lib/pushPerms.js +54 -0
- package/dist/lib/pushPerms.js.map +1 -0
- package/dist/lib/pushSchema.d.ts +53 -0
- package/dist/lib/pushSchema.d.ts.map +1 -0
- package/dist/lib/pushSchema.js +165 -0
- package/dist/lib/pushSchema.js.map +1 -0
- package/dist/lib/ui.d.ts +18 -0
- package/dist/lib/ui.d.ts.map +1 -0
- package/dist/lib/ui.js +32 -0
- package/dist/lib/ui.js.map +1 -0
- package/dist/lib/webhooks.d.ts +27 -0
- package/dist/lib/webhooks.d.ts.map +1 -0
- package/dist/lib/webhooks.js +95 -0
- package/dist/lib/webhooks.js.map +1 -0
- package/dist/logging.d.ts +5 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +25 -0
- package/dist/logging.js.map +1 -0
- package/dist/old.d.ts +17 -0
- package/dist/old.d.ts.map +1 -0
- package/dist/old.js +410 -0
- package/dist/old.js.map +1 -0
- package/dist/program.d.ts +3 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +3 -0
- package/dist/program.js.map +1 -0
- package/dist/renderSchemaPlan.d.ts +19 -0
- package/dist/renderSchemaPlan.d.ts.map +1 -0
- package/dist/renderSchemaPlan.js +220 -0
- package/dist/renderSchemaPlan.js.map +1 -0
- package/dist/ui/index.d.ts +292 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +1296 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/lib.d.ts +124 -0
- package/dist/ui/lib.d.ts.map +1 -0
- package/dist/ui/lib.js +333 -0
- package/dist/ui/lib.js.map +1 -0
- package/dist/util/findConfigCandidates.d.ts +13 -0
- package/dist/util/findConfigCandidates.d.ts.map +1 -0
- package/dist/util/findConfigCandidates.js +211 -0
- package/dist/util/findConfigCandidates.js.map +1 -0
- package/dist/util/fs.d.ts +4 -0
- package/dist/util/fs.d.ts.map +1 -0
- package/dist/util/fs.js +22 -0
- package/dist/util/fs.js.map +1 -0
- package/dist/util/getAppName.d.ts +5 -0
- package/dist/util/getAppName.d.ts.map +1 -0
- package/dist/util/getAppName.js +14 -0
- package/dist/util/getAppName.js.map +1 -0
- package/dist/util/instantConfig.d.ts +9 -0
- package/dist/util/instantConfig.d.ts.map +1 -0
- package/dist/util/instantConfig.js +13 -0
- package/dist/util/instantConfig.js.map +1 -0
- package/dist/util/isHeadlessEnvironment.d.ts +4 -0
- package/dist/util/isHeadlessEnvironment.d.ts.map +1 -0
- package/dist/util/isHeadlessEnvironment.js +11 -0
- package/dist/util/isHeadlessEnvironment.js.map +1 -0
- package/dist/util/loadConfig.d.ts +3 -0
- package/dist/util/loadConfig.d.ts.map +1 -0
- package/dist/util/loadConfig.js +72 -0
- package/dist/util/loadConfig.js.map +1 -0
- package/dist/util/loadEnv.d.ts +2 -0
- package/dist/util/loadEnv.d.ts.map +1 -0
- package/dist/util/loadEnv.js +10 -0
- package/dist/util/loadEnv.js.map +1 -0
- package/dist/util/mergeSchema.d.ts +10 -0
- package/dist/util/mergeSchema.d.ts.map +1 -0
- package/dist/util/mergeSchema.js +338 -0
- package/dist/util/mergeSchema.js.map +1 -0
- package/dist/util/projectDir.d.ts +7 -0
- package/dist/util/projectDir.d.ts.map +1 -0
- package/dist/util/projectDir.js +43 -0
- package/dist/util/projectDir.js.map +1 -0
- package/dist/util/renamePrompt.d.ts +15 -0
- package/dist/util/renamePrompt.d.ts.map +1 -0
- package/dist/util/renamePrompt.js +57 -0
- package/dist/util/renamePrompt.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FileSystem, Path } from '@effect/platform';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
import { CurrentApp } from '../context/currentApp.ts';
|
|
4
|
+
import { ProjectInfo } from '../context/projectInfo.ts';
|
|
5
|
+
import { InstantHttpAuthed } from './http.ts';
|
|
6
|
+
import { ReadSchemaFileError } from './pushSchema.ts';
|
|
7
|
+
import { MergeSchemaError } from '../util/mergeSchema.ts';
|
|
8
|
+
export declare const pullSchema: ({ experimentalTypePreservation, }: {
|
|
9
|
+
experimentalTypePreservation?: boolean;
|
|
10
|
+
}) => Effect.Effect<void, import("effect/Cause").UnknownException | import("effect/ParseResult").ParseError | import("./http.ts").InstantHttpError | import("effect/Cause").TimeoutException | import("@effect/platform/HttpClientError").RequestError | import("@effect/platform/HttpClientError").ResponseError | import("@effect/platform/Error").PlatformError | ReadSchemaFileError | MergeSchemaError, import("../context/globalOpts.ts").GlobalOpts | ProjectInfo | InstantHttpAuthed | FileSystem.FileSystem | Path.Path | CurrentApp>;
|
|
11
|
+
export declare const writeTypescript: (path: string, content: string) => Effect.Effect<void, import("effect/Cause").UnknownException | import("@effect/platform/Error").PlatformError, FileSystem.FileSystem>;
|
|
12
|
+
//# sourceMappingURL=pullSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pullSchema.d.ts","sourceRoot":"","sources":["../../src/lib/pullSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAKxE,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAKxC,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAe,MAAM,WAAW,CAAC;AAE3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAe,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAEvE,eAAO,MAAM,UAAU,GAAI,mCAExB;IACD,4BAA4B,CAAC,EAAE,OAAO,CAAC;CACxC,6gBA0DG,CAAC;AAEL,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,EAAE,SAAS,MAAM,yIAazD,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { FileSystem, HttpClientResponse, Path } from '@effect/platform';
|
|
2
|
+
import { apiSchemaToInstantSchemaDef, generateSchemaTypescriptFile, } from '@superlayer/platform';
|
|
3
|
+
import { Effect, Schema } from 'effect';
|
|
4
|
+
import prettier from 'prettier';
|
|
5
|
+
import { countEntities, readLocalSchemaFile } from '../old.js';
|
|
6
|
+
import { UI } from "../ui/index.js";
|
|
7
|
+
import { getSchemaPathToWrite } from "../util/findConfigCandidates.js";
|
|
8
|
+
import { CurrentApp } from "../context/currentApp.js";
|
|
9
|
+
import { ProjectInfo } from "../context/projectInfo.js";
|
|
10
|
+
import { InstantHttpAuthed, withCommand } from "./http.js";
|
|
11
|
+
import { promptOk } from "./ui.js";
|
|
12
|
+
import { ReadSchemaFileError } from "./pushSchema.js";
|
|
13
|
+
import { mergeSchema, MergeSchemaError } from "../util/mergeSchema.js";
|
|
14
|
+
export const pullSchema = ({ experimentalTypePreservation, }) => Effect.gen(function* () {
|
|
15
|
+
yield* Effect.log('Pulling schema...');
|
|
16
|
+
const { appId } = yield* CurrentApp;
|
|
17
|
+
const http = yield* InstantHttpAuthed;
|
|
18
|
+
const schemaResponse = yield* http
|
|
19
|
+
.pipe(withCommand('pull'))
|
|
20
|
+
.get(`/dash/apps/${appId}/schema/pull`)
|
|
21
|
+
.pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any))); // parse result body into "any"
|
|
22
|
+
if (!countEntities(schemaResponse.schema.refs) &&
|
|
23
|
+
!countEntities(schemaResponse.schema.blobs)) {
|
|
24
|
+
yield* Effect.log('Schema is empty. Skipping.');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const prevSchemaFile = yield* Effect.tryPromise(readLocalSchemaFile).pipe(Effect.mapError((err) => ReadSchemaFileError.make({
|
|
28
|
+
message: `Error reading local schema file: ${err}`,
|
|
29
|
+
cause: err,
|
|
30
|
+
})));
|
|
31
|
+
const shortSchemaPath = getSchemaPathToWrite(prevSchemaFile?.path);
|
|
32
|
+
const path = yield* Path.Path;
|
|
33
|
+
const { pkgDir, instantModuleName } = yield* ProjectInfo;
|
|
34
|
+
const schemaPath = path.join(pkgDir, shortSchemaPath);
|
|
35
|
+
if (prevSchemaFile) {
|
|
36
|
+
const shouldContinue = yield* promptOk({
|
|
37
|
+
promptText: `This will overwrite your local ${shortSchemaPath} file, OK to proceed?`,
|
|
38
|
+
modifyOutput: UI.modifiers.yPadding,
|
|
39
|
+
inline: true,
|
|
40
|
+
});
|
|
41
|
+
if (!shouldContinue)
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let newSchemaContent = generateSchemaTypescriptFile(prevSchemaFile?.schema, apiSchemaToInstantSchemaDef(schemaResponse.schema), instantModuleName);
|
|
45
|
+
if (prevSchemaFile && experimentalTypePreservation) {
|
|
46
|
+
const fs = yield* FileSystem.FileSystem;
|
|
47
|
+
const oldSchemaContent = yield* fs.readFileString(prevSchemaFile.path);
|
|
48
|
+
newSchemaContent = yield* Effect.try(() => mergeSchema(oldSchemaContent, newSchemaContent)).pipe(Effect.mapError((e) => new MergeSchemaError({ message: e.message })));
|
|
49
|
+
}
|
|
50
|
+
yield* writeTypescript(schemaPath, newSchemaContent);
|
|
51
|
+
yield* Effect.log('✅ Wrote schema to ' + shortSchemaPath);
|
|
52
|
+
});
|
|
53
|
+
export const writeTypescript = (path, content) => Effect.gen(function* () {
|
|
54
|
+
const prettierConfig = yield* Effect.tryPromise(() => prettier.resolveConfig(path));
|
|
55
|
+
const formattedCode = yield* Effect.tryPromise(() => prettier.format(content, {
|
|
56
|
+
...prettierConfig,
|
|
57
|
+
parser: 'typescript',
|
|
58
|
+
}));
|
|
59
|
+
const fs = yield* FileSystem.FileSystem;
|
|
60
|
+
yield* fs.writeFileString(path, formattedCode);
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=pullSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pullSchema.js","sourceRoot":"","sources":["../../src/lib/pullSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,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E,gBAAgB,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CACxC,WAAW,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAChD,CAAC,IAAI,CACJ,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CACrE,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,CAAC,eAAe,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;IACrD,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,oBAAoB,GAAG,eAAe,CAAC,CAAC;AAC5D,CAAC,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAY,EAAE,OAAe,EAAE,EAAE,CAC/D,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,cAAc,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,CACnD,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAC7B,CAAC;IACF,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,CAClD,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE;QACvB,GAAG,cAAc;QACjB,MAAM,EAAE,YAAY;KACrB,CAAC,CACH,CAAC;IACF,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;IACxC,KAAK,CAAC,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;AACjD,CAAC,CAAC,CAAC","sourcesContent":["import { FileSystem, HttpClientResponse, Path } from '@effect/platform';\nimport {\n apiSchemaToInstantSchemaDef,\n generateSchemaTypescriptFile,\n} from '@superlayer/platform';\nimport { Effect, Schema } from 'effect';\nimport prettier from 'prettier';\nimport { countEntities, readLocalSchemaFile } from '../old.js';\nimport { UI } from '../ui/index.ts';\nimport { getSchemaPathToWrite } from '../util/findConfigCandidates.ts';\nimport { CurrentApp } from '../context/currentApp.ts';\nimport { ProjectInfo } from '../context/projectInfo.ts';\nimport { InstantHttpAuthed, withCommand } from './http.ts';\nimport { promptOk } from './ui.ts';\nimport { ReadSchemaFileError } from './pushSchema.ts';\nimport { mergeSchema, MergeSchemaError } from '../util/mergeSchema.ts';\n\nexport const pullSchema = ({\n experimentalTypePreservation,\n}: {\n experimentalTypePreservation?: boolean;\n}) =>\n Effect.gen(function* () {\n yield* Effect.log('Pulling schema...');\n const { appId } = yield* CurrentApp;\n const http = yield* InstantHttpAuthed;\n\n const schemaResponse = yield* http\n .pipe(withCommand('pull'))\n .get(`/dash/apps/${appId}/schema/pull`)\n .pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any))); // parse result body into \"any\"\n\n if (\n !countEntities(schemaResponse.schema.refs) &&\n !countEntities(schemaResponse.schema.blobs)\n ) {\n yield* Effect.log('Schema is empty. Skipping.');\n return;\n }\n\n const prevSchemaFile = yield* Effect.tryPromise(readLocalSchemaFile).pipe(\n Effect.mapError((err) =>\n ReadSchemaFileError.make({\n message: `Error reading local schema file: ${err}`,\n cause: err,\n }),\n ),\n );\n const shortSchemaPath = getSchemaPathToWrite(prevSchemaFile?.path);\n const path = yield* Path.Path;\n const { pkgDir, instantModuleName } = yield* ProjectInfo;\n const schemaPath = path.join(pkgDir, shortSchemaPath);\n\n if (prevSchemaFile) {\n const shouldContinue = yield* promptOk({\n promptText: `This will overwrite your local ${shortSchemaPath} file, OK to proceed?`,\n modifyOutput: UI.modifiers.yPadding,\n inline: true,\n });\n if (!shouldContinue) return;\n }\n\n let newSchemaContent = generateSchemaTypescriptFile(\n prevSchemaFile?.schema,\n apiSchemaToInstantSchemaDef(schemaResponse.schema),\n instantModuleName,\n );\n\n if (prevSchemaFile && experimentalTypePreservation) {\n const fs = yield* FileSystem.FileSystem;\n const oldSchemaContent = yield* fs.readFileString(prevSchemaFile.path);\n newSchemaContent = yield* Effect.try(() =>\n mergeSchema(oldSchemaContent, newSchemaContent),\n ).pipe(\n Effect.mapError((e) => new MergeSchemaError({ message: e.message })),\n );\n }\n yield* writeTypescript(schemaPath, newSchemaContent);\n yield* Effect.log('✅ Wrote schema to ' + shortSchemaPath);\n });\n\nexport const writeTypescript = (path: string, content: string) =>\n Effect.gen(function* () {\n const prettierConfig = yield* Effect.tryPromise(() =>\n prettier.resolveConfig(path),\n );\n const formattedCode = yield* Effect.tryPromise(() =>\n prettier.format(content, {\n ...prettierConfig,\n parser: 'typescript',\n }),\n );\n const fs = yield* FileSystem.FileSystem;\n yield* fs.writeFileString(path, formattedCode);\n });\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Effect, Schema } from 'effect';
|
|
2
|
+
import { InstantHttpAuthed } from './http.ts';
|
|
3
|
+
import { CurrentApp } from '../context/currentApp.ts';
|
|
4
|
+
declare const NoPermsFileError_base: Schema.TaggedErrorClass<NoPermsFileError, "NoPermsFileError", {
|
|
5
|
+
readonly _tag: Schema.tag<"NoPermsFileError">;
|
|
6
|
+
} & {
|
|
7
|
+
message: typeof Schema.String;
|
|
8
|
+
}>;
|
|
9
|
+
export declare class NoPermsFileError extends NoPermsFileError_base {
|
|
10
|
+
}
|
|
11
|
+
export declare const pushPerms: Effect.Effect<void, import("effect/Cause").UnknownException | import("effect/ParseResult").ParseError | import("./http.ts").InstantHttpError | import("effect/Cause").TimeoutException | import("@effect/platform/HttpClientError").RequestError | import("@effect/platform/HttpClientError").ResponseError | import("@effect/platform/HttpBody").HttpBodyError | NoPermsFileError, import("../context/globalOpts.ts").GlobalOpts | InstantHttpAuthed | CurrentApp>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=pushPerms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pushPerms.d.ts","sourceRoot":"","sources":["../../src/lib/pushPerms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhD,OAAO,EAAE,iBAAiB,EAAe,MAAM,WAAW,CAAC;AAM3D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;;;;;;AAKtD,qBAAa,gBAAiB,SAAQ,qBAIpC;CAAG;AAML,eAAO,MAAM,SAAS,qcAuDpB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Effect, Option, Schema } from 'effect';
|
|
2
|
+
import jsonDiff from 'json-diff';
|
|
3
|
+
import { readLocalPermsFile } from '../old.js';
|
|
4
|
+
import { InstantHttpAuthed, withCommand } from "./http.js";
|
|
5
|
+
import { HttpClient, HttpClientRequest, HttpClientResponse, } from '@effect/platform';
|
|
6
|
+
import { CurrentApp } from "../context/currentApp.js";
|
|
7
|
+
import { promptOk } from "./ui.js";
|
|
8
|
+
import boxen from 'boxen';
|
|
9
|
+
import chalk from 'chalk';
|
|
10
|
+
export class NoPermsFileError extends Schema.TaggedError('NoPermsFileError')('NoPermsFileError', {
|
|
11
|
+
message: Schema.String,
|
|
12
|
+
}) {
|
|
13
|
+
}
|
|
14
|
+
const PullPermsResponse = Schema.Struct({
|
|
15
|
+
perms: Schema.Any.pipe(Schema.optional),
|
|
16
|
+
});
|
|
17
|
+
export const pushPerms = Effect.gen(function* () {
|
|
18
|
+
yield* Effect.log('Planning perms...');
|
|
19
|
+
const { appId } = yield* CurrentApp;
|
|
20
|
+
const http = yield* InstantHttpAuthed;
|
|
21
|
+
const permsFile = yield* Effect.tryPromise(readLocalPermsFile).pipe(Effect.flatMap(Option.fromNullable), Effect.mapError(() => NoPermsFileError.make({
|
|
22
|
+
message: `We couldn't find your ${chalk.yellow('`instant.perms.ts`')} file. Make sure it's in the root directory. (Hint: You can use an INSTANT_PERMS_FILE_PATH environment variable to specify it.)`,
|
|
23
|
+
})));
|
|
24
|
+
const prodPerms = yield* http
|
|
25
|
+
.pipe(withCommand('push'))
|
|
26
|
+
.get(`/dash/apps/${appId}/perms/pull`)
|
|
27
|
+
.pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(PullPermsResponse))); // parse result body into "any"
|
|
28
|
+
const diffedStr = jsonDiff.diffString(prodPerms.perms || {}, permsFile.perms || {});
|
|
29
|
+
if (!diffedStr.length) {
|
|
30
|
+
yield* Effect.log(chalk.bgGray('No perms changes to apply!'));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const okPush = yield* promptOk({
|
|
34
|
+
promptText: 'Push these changes to your perms?',
|
|
35
|
+
modifyOutput: (output) => {
|
|
36
|
+
let both = diffedStr + '\n' + output;
|
|
37
|
+
return boxen(both, {
|
|
38
|
+
dimBorder: true,
|
|
39
|
+
padding: {
|
|
40
|
+
left: 1,
|
|
41
|
+
right: 1,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
if (!okPush)
|
|
47
|
+
return;
|
|
48
|
+
yield* http
|
|
49
|
+
.pipe(withCommand('push'), HttpClient.mapRequestInputEffect(HttpClientRequest.bodyJson({ code: permsFile.perms })))
|
|
50
|
+
.post(`/dash/apps/${appId}/rules`)
|
|
51
|
+
.pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any)));
|
|
52
|
+
yield* Effect.log(chalk.green('Permissions updated!'));
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=pushPerms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pushPerms.js","sourceRoot":"","sources":["../../src/lib/pushPerms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,WAAW,E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E,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC;AACzD,CAAC,CAAC,CAAC","sourcesContent":["import { Effect, Option, Schema } from 'effect';\nimport jsonDiff from 'json-diff';\nimport { readLocalPermsFile } from '../old.js';\nimport { InstantHttpAuthed, withCommand } from './http.ts';\nimport {\n HttpClient,\n HttpClientRequest,\n HttpClientResponse,\n} from '@effect/platform';\nimport { CurrentApp } from '../context/currentApp.ts';\nimport { promptOk } from './ui.ts';\nimport boxen from 'boxen';\nimport chalk from 'chalk';\n\nexport class NoPermsFileError extends Schema.TaggedError<NoPermsFileError>(\n 'NoPermsFileError',\n)('NoPermsFileError', {\n message: Schema.String,\n}) {}\n\nconst PullPermsResponse = Schema.Struct({\n perms: Schema.Any.pipe(Schema.optional),\n});\n\nexport const pushPerms = Effect.gen(function* () {\n yield* Effect.log('Planning perms...');\n const { appId } = yield* CurrentApp;\n const http = yield* InstantHttpAuthed;\n\n const permsFile = yield* Effect.tryPromise(readLocalPermsFile).pipe(\n Effect.flatMap(Option.fromNullable),\n Effect.mapError(() =>\n NoPermsFileError.make({\n message: `We couldn't find your ${chalk.yellow('`instant.perms.ts`')} file. Make sure it's in the root directory. (Hint: You can use an INSTANT_PERMS_FILE_PATH environment variable to specify it.)`,\n }),\n ),\n );\n\n const prodPerms = yield* http\n .pipe(withCommand('push'))\n .get(`/dash/apps/${appId}/perms/pull`)\n .pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(PullPermsResponse))); // parse result body into \"any\"\n\n const diffedStr = jsonDiff.diffString(\n prodPerms.perms || {},\n permsFile.perms || {},\n );\n\n if (!diffedStr.length) {\n yield* Effect.log(chalk.bgGray('No perms changes to apply!'));\n return;\n }\n\n const okPush = yield* promptOk({\n promptText: 'Push these changes to your perms?',\n modifyOutput: (output) => {\n let both = diffedStr + '\\n' + output;\n return boxen(both, {\n dimBorder: true,\n padding: {\n left: 1,\n right: 1,\n },\n });\n },\n });\n if (!okPush) return;\n\n yield* http\n .pipe(\n withCommand('push'),\n HttpClient.mapRequestInputEffect(\n HttpClientRequest.bodyJson({ code: permsFile.perms }),\n ),\n )\n .post(`/dash/apps/${appId}/rules`)\n .pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any)));\n\n yield* Effect.log(chalk.green('Permissions updated!'));\n});\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Effect, Schema } from 'effect';
|
|
2
|
+
import { CurrentApp } from '../context/currentApp.ts';
|
|
3
|
+
import { InstantHttpAuthed } from './http.ts';
|
|
4
|
+
import { GlobalOpts } from '../context/globalOpts.ts';
|
|
5
|
+
import { pushDef } from '../index.ts';
|
|
6
|
+
import type { OptsFromCommand } from '../index.ts';
|
|
7
|
+
import { AuthToken } from '../context/authToken.ts';
|
|
8
|
+
declare const ReadSchemaFileError_base: Schema.TaggedErrorClass<ReadSchemaFileError, "ReadSchemaFileError", {
|
|
9
|
+
readonly _tag: Schema.tag<"ReadSchemaFileError">;
|
|
10
|
+
} & {
|
|
11
|
+
message: typeof Schema.String;
|
|
12
|
+
cause: Schema.optional<typeof Schema.Any>;
|
|
13
|
+
}>;
|
|
14
|
+
export declare class ReadSchemaFileError extends ReadSchemaFileError_base {
|
|
15
|
+
}
|
|
16
|
+
declare const SchemaDiffError_base: Schema.TaggedErrorClass<SchemaDiffError, "SchemaDiffError", {
|
|
17
|
+
readonly _tag: Schema.tag<"SchemaDiffError">;
|
|
18
|
+
} & {
|
|
19
|
+
message: typeof Schema.String;
|
|
20
|
+
}>;
|
|
21
|
+
export declare class SchemaDiffError extends SchemaDiffError_base {
|
|
22
|
+
}
|
|
23
|
+
declare const GetSchemaError_base: Schema.TaggedErrorClass<GetSchemaError, "GetSchemaError", {
|
|
24
|
+
readonly _tag: Schema.tag<"GetSchemaError">;
|
|
25
|
+
} & {
|
|
26
|
+
message: typeof Schema.String;
|
|
27
|
+
}>;
|
|
28
|
+
export declare class GetSchemaError extends GetSchemaError_base {
|
|
29
|
+
}
|
|
30
|
+
declare const SchemaValidationError_base: Schema.TaggedErrorClass<SchemaValidationError, "SchemaValidationError", {
|
|
31
|
+
readonly _tag: Schema.tag<"SchemaValidationError">;
|
|
32
|
+
} & {
|
|
33
|
+
message: typeof Schema.String;
|
|
34
|
+
}>;
|
|
35
|
+
export declare class SchemaValidationError extends SchemaValidationError_base {
|
|
36
|
+
}
|
|
37
|
+
export declare const pushSchema: (rename?: OptsFromCommand<typeof pushDef>["rename"]) => Effect.Effect<undefined, import("../errors.ts").BadArgsError | import("effect/Cause").UnknownException | import("effect/ConfigError").ConfigError | import("effect/ParseResult").ParseError | import("./http.ts").InstantHttpError | import("effect/Cause").TimeoutException | import("@effect/platform/HttpClientError").RequestError | import("@effect/platform/HttpClientError").ResponseError | import("@effect/platform/HttpBody").HttpBodyError | ReadSchemaFileError | SchemaDiffError | GetSchemaError | SchemaValidationError | WaitForJobsError | CancelSchemaError, GlobalOpts | AuthToken | InstantHttpAuthed | CurrentApp>;
|
|
38
|
+
declare const WaitForJobsError_base: Schema.TaggedErrorClass<WaitForJobsError, "WaitForJobsError", {
|
|
39
|
+
readonly _tag: Schema.tag<"WaitForJobsError">;
|
|
40
|
+
} & {
|
|
41
|
+
message: typeof Schema.String;
|
|
42
|
+
}>;
|
|
43
|
+
export declare class WaitForJobsError extends WaitForJobsError_base {
|
|
44
|
+
}
|
|
45
|
+
declare const CancelSchemaError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
46
|
+
readonly _tag: "CancelSchemaError";
|
|
47
|
+
} & Readonly<A>;
|
|
48
|
+
export declare class CancelSchemaError extends CancelSchemaError_base<{
|
|
49
|
+
message: string;
|
|
50
|
+
}> {
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=pushSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pushSchema.d.ts","sourceRoot":"","sources":["../../src/lib/pushSchema.ts"],"names":[],"mappings":"AAeA,OAAO,EAAQ,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAMtD,OAAO,EAAc,iBAAiB,EAAe,MAAM,WAAW,CAAC;AAGvE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAInD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;;;;;;;AAWpD,qBAAa,mBAAoB,SAAQ,wBAKvC;CAAG;;;;;;AAEL,qBAAa,eAAgB,SAAQ,oBAInC;CAAG;;;;;;AAEL,qBAAa,cAAe,SAAQ,mBAIlC;CAAG;;;;;;AAEL,qBAAa,qBAAsB,SAAQ,0BAIzC;CAAG;AAEL,eAAO,MAAM,UAAU,GACrB,SAAS,eAAe,CAAC,OAAO,OAAO,CAAC,CAAC,QAAQ,CAAC,4mBAiIhD,CAAC;;;;;;AAEL,qBAAa,gBAAiB,SAAQ,qBAIpC;CAAG;;;;AAEL,qBAAa,iBAAkB,SAAQ,uBAAsC;IAC3E,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;CAAG"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { HttpClient, HttpClientRequest, HttpClientResponse, } from '@effect/platform';
|
|
2
|
+
import { apiSchemaToInstantSchemaDef, buildAutoRenameSelector, collectSystemCatalogIdentNames, convertTxSteps, diffSchemas, SchemaValidationError as PlatformSchemaError, validateSchema, } from '@superlayer/platform';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { Data, Effect, Schema } from 'effect';
|
|
5
|
+
import { CurrentApp } from "../context/currentApp.js";
|
|
6
|
+
import { readLocalSchemaFile, resolveRenames, waitForIndexingJobsToFinish, } from '../old.js';
|
|
7
|
+
import { getBaseUrl, InstantHttpAuthed, withCommand } from "./http.js";
|
|
8
|
+
import boxen from 'boxen';
|
|
9
|
+
import { GlobalOpts } from "../context/globalOpts.js";
|
|
10
|
+
import { pushDef } from "../index.js";
|
|
11
|
+
import { groupSteps, renderSchemaPlan } from "../renderSchemaPlan.js";
|
|
12
|
+
import { promptOk } from "./ui.js";
|
|
13
|
+
import { AuthToken } from "../context/authToken.js";
|
|
14
|
+
const FetchSchemaResponse = Schema.Struct({
|
|
15
|
+
schema: Schema.Struct({
|
|
16
|
+
refs: Schema.Any,
|
|
17
|
+
blobs: Schema.Any,
|
|
18
|
+
}),
|
|
19
|
+
attrs: Schema.Array(Schema.Any).pipe(Schema.mutable),
|
|
20
|
+
'app-title': Schema.String,
|
|
21
|
+
}).pipe(Schema.mutable);
|
|
22
|
+
export class ReadSchemaFileError extends Schema.TaggedError('ReadSchemaFileError')('ReadSchemaFileError', {
|
|
23
|
+
message: Schema.String,
|
|
24
|
+
cause: Schema.Any.pipe(Schema.optional),
|
|
25
|
+
}) {
|
|
26
|
+
}
|
|
27
|
+
export class SchemaDiffError extends Schema.TaggedError('SchemaDiffError')('SchemaDiffError', {
|
|
28
|
+
message: Schema.String,
|
|
29
|
+
}) {
|
|
30
|
+
}
|
|
31
|
+
export class GetSchemaError extends Schema.TaggedError('GetSchemaError')('GetSchemaError', {
|
|
32
|
+
message: Schema.String,
|
|
33
|
+
}) {
|
|
34
|
+
}
|
|
35
|
+
export class SchemaValidationError extends Schema.TaggedError('SchemaValidationError')('SchemaValidationError', {
|
|
36
|
+
message: Schema.String,
|
|
37
|
+
}) {
|
|
38
|
+
}
|
|
39
|
+
export const pushSchema = (rename) => Effect.gen(function* () {
|
|
40
|
+
const localSchemaFile = yield* Effect.tryPromise({
|
|
41
|
+
try: readLocalSchemaFile,
|
|
42
|
+
catch: (e) => e instanceof Error
|
|
43
|
+
? ReadSchemaFileError.make({ message: e.message })
|
|
44
|
+
: ReadSchemaFileError.make({ message: String(e) }),
|
|
45
|
+
});
|
|
46
|
+
if (!localSchemaFile || !localSchemaFile?.schema) {
|
|
47
|
+
return yield* ReadSchemaFileError.make({
|
|
48
|
+
message: `We couldn't find your ${chalk.yellow('`instant.schema.ts`')} file. Make sure it's in the root directory. (Hint: You can use an INSTANT_SCHEMA_FILE_PATH environment variable to specify it.)`,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (localSchemaFile.schema?.constructor?.name !== 'InstantSchemaDef') {
|
|
52
|
+
return yield* SchemaValidationError.make({
|
|
53
|
+
message: `We couldn't find your schema export.\nIn your ${chalk.yellow('`instant.schema.ts`')} file, make sure you ${chalk.green('`export default schema`')}`,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const http = yield* InstantHttpAuthed;
|
|
57
|
+
const { appId } = yield* CurrentApp;
|
|
58
|
+
const res = yield* http
|
|
59
|
+
.pipe(withCommand('push'))
|
|
60
|
+
.get(`/dash/apps/${appId}/schema/pull`)
|
|
61
|
+
.pipe(Effect.andThen(HttpClientResponse.schemaBodyJson(FetchSchemaResponse)), Effect.mapError((e) => GetSchemaError.make({ message: e.message })));
|
|
62
|
+
const currentAttrs = res['attrs'];
|
|
63
|
+
const currentApiSchema = res['schema'];
|
|
64
|
+
const oldSchema = apiSchemaToInstantSchemaDef(currentApiSchema);
|
|
65
|
+
const systemCatalogIdentNames = collectSystemCatalogIdentNames(currentAttrs);
|
|
66
|
+
yield* Effect.tryPromise({
|
|
67
|
+
try: async () => validateSchema(localSchemaFile.schema, systemCatalogIdentNames),
|
|
68
|
+
catch: (e) => {
|
|
69
|
+
if (e instanceof PlatformSchemaError) {
|
|
70
|
+
return SchemaValidationError.make({
|
|
71
|
+
message: 'Invalid Schema: ' + e.message,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return SchemaValidationError.make({
|
|
75
|
+
message: 'Failed to validate schema' + e,
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
const renames = rename && Array.isArray(rename) ? rename : [];
|
|
80
|
+
const globalOpts = yield* GlobalOpts;
|
|
81
|
+
const autoRenameSelector = buildAutoRenameSelector(renames);
|
|
82
|
+
const renameSelector = globalOpts.yes
|
|
83
|
+
? autoRenameSelector
|
|
84
|
+
: async (created, promptData, extraInfo) => {
|
|
85
|
+
const autoResolved = await autoRenameSelector(created, promptData, extraInfo);
|
|
86
|
+
// If the user provided an explicit --rename match, skip the prompt.
|
|
87
|
+
if (autoResolved !== created) {
|
|
88
|
+
return autoResolved;
|
|
89
|
+
}
|
|
90
|
+
return resolveRenames(created, promptData, extraInfo);
|
|
91
|
+
};
|
|
92
|
+
const diffResult = yield* Effect.tryPromise(() => diffSchemas(oldSchema, localSchemaFile.schema, renameSelector, systemCatalogIdentNames)).pipe(Effect.mapError((e) => {
|
|
93
|
+
if (e.cause instanceof Error) {
|
|
94
|
+
return SchemaDiffError.make({ message: e.cause.message });
|
|
95
|
+
}
|
|
96
|
+
return SchemaDiffError.make({ message: e.message });
|
|
97
|
+
}));
|
|
98
|
+
const txSteps = convertTxSteps(diffResult, currentAttrs);
|
|
99
|
+
if (txSteps.length === 0) {
|
|
100
|
+
yield* Effect.log(chalk.bgGray('No schema changes to apply!'));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const groupedSteps = groupSteps(diffResult);
|
|
104
|
+
yield* confirmSchemaChanges(groupedSteps, currentAttrs);
|
|
105
|
+
const pushRes = yield* http
|
|
106
|
+
.pipe(HttpClient.mapRequestInputEffect(HttpClientRequest.bodyJson({
|
|
107
|
+
steps: txSteps,
|
|
108
|
+
})))
|
|
109
|
+
.post(`/dash/apps/${appId}/schema/steps/apply`)
|
|
110
|
+
.pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any)));
|
|
111
|
+
yield* Effect.log(chalk.green('Schema updated!'));
|
|
112
|
+
const authToken = yield* (yield* AuthToken).getAuthToken;
|
|
113
|
+
if (pushRes?.['indexing-jobs']) {
|
|
114
|
+
// TODO: rewrite in effect
|
|
115
|
+
const apiURI = yield* getBaseUrl;
|
|
116
|
+
yield* Effect.tryPromise({
|
|
117
|
+
try: () => waitForIndexingJobsToFinish(appId, pushRes?.['indexing-jobs'] || [], authToken, apiURI),
|
|
118
|
+
catch: (e) => WaitForJobsError.make({
|
|
119
|
+
message: e?.message || 'Error waiting for schema push jobs to finish',
|
|
120
|
+
}),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
export class WaitForJobsError extends Schema.TaggedError('WaitForJobsError')('WaitForJobsError', {
|
|
125
|
+
message: Schema.String,
|
|
126
|
+
}) {
|
|
127
|
+
}
|
|
128
|
+
export class CancelSchemaError extends Data.TaggedError('CancelSchemaError') {
|
|
129
|
+
}
|
|
130
|
+
const confirmSchemaChanges = (steps, currentAttrs) => Effect.gen(function* () {
|
|
131
|
+
const lines = renderSchemaPlan(steps, currentAttrs);
|
|
132
|
+
const globalOpts = yield* GlobalOpts;
|
|
133
|
+
if (globalOpts.yes) {
|
|
134
|
+
console.log('Applying schema changes...');
|
|
135
|
+
console.log(boxen(lines.join('\n'), {
|
|
136
|
+
dimBorder: true,
|
|
137
|
+
padding: {
|
|
138
|
+
left: 1,
|
|
139
|
+
right: 1,
|
|
140
|
+
},
|
|
141
|
+
}));
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const wantsToPush = yield* promptOk({
|
|
145
|
+
promptText: 'Push these changes?',
|
|
146
|
+
yesText: 'Push',
|
|
147
|
+
noText: 'Cancel',
|
|
148
|
+
modifyOutput: (output) => {
|
|
149
|
+
let both = lines.join('\n') + '\n\n' + output;
|
|
150
|
+
return boxen(both, {
|
|
151
|
+
dimBorder: true,
|
|
152
|
+
padding: {
|
|
153
|
+
left: 1,
|
|
154
|
+
right: 1,
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
if (!wantsToPush) {
|
|
160
|
+
return yield* new CancelSchemaError({
|
|
161
|
+
message: 'Schema Migration Cancelled',
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
//# sourceMappingURL=pushSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pushSchema.js","sourceRoot":"","sources":["../../src/lib/pushSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,EACvB,8BAA8B,EAC9B,cAAc,EACd,WAAW,EACX,qBAAqB,IAAI,mBAAmB,EAC5C,cAAc,GACf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,2BAA2B,GAC5B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAEvE,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAEtE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;QAC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CAAC;QACnB,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QAC1C,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACtB,SAAS,EAAE,IAAI;YACf,OAAO,EAAE;gBACP,IAAI,EAAE,CAAC;gBACP,KAAK,EAAE,CAAC;aACT;SACF,CAAC,CACH,CAAC;QAEF,OAAO;IACT,CAAC;IACD,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC;QAClC,UAAU,EAAE,qBAAqB;QACjC,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,QAAQ;QAChB,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE;YACvB,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC;YAC9C,OAAO,KAAK,CAAC,IAAI,EAAE;gBACjB,SAAS,EAAE,IAAI;gBACf,OAAO,EAAE;oBACP,IAAI,EAAE,CAAC;oBACP,KAAK,EAAE,CAAC;iBACT;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;IACH,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC,CAAC,IAAI,iBAAiB,CAAC;YAClC,OAAO,EAAE,4BAA4B;SACtC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import {\n HttpClient,\n HttpClientRequest,\n HttpClientResponse,\n} from '@effect/platform';\nimport {\n apiSchemaToInstantSchemaDef,\n buildAutoRenameSelector,\n collectSystemCatalogIdentNames,\n convertTxSteps,\n diffSchemas,\n SchemaValidationError as PlatformSchemaError,\n validateSchema,\n} from '@superlayer/platform';\nimport chalk from 'chalk';\nimport { Data, Effect, Schema } from 'effect';\nimport { CurrentApp } from '../context/currentApp.ts';\nimport {\n readLocalSchemaFile,\n resolveRenames,\n waitForIndexingJobsToFinish,\n} from '../old.js';\nimport { getBaseUrl, InstantHttpAuthed, withCommand } from './http.ts';\n\nimport boxen from 'boxen';\nimport { GlobalOpts } from '../context/globalOpts.ts';\nimport { pushDef } from '../index.ts';\nimport type { OptsFromCommand } from '../index.ts';\nimport { groupSteps, renderSchemaPlan } from '../renderSchemaPlan.ts';\nimport type { SuperMigrationTx } from '../renderSchemaPlan.ts';\nimport { promptOk } from './ui.ts';\nimport { AuthToken } from '../context/authToken.ts';\n\nconst FetchSchemaResponse = Schema.Struct({\n schema: Schema.Struct({\n refs: Schema.Any,\n blobs: Schema.Any,\n }),\n attrs: Schema.Array(Schema.Any).pipe(Schema.mutable),\n 'app-title': Schema.String,\n}).pipe(Schema.mutable);\n\nexport class ReadSchemaFileError extends Schema.TaggedError<ReadSchemaFileError>(\n 'ReadSchemaFileError',\n)('ReadSchemaFileError', {\n message: Schema.String,\n cause: Schema.Any.pipe(Schema.optional),\n}) {}\n\nexport class SchemaDiffError extends Schema.TaggedError<SchemaDiffError>(\n 'SchemaDiffError',\n)('SchemaDiffError', {\n message: Schema.String,\n}) {}\n\nexport class GetSchemaError extends Schema.TaggedError<GetSchemaError>(\n 'GetSchemaError',\n)('GetSchemaError', {\n message: Schema.String,\n}) {}\n\nexport class SchemaValidationError extends Schema.TaggedError<SchemaValidationError>(\n 'SchemaValidationError',\n)('SchemaValidationError', {\n message: Schema.String,\n}) {}\n\nexport const pushSchema = (\n rename?: OptsFromCommand<typeof pushDef>['rename'],\n) =>\n Effect.gen(function* () {\n const localSchemaFile = yield* Effect.tryPromise({\n try: readLocalSchemaFile,\n catch: (e) =>\n e instanceof Error\n ? ReadSchemaFileError.make({ message: e.message })\n : ReadSchemaFileError.make({ message: String(e) }),\n });\n if (!localSchemaFile || !localSchemaFile?.schema) {\n return yield* ReadSchemaFileError.make({\n message: `We couldn't find your ${chalk.yellow('`instant.schema.ts`')} file. Make sure it's in the root directory. (Hint: You can use an INSTANT_SCHEMA_FILE_PATH environment variable to specify it.)`,\n });\n }\n if (localSchemaFile.schema?.constructor?.name !== 'InstantSchemaDef') {\n return yield* SchemaValidationError.make({\n message: `We couldn't find your schema export.\\nIn your ${chalk.yellow('`instant.schema.ts`')} file, make sure you ${chalk.green('`export default schema`')}`,\n });\n }\n\n const http = yield* InstantHttpAuthed;\n const { appId } = yield* CurrentApp;\n const res = yield* http\n .pipe(withCommand('push'))\n .get(`/dash/apps/${appId}/schema/pull`)\n .pipe(\n Effect.andThen(HttpClientResponse.schemaBodyJson(FetchSchemaResponse)),\n Effect.mapError((e) => GetSchemaError.make({ message: e.message })),\n );\n\n const currentAttrs = res['attrs'];\n const currentApiSchema = res['schema'];\n const oldSchema = apiSchemaToInstantSchemaDef(currentApiSchema);\n const systemCatalogIdentNames =\n collectSystemCatalogIdentNames(currentAttrs);\n\n yield* Effect.tryPromise({\n try: async () =>\n validateSchema(localSchemaFile.schema, systemCatalogIdentNames),\n catch: (e) => {\n if (e instanceof PlatformSchemaError) {\n return SchemaValidationError.make({\n message: 'Invalid Schema: ' + e.message,\n });\n }\n return SchemaValidationError.make({\n message: 'Failed to validate schema' + e,\n });\n },\n });\n const renames = rename && Array.isArray(rename) ? rename : [];\n const globalOpts = yield* GlobalOpts;\n const autoRenameSelector = buildAutoRenameSelector(renames as any);\n const renameSelector = globalOpts.yes\n ? autoRenameSelector\n : async (created: any, promptData: any, extraInfo: any) => {\n const autoResolved = await autoRenameSelector(\n created,\n promptData,\n extraInfo,\n );\n\n // If the user provided an explicit --rename match, skip the prompt.\n if (autoResolved !== created) {\n return autoResolved;\n }\n\n return resolveRenames(created, promptData, extraInfo);\n };\n\n const diffResult = yield* Effect.tryPromise(() =>\n diffSchemas(\n oldSchema,\n localSchemaFile.schema,\n renameSelector,\n systemCatalogIdentNames,\n ),\n ).pipe(\n Effect.mapError((e) => {\n if (e.cause instanceof Error) {\n return SchemaDiffError.make({ message: e.cause.message });\n }\n return SchemaDiffError.make({ message: e.message });\n }),\n );\n\n const txSteps = convertTxSteps(diffResult, currentAttrs);\n if (txSteps.length === 0) {\n yield* Effect.log(chalk.bgGray('No schema changes to apply!'));\n return;\n }\n\n const groupedSteps = groupSteps(diffResult);\n yield* confirmSchemaChanges(groupedSteps, currentAttrs);\n\n const pushRes = yield* http\n .pipe(\n HttpClient.mapRequestInputEffect(\n HttpClientRequest.bodyJson({\n steps: txSteps,\n }),\n ),\n )\n .post(`/dash/apps/${appId}/schema/steps/apply`)\n .pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Schema.Any)));\n\n yield* Effect.log(chalk.green('Schema updated!'));\n\n const authToken = yield* (yield* AuthToken).getAuthToken;\n\n if (pushRes?.['indexing-jobs']) {\n // TODO: rewrite in effect\n const apiURI = yield* getBaseUrl;\n yield* Effect.tryPromise({\n try: () =>\n waitForIndexingJobsToFinish(\n appId,\n pushRes?.['indexing-jobs'] || [],\n authToken,\n apiURI,\n ),\n catch: (e: any) =>\n WaitForJobsError.make({\n message:\n e?.message || 'Error waiting for schema push jobs to finish',\n }),\n });\n }\n });\n\nexport class WaitForJobsError extends Schema.TaggedError<WaitForJobsError>(\n 'WaitForJobsError',\n)('WaitForJobsError', {\n message: Schema.String,\n}) {}\n\nexport class CancelSchemaError extends Data.TaggedError('CancelSchemaError')<{\n message: string;\n}> {}\n\nconst confirmSchemaChanges = (steps: SuperMigrationTx[], currentAttrs: any[]) =>\n Effect.gen(function* () {\n const lines = renderSchemaPlan(steps, currentAttrs);\n const globalOpts = yield* GlobalOpts;\n if (globalOpts.yes) {\n console.log('Applying schema changes...');\n console.log(\n boxen(lines.join('\\n'), {\n dimBorder: true,\n padding: {\n left: 1,\n right: 1,\n },\n }),\n );\n\n return;\n }\n const wantsToPush = yield* promptOk({\n promptText: 'Push these changes?',\n yesText: 'Push',\n noText: 'Cancel',\n modifyOutput: (output) => {\n let both = lines.join('\\n') + '\\n\\n' + output;\n return boxen(both, {\n dimBorder: true,\n padding: {\n left: 1,\n right: 1,\n },\n });\n },\n });\n if (!wantsToPush) {\n return yield* new CancelSchemaError({\n message: 'Schema Migration Cancelled',\n });\n }\n });\n"]}
|
package/dist/lib/ui.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { GlobalOpts } from '../context/globalOpts.ts';
|
|
3
|
+
import { Prompt } from '../ui/lib.ts';
|
|
4
|
+
import { UI } from '../ui/index.ts';
|
|
5
|
+
declare const UIError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
6
|
+
readonly _tag: "UIError";
|
|
7
|
+
} & Readonly<A>;
|
|
8
|
+
export declare class UIError extends UIError_base<{
|
|
9
|
+
message: string;
|
|
10
|
+
cause?: unknown;
|
|
11
|
+
}> {
|
|
12
|
+
}
|
|
13
|
+
export declare const promptOk: (props: UI.ConfirmationProps, defaultValue?: boolean | undefined) => Effect.Effect<boolean, import("effect/Cause").UnknownException, GlobalOpts>;
|
|
14
|
+
export declare const runUIEffect: <P>(prompt: Prompt<P>) => Effect.Effect<P, UIError, never>;
|
|
15
|
+
export declare const stripFirstBlankLine: (str: string) => string;
|
|
16
|
+
export declare const validateRequired: (input: string) => "Value is required" | undefined;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=ui.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../../src/lib/ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,MAAM,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,MAAM,EAAgB,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;;;;AAEpC,qBAAa,OAAQ,SAAQ,aAA4B;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;CAAG;AAEL,eAAO,MAAM,QAAQ,kJAiBnB,CAAC;AAEH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,QAAQ,MAAM,CAAC,CAAC,CAAC,qCAO5C,CAAC;AAEL,eAAO,MAAM,mBAAmB,GAAI,KAAK,MAAM,KAAG,MAMjD,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,oCACa,CAAC"}
|
package/dist/lib/ui.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Data, Effect } from 'effect';
|
|
2
|
+
import { GlobalOpts } from "../context/globalOpts.js";
|
|
3
|
+
import { Prompt, renderUnwrap } from "../ui/lib.js";
|
|
4
|
+
import { UI } from "../ui/index.js";
|
|
5
|
+
export class UIError extends Data.TaggedError('UIError') {
|
|
6
|
+
}
|
|
7
|
+
export const promptOk = Effect.fn('promptOk')(function* (props, defaultValue = true) {
|
|
8
|
+
const opts = yield* GlobalOpts;
|
|
9
|
+
if (opts.yes) {
|
|
10
|
+
return defaultValue;
|
|
11
|
+
}
|
|
12
|
+
return yield* Effect.tryPromise(() => renderUnwrap(new UI.Confirmation({
|
|
13
|
+
...props,
|
|
14
|
+
defaultValue,
|
|
15
|
+
})));
|
|
16
|
+
});
|
|
17
|
+
export const runUIEffect = (prompt) => Effect.tryPromise({
|
|
18
|
+
try: () => renderUnwrap(prompt),
|
|
19
|
+
catch: (error) => new UIError({
|
|
20
|
+
message: error instanceof Error ? error.message : String(error),
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
export const stripFirstBlankLine = (str) => {
|
|
24
|
+
const lines = str.split('\n');
|
|
25
|
+
const firstBlankIndex = lines.findIndex((line) => line.trim() === '');
|
|
26
|
+
if (firstBlankIndex === -1)
|
|
27
|
+
return str;
|
|
28
|
+
lines.splice(firstBlankIndex, 1);
|
|
29
|
+
return lines.join('\n');
|
|
30
|
+
};
|
|
31
|
+
export const validateRequired = (input) => input.trim().length > 0 ?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ChE,CAAC;CACL,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAW,EAAU,EAAE;IACzD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,eAAe,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACtE,IAAI,eAAe,KAAK,CAAC,CAAC;QAAE,OAAO,GAAG,CAAC;IACvC,KAAK,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAE,EAAE,CAChD,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,mBAAmB,CAAC","sourcesContent":["import { Data, Effect } from 'effect';\nimport { GlobalOpts } from '../context/globalOpts.ts';\nimport { Prompt, renderUnwrap } from '../ui/lib.ts';\nimport { UI } from '../ui/index.ts';\n\nexport class UIError extends Data.TaggedError('UIError')<{\n message: string;\n cause?: unknown;\n}> {}\n\nexport const promptOk = Effect.fn('promptOk')(function* (\n props: UI.ConfirmationProps,\n defaultValue: boolean = true,\n) {\n const opts = yield* GlobalOpts;\n if (opts.yes) {\n return defaultValue;\n }\n\n return yield* Effect.tryPromise(() =>\n renderUnwrap(\n new UI.Confirmation({\n ...props,\n defaultValue,\n }),\n ),\n );\n});\n\nexport const runUIEffect = <P>(prompt: Prompt<P>) =>\n Effect.tryPromise({\n try: () => renderUnwrap(prompt),\n catch: (error) =>\n new UIError({\n message: error instanceof Error ? error.message : String(error),\n }),\n });\n\nexport const stripFirstBlankLine = (str: string): string => {\n const lines = str.split('\\n');\n const firstBlankIndex = lines.findIndex((line) => line.trim() === '');\n if (firstBlankIndex === -1) return str;\n lines.splice(firstBlankIndex, 1);\n return lines.join('\\n');\n};\n\nexport const validateRequired = (input: string) =>\n input.trim().length > 0 ? undefined : 'Value is required';\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { type WebhookAction, type WebhookEventInfo, type WebhooksManager } from '@superlayer/platform';
|
|
3
|
+
import { CurrentApp } from '../context/currentApp.ts';
|
|
4
|
+
import { PlatformApiError } from '../context/platformApi.ts';
|
|
5
|
+
import { BadArgsError } from '../errors.ts';
|
|
6
|
+
export declare const WEBHOOK_ACTIONS: readonly WebhookAction[];
|
|
7
|
+
export declare const useWebhooksManager: <R>(fun: (manager: WebhooksManager<any>) => Promise<R>, errorMessage?: string) => Effect.Effect<R, BadArgsError | import("effect/Cause").UnknownException | import("effect/ConfigError").ConfigError | PlatformApiError, import("../context/authToken.ts").AuthToken | CurrentApp>;
|
|
8
|
+
/**
|
|
9
|
+
* Yields a `WebhooksManager` instance scoped to the current app. Use when you
|
|
10
|
+
* need to hold on to the manager outside an Effect (e.g. to call from inside
|
|
11
|
+
* an async UI callback).
|
|
12
|
+
*/
|
|
13
|
+
export declare const buildWebhooksManager: Effect.Effect<WebhooksManager<import("@superlayer/core").InstantUnknownSchemaDef>, BadArgsError | import("effect/Cause").UnknownException | import("effect/ConfigError").ConfigError, import("../context/authToken.ts").AuthToken | CurrentApp>;
|
|
14
|
+
/**
|
|
15
|
+
* Fetches the app's schema and returns the sorted list of namespace names. Returns
|
|
16
|
+
* `null` if the schema can't be fetched (network, auth, missing app, etc.) so
|
|
17
|
+
* callers can fall back to a plain text prompt.
|
|
18
|
+
*/
|
|
19
|
+
export declare const getRemoteNamespaces: Effect.Effect<string[] | null, BadArgsError | import("effect/Cause").UnknownException | import("effect/ConfigError").ConfigError, import("../context/authToken.ts").AuthToken | CurrentApp>;
|
|
20
|
+
/**
|
|
21
|
+
* Pages through `manager.listEvents` until we have `limit` events or the server
|
|
22
|
+
* runs out. Returns the events in their natural (newest-first) order.
|
|
23
|
+
*/
|
|
24
|
+
export declare const fetchRecentEvents: (webhookId: string, limit: number) => Effect.Effect<WebhookEventInfo[], BadArgsError | import("effect/Cause").UnknownException | import("effect/ConfigError").ConfigError | PlatformApiError, import("../context/authToken.ts").AuthToken | CurrentApp>;
|
|
25
|
+
export declare const parseNamespaces: (raw: string | undefined) => Effect.Effect<string[] | undefined, BadArgsError, never>;
|
|
26
|
+
export declare const parseActions: (raw: string | undefined) => Effect.Effect<WebhookAction[] | undefined, BadArgsError, never>;
|
|
27
|
+
//# sourceMappingURL=webhooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../src/lib/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,eAAO,MAAM,eAAe,EAAE,SAAS,aAAa,EAI1C,CAAC;AAEX,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAClC,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAClD,eAAe,MAAM,qMAanB,CAAC;AAEL;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,iPAI/B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,6LAS9B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,WAAW,MAAM,EAAE,OAAO,MAAM,sNAc9D,CAAC;AAQL,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,GAAG,SAAS,6DAUnD,CAAC;AAEL,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,GAAG,SAAS,oEAkBhD,CAAC"}
|