instant-cli 0.22.120 → 0.22.121-experimental.drewh-clief.21610676979.1
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/.turbo/turbo-build.log +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/new/commands/init.d.ts +9 -0
- package/dist/new/commands/init.d.ts.map +1 -0
- package/dist/new/commands/init.js +9 -0
- package/dist/new/commands/init.js.map +1 -0
- package/dist/new/commands/initWithoutFiles.d.ts +10 -0
- package/dist/new/commands/initWithoutFiles.d.ts.map +1 -0
- package/dist/new/commands/initWithoutFiles.js +36 -0
- package/dist/new/commands/initWithoutFiles.js.map +1 -0
- package/dist/new/commands/login.d.ts +9 -0
- package/dist/new/commands/login.d.ts.map +1 -0
- package/dist/new/commands/login.js +51 -0
- package/dist/new/commands/login.js.map +1 -0
- package/dist/new/commands/logout.d.ts +4 -0
- package/dist/new/commands/logout.d.ts.map +1 -0
- package/dist/new/commands/logout.js +22 -0
- package/dist/new/commands/logout.js.map +1 -0
- package/dist/new/context/authToken.d.ts +19 -0
- package/dist/new/context/authToken.d.ts.map +1 -0
- package/dist/new/context/authToken.js +51 -0
- package/dist/new/context/authToken.js.map +1 -0
- package/dist/new/context/currentApp.d.ts +36 -0
- package/dist/new/context/currentApp.d.ts.map +1 -0
- package/dist/new/context/currentApp.js +145 -0
- package/dist/new/context/currentApp.js.map +1 -0
- package/dist/new/context/globalOpts.d.ts +11 -0
- package/dist/new/context/globalOpts.d.ts.map +1 -0
- package/dist/new/context/globalOpts.js +10 -0
- package/dist/new/context/globalOpts.js.map +1 -0
- package/dist/new/context/platformApi.d.ts +19 -0
- package/dist/new/context/platformApi.d.ts.map +1 -0
- package/dist/new/context/platformApi.js +24 -0
- package/dist/new/context/platformApi.js.map +1 -0
- package/dist/new/context/projectInfo.d.ts +25 -0
- package/dist/new/context/projectInfo.d.ts.map +1 -0
- package/dist/new/context/projectInfo.js +120 -0
- package/dist/new/context/projectInfo.js.map +1 -0
- package/dist/new/errors.d.ts +10 -0
- package/dist/new/errors.d.ts.map +1 -0
- package/dist/new/errors.js +6 -0
- package/dist/new/errors.js.map +1 -0
- package/dist/new/index.d.ts +17 -0
- package/dist/new/index.d.ts.map +1 -0
- package/dist/new/index.js +159 -0
- package/dist/new/index.js.map +1 -0
- package/dist/new/layer.d.ts +15 -0
- package/dist/new/layer.d.ts.map +1 -0
- package/dist/new/layer.js +41 -0
- package/dist/new/layer.js.map +1 -0
- package/dist/new/lib/createApp.d.ts +4 -0
- package/dist/new/lib/createApp.d.ts.map +1 -0
- package/dist/new/lib/createApp.js +13 -0
- package/dist/new/lib/createApp.js.map +1 -0
- package/dist/new/lib/handleEnv.d.ts +7 -0
- package/dist/new/lib/handleEnv.d.ts.map +1 -0
- package/dist/new/lib/handleEnv.js +88 -0
- package/dist/new/lib/handleEnv.js.map +1 -0
- package/dist/new/lib/http.d.ts +15 -0
- package/dist/new/lib/http.d.ts.map +1 -0
- package/dist/new/lib/http.js +32 -0
- package/dist/new/lib/http.js.map +1 -0
- package/dist/new/lib/login.d.ts +13 -0
- package/dist/new/lib/login.d.ts.map +1 -0
- package/dist/new/lib/login.js +36 -0
- package/dist/new/lib/login.js.map +1 -0
- package/dist/new/lib/ui.d.ts +16 -0
- package/dist/new/lib/ui.d.ts.map +1 -0
- package/dist/new/lib/ui.js +30 -0
- package/dist/new/lib/ui.js.map +1 -0
- package/dist/new/logging.d.ts +3 -0
- package/dist/new/logging.d.ts.map +1 -0
- package/dist/new/logging.js +8 -0
- package/dist/new/logging.js.map +1 -0
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js.map +1 -1
- package/dist/util/getAuthPaths.d.ts.map +1 -1
- package/dist/util/getAuthPaths.js.map +1 -1
- package/package.json +14 -5
- package/src/index.js +1 -1
- package/src/new/commands/init.ts +12 -0
- package/src/new/commands/initWithoutFiles.ts +44 -0
- package/src/new/commands/login.ts +73 -0
- package/src/new/commands/logout.ts +23 -0
- package/src/new/context/authToken.ts +77 -0
- package/src/new/context/currentApp.ts +207 -0
- package/src/new/context/globalOpts.ts +22 -0
- package/src/new/context/platformApi.ts +35 -0
- package/src/new/context/projectInfo.ts +172 -0
- package/src/new/errors.ts +7 -0
- package/src/new/index.ts +245 -0
- package/src/new/layer.ts +78 -0
- package/src/new/lib/createApp.ts +18 -0
- package/src/new/lib/handleEnv.ts +107 -0
- package/src/new/lib/http.ts +63 -0
- package/src/new/lib/login.ts +50 -0
- package/src/new/lib/ui.ts +45 -0
- package/src/new/logging.ts +9 -0
- package/src/ui/index.ts +1 -1
- package/src/util/getAuthPaths.ts +1 -0
- package/tsconfig.json +7 -2
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Context, Layer } from 'effect';
|
|
2
|
+
declare const ProjectInfo_base: Context.TagClass<ProjectInfo, "instant-cli/new/context/projectInfo", {
|
|
3
|
+
pkgDir: string;
|
|
4
|
+
projectType: "node" | "deno";
|
|
5
|
+
instantModuleName: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare class ProjectInfo extends ProjectInfo_base {
|
|
8
|
+
}
|
|
9
|
+
export declare const PACKAGE_ALIAS_AND_FULL_NAMES: {
|
|
10
|
+
react: string;
|
|
11
|
+
'react-native': string;
|
|
12
|
+
core: string;
|
|
13
|
+
admin: string;
|
|
14
|
+
};
|
|
15
|
+
declare const ProjectInfoError_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 & {
|
|
16
|
+
readonly _tag: "ProjectInfoError";
|
|
17
|
+
} & Readonly<A>;
|
|
18
|
+
export declare class ProjectInfoError extends ProjectInfoError_base<{
|
|
19
|
+
message: string;
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
}> {
|
|
22
|
+
}
|
|
23
|
+
export declare const ProjectInfoLive: (coerce?: boolean, packageName?: keyof typeof PACKAGE_ALIAS_AND_FULL_NAMES) => Layer.Layer<ProjectInfo, import("../lib/ui.js").UIError | ProjectInfoError, never>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=projectInfo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectInfo.d.ts","sourceRoot":"","sources":["../../../src/new/context/projectInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAgB,KAAK,EAAE,MAAM,QAAQ,CAAC;;YAe1C,MAAM;iBACD,MAAM,GAAG,MAAM;uBACT,MAAM;;AAP7B,qBAAa,WAAY,SAAQ,gBAS9B;CAAG;AAIN,eAAO,MAAM,4BAA4B;;;;;CAKxC,CAAC;;;;AAEF,qBAAa,gBAAiB,SAAQ,sBAAqC;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;CAAG;AAmHL,eAAO,MAAM,eAAe,GAC1B,SAAQ,OAAc,EACtB,cAAc,MAAM,OAAO,4BAA4B,uFACU,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Context, Data, Effect, Layer } from 'effect';
|
|
2
|
+
import { detect } from 'package-manager-detector/detect';
|
|
3
|
+
import { readPackage } from 'pkg-types';
|
|
4
|
+
import { exec } from 'child_process';
|
|
5
|
+
import { promisify } from 'util';
|
|
6
|
+
import { UI } from '../../ui/index.js';
|
|
7
|
+
import { findProjectDir } from '../../util/projectDir.js';
|
|
8
|
+
import { runUIEffect } from '../lib/ui.js';
|
|
9
|
+
export class ProjectInfo extends Context.Tag('instant-cli/new/context/projectInfo')() {
|
|
10
|
+
}
|
|
11
|
+
const execAsync = promisify(exec);
|
|
12
|
+
export const PACKAGE_ALIAS_AND_FULL_NAMES = {
|
|
13
|
+
react: '@instantdb/react',
|
|
14
|
+
'react-native': '@instantdb/react-native',
|
|
15
|
+
core: '@instantdb/core',
|
|
16
|
+
admin: '@instantdb/admin',
|
|
17
|
+
};
|
|
18
|
+
export class ProjectInfoError extends Data.TaggedError('ProjectInfoError') {
|
|
19
|
+
}
|
|
20
|
+
const getProjectInfo = (coerce = true, packageName) => Effect.gen(function* () {
|
|
21
|
+
const projectDir = yield* Effect.tryPromise({
|
|
22
|
+
try: () => findProjectDir(),
|
|
23
|
+
catch: (e) => new ProjectInfoError({ message: "Couldn't get project dir" }),
|
|
24
|
+
});
|
|
25
|
+
if (!projectDir) {
|
|
26
|
+
return yield* new ProjectInfoError({
|
|
27
|
+
message: "Couldn't find a project directory (package.json)",
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (projectDir.type === 'deno') {
|
|
31
|
+
return {
|
|
32
|
+
pkgDir: projectDir.dir,
|
|
33
|
+
projectType: projectDir.type,
|
|
34
|
+
instantModuleName: '@instantdb/core',
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const pkgJson = yield* Effect.tryPromise({
|
|
38
|
+
try: () => readPackage(),
|
|
39
|
+
catch: () => new ProjectInfoError({ message: "Couldn't read package.json" }),
|
|
40
|
+
});
|
|
41
|
+
let moduleName = getInstantModuleName(pkgJson);
|
|
42
|
+
if (!moduleName && !coerce) {
|
|
43
|
+
return yield* new ProjectInfoError({
|
|
44
|
+
message: 'No instant client library installed',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// TODO: Clean up with option
|
|
48
|
+
const packageManager = yield* Effect.tryPromise(() => detect()).pipe(Effect.flatMap(Effect.fromNullable), Effect.mapError(() => new ProjectInfoError({
|
|
49
|
+
message: 'Failed to detect package manager',
|
|
50
|
+
})));
|
|
51
|
+
if (!moduleName && coerce) {
|
|
52
|
+
// install the packages
|
|
53
|
+
if (packageName) {
|
|
54
|
+
moduleName = PACKAGE_ALIAS_AND_FULL_NAMES[packageName];
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
moduleName = yield* runUIEffect(new UI.Select({
|
|
58
|
+
promptText: 'Which package would you like to use?',
|
|
59
|
+
options: [
|
|
60
|
+
{ label: '@instantdb/react', value: '@instantdb/react' },
|
|
61
|
+
{
|
|
62
|
+
label: '@instantdb/react-native',
|
|
63
|
+
value: '@instantdb/react-native',
|
|
64
|
+
},
|
|
65
|
+
{ label: '@instantdb/core', value: '@instantdb/core' },
|
|
66
|
+
{ label: '@instantdb/admin', value: '@instantdb/admin' },
|
|
67
|
+
],
|
|
68
|
+
})).pipe(Effect.flatMap(Effect.fromNullable), Effect.mapError(() => new ProjectInfoError({
|
|
69
|
+
message: 'Failed to select package',
|
|
70
|
+
})));
|
|
71
|
+
}
|
|
72
|
+
const packagesToInstall = [moduleName];
|
|
73
|
+
if (moduleName === '@instantdb/react-native') {
|
|
74
|
+
packagesToInstall.push('react-native-get-random-values', '@react-native-async-storage/async-storage');
|
|
75
|
+
}
|
|
76
|
+
const installCommand = getInstallCommand(packageManager.agent, packagesToInstall.join(' '));
|
|
77
|
+
console.log(installCommand);
|
|
78
|
+
yield* runUIEffect(new UI.Spinner({
|
|
79
|
+
promise: execAsync(installCommand, {
|
|
80
|
+
cwd: projectDir.dir,
|
|
81
|
+
}),
|
|
82
|
+
errorText: 'Failed to install packages',
|
|
83
|
+
workingText: `Installing ${packagesToInstall.join(', ')} using ${packageManager.agent}...`,
|
|
84
|
+
doneText: `Installed ${packagesToInstall.join(', ')} using ${packageManager.agent}.`,
|
|
85
|
+
}));
|
|
86
|
+
return {
|
|
87
|
+
pkgDir: projectDir.dir,
|
|
88
|
+
projectType: projectDir.type,
|
|
89
|
+
instantModuleName: moduleName,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return {
|
|
94
|
+
pkgDir: projectDir.dir,
|
|
95
|
+
projectType: projectDir.type,
|
|
96
|
+
instantModuleName: moduleName,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
export const ProjectInfoLive = (coerce = true, packageName) => Layer.effect(ProjectInfo, getProjectInfo(coerce, packageName));
|
|
101
|
+
function getInstantModuleName(pkgJson) {
|
|
102
|
+
const deps = pkgJson.dependencies || {};
|
|
103
|
+
const devDeps = pkgJson.devDependencies || {};
|
|
104
|
+
const instantModuleName = [
|
|
105
|
+
'@instantdb/react',
|
|
106
|
+
'@instantdb/react-native',
|
|
107
|
+
'@instantdb/core',
|
|
108
|
+
'@instantdb/admin',
|
|
109
|
+
].find((name) => deps[name] || devDeps[name]);
|
|
110
|
+
return instantModuleName;
|
|
111
|
+
}
|
|
112
|
+
function getInstallCommand(packageManager, moduleName) {
|
|
113
|
+
if (packageManager === 'npm') {
|
|
114
|
+
return `npm install ${moduleName}`;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
return `${packageManager} add ${moduleName}`;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=projectInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectInfo.js","sourceRoot":"","sources":["../../../src/new/context/projectInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAe,WAAW,EAAE,MAAM,WAAW,CAAC;AAErD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,OAAO,WAAY,SAAQ,OAAO,CAAC,GAAG,CAC1C,qCAAqC,CACtC,EAOE;CAAG;AAEN,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAElC,MAAM,CAAC,MAAM,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,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;IACxC,MAAM,OAAO,GAAG,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC;IAC9C,MAAM,iBAAiB,GAAG;QACxB,kBAAkB;QAClB,yBAAyB;QACzB,iBAAiB;QACjB,kBAAkB;KACnB,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED,SAAS,iBAAiB,CAAC,cAAsB,EAAE,UAAkB;IACnE,IAAI,cAAc,KAAK,KAAK,EAAE,CAAC;QAC7B,OAAO,eAAe,UAAU,EAAE,CAAC;IACrC,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,cAAc,QAAQ,UAAU,EAAE,CAAC;IAC/C,CAAC;AACH,CAAC","sourcesContent":["import { Context, Data, Effect, Layer } from 'effect';\nimport { detect } from 'package-manager-detector/detect';\nimport { PackageJson, readPackage } from 'pkg-types';\n\nimport { exec } from 'child_process';\nimport { promisify } from 'util';\nimport { UI } from '../../ui/index.js';\nimport { findProjectDir } from '../../util/projectDir.js';\nimport { runUIEffect } from '../lib/ui.js';\n\nexport class ProjectInfo extends Context.Tag(\n 'instant-cli/new/context/projectInfo',\n)<\n ProjectInfo,\n {\n pkgDir: string;\n projectType: 'node' | 'deno';\n instantModuleName: string;\n }\n>() {}\n\nconst execAsync = promisify(exec);\n\nexport const PACKAGE_ALIAS_AND_FULL_NAMES = {\n react: '@instantdb/react',\n 'react-native': '@instantdb/react-native',\n core: '@instantdb/core',\n admin: '@instantdb/admin',\n};\n\nexport class ProjectInfoError extends Data.TaggedError('ProjectInfoError')<{\n message: string;\n cause?: unknown;\n}> {}\n\nconst getProjectInfo = (\n coerce: boolean = true,\n packageName?: keyof typeof PACKAGE_ALIAS_AND_FULL_NAMES,\n) =>\n Effect.gen(function* () {\n const projectDir = yield* Effect.tryPromise({\n try: () => findProjectDir(),\n catch: (e) =>\n new ProjectInfoError({ message: \"Couldn't get project dir\" }),\n });\n\n if (!projectDir) {\n return yield* new ProjectInfoError({\n message: \"Couldn't find a project directory (package.json)\",\n });\n }\n\n if (projectDir.type === 'deno') {\n return {\n pkgDir: projectDir.dir,\n projectType: projectDir.type,\n instantModuleName: '@instantdb/core',\n };\n }\n\n const pkgJson = yield* Effect.tryPromise({\n try: () => readPackage(),\n catch: () =>\n new ProjectInfoError({ message: \"Couldn't read package.json\" }),\n });\n\n let moduleName = getInstantModuleName(pkgJson);\n if (!moduleName && !coerce) {\n return yield* new ProjectInfoError({\n message: 'No instant client library installed',\n });\n }\n\n // TODO: Clean up with option\n const packageManager = yield* Effect.tryPromise(() => detect()).pipe(\n Effect.flatMap(Effect.fromNullable),\n Effect.mapError(\n () =>\n new ProjectInfoError({\n message: 'Failed to detect package manager',\n }),\n ),\n );\n\n if (!moduleName && coerce) {\n // install the packages\n if (packageName) {\n moduleName = PACKAGE_ALIAS_AND_FULL_NAMES[packageName];\n } else {\n moduleName = yield* runUIEffect(\n new UI.Select({\n promptText: 'Which package would you like to use?',\n options: [\n { label: '@instantdb/react', value: '@instantdb/react' },\n {\n label: '@instantdb/react-native',\n value: '@instantdb/react-native',\n },\n { label: '@instantdb/core', value: '@instantdb/core' },\n { label: '@instantdb/admin', value: '@instantdb/admin' },\n ],\n }),\n ).pipe(\n Effect.flatMap(Effect.fromNullable),\n Effect.mapError(\n () =>\n new ProjectInfoError({\n message: 'Failed to select package',\n }),\n ),\n );\n }\n const packagesToInstall = [moduleName];\n if (moduleName === '@instantdb/react-native') {\n packagesToInstall.push(\n 'react-native-get-random-values',\n '@react-native-async-storage/async-storage',\n );\n }\n const installCommand = getInstallCommand(\n packageManager.agent,\n packagesToInstall.join(' '),\n );\n console.log(installCommand);\n yield* runUIEffect(\n new UI.Spinner({\n promise: execAsync(installCommand, {\n cwd: projectDir.dir,\n }),\n errorText: 'Failed to install packages',\n workingText: `Installing ${packagesToInstall.join(', ')} using ${packageManager.agent}...`,\n doneText: `Installed ${packagesToInstall.join(', ')} using ${packageManager.agent}.`,\n }),\n );\n return {\n pkgDir: projectDir.dir,\n projectType: projectDir.type,\n instantModuleName: moduleName,\n };\n } else {\n return {\n pkgDir: projectDir.dir,\n projectType: projectDir.type,\n instantModuleName: moduleName!,\n };\n }\n });\n\nexport const ProjectInfoLive = (\n coerce: boolean = true,\n packageName?: keyof typeof PACKAGE_ALIAS_AND_FULL_NAMES,\n) => Layer.effect(ProjectInfo, getProjectInfo(coerce, packageName));\n\nfunction getInstantModuleName(pkgJson: PackageJson) {\n const deps = pkgJson.dependencies || {};\n const devDeps = pkgJson.devDependencies || {};\n const instantModuleName = [\n '@instantdb/react',\n '@instantdb/react-native',\n '@instantdb/core',\n '@instantdb/admin',\n ].find((name) => deps[name] || devDeps[name]);\n return instantModuleName;\n}\n\nfunction getInstallCommand(packageManager: string, moduleName: string) {\n if (packageManager === 'npm') {\n return `npm install ${moduleName}`;\n } else {\n return `${packageManager} add ${moduleName}`;\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
declare const BadArgsError_base: Schema.TaggedErrorClass<BadArgsError, "BadArgsError", {
|
|
3
|
+
readonly _tag: Schema.tag<"BadArgsError">;
|
|
4
|
+
} & {
|
|
5
|
+
message: typeof Schema.String;
|
|
6
|
+
}>;
|
|
7
|
+
export declare class BadArgsError extends BadArgsError_base {
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/new/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;;;AAEhC,qBAAa,YAAa,SAAQ,iBAIhC;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/new/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,OAAO,YAAa,SAAQ,MAAM,CAAC,WAAW,CAClD,cAAc,CACf,CAAC,cAAc,EAAE;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG","sourcesContent":["import { Schema } from 'effect';\n\nexport class BadArgsError extends Schema.TaggedError<BadArgsError>(\n 'BadArgsError',\n)('BadArgsError', {\n message: Schema.String,\n}) {}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Command } from '@commander-js/extra-typings';
|
|
2
|
+
export type ArgsFromCommand<C> = C extends Command<any, infer R, any> ? R : never;
|
|
3
|
+
export declare const initDef: Command<[], {
|
|
4
|
+
app?: string | undefined;
|
|
5
|
+
package?: string | undefined;
|
|
6
|
+
title?: string | undefined;
|
|
7
|
+
}, {}>;
|
|
8
|
+
export declare const initWithoutFilesDef: Command<[], {
|
|
9
|
+
title?: string | undefined;
|
|
10
|
+
orgId?: string | undefined;
|
|
11
|
+
temp?: true | undefined;
|
|
12
|
+
}, {}>;
|
|
13
|
+
export declare const loginDef: Command<[], {
|
|
14
|
+
print?: true | undefined;
|
|
15
|
+
headless?: true | undefined;
|
|
16
|
+
}, {}>;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/new/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAmB,MAAM,6BAA6B,CAAC;AAkBvE,MAAM,MAAM,eAAe,CAAC,CAAC,IAC3B,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAiBnD,eAAO,MAAM,OAAO;;;;MA2BhB,CAAC;AAEL,eAAO,MAAM,mBAAmB;;;;MAmB5B,CAAC;AAEL,eAAO,MAAM,QAAQ;;;MAYjB,CAAC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Option, program } from '@commander-js/extra-typings';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { Effect } from 'effect';
|
|
4
|
+
import version from '../version.js';
|
|
5
|
+
import { initCommand } from './commands/init.js';
|
|
6
|
+
import { initWithoutFilesCommand } from './commands/initWithoutFiles.js';
|
|
7
|
+
import { loginCommand } from './commands/login.js';
|
|
8
|
+
import { logoutCommand } from './commands/logout.js';
|
|
9
|
+
import { loadEnv } from '../util/loadEnv.js';
|
|
10
|
+
import { AuthLayerLive, BaseLayerLive, printRedErrors, WithAppLayer, } from './layer.js';
|
|
11
|
+
loadEnv();
|
|
12
|
+
program
|
|
13
|
+
.name('instant-cli')
|
|
14
|
+
.addOption(globalOption('-t --token <token>', 'Auth token override'))
|
|
15
|
+
.addOption(globalOption('-y --yes', "Answer 'yes' to all prompts"))
|
|
16
|
+
.addOption(globalOption('--env <file>', 'Use a specific .env file'))
|
|
17
|
+
.addOption(globalOption('-v --version', 'Print the version number', () => {
|
|
18
|
+
console.log(version);
|
|
19
|
+
process.exit(0);
|
|
20
|
+
}))
|
|
21
|
+
.addHelpOption(globalOption('-h --help', 'Print the help text for a command'))
|
|
22
|
+
.usage(`<command> ${chalk.dim('[options] [args]')}`);
|
|
23
|
+
// Command List
|
|
24
|
+
export const initDef = program
|
|
25
|
+
.command('init')
|
|
26
|
+
.description('Set up a new project.')
|
|
27
|
+
.option('-a --app <app-id>', 'If you have an existing app ID, we can pull schema and perms from there.')
|
|
28
|
+
.option('-p --package <react|react-native|core|admin>', 'Which package to automatically install if there is not one installed already.')
|
|
29
|
+
.option('--title <title>', 'Title for the created app')
|
|
30
|
+
.action((options) => {
|
|
31
|
+
return Effect.runPromise(initCommand(options).pipe(Effect.provide(WithAppLayer({
|
|
32
|
+
coerce: true,
|
|
33
|
+
title: options.title,
|
|
34
|
+
appId: options.app,
|
|
35
|
+
packageName: options.package,
|
|
36
|
+
applyEnv: true,
|
|
37
|
+
})), printRedErrors));
|
|
38
|
+
});
|
|
39
|
+
export const initWithoutFilesDef = program
|
|
40
|
+
.command('init-without-files')
|
|
41
|
+
.description('Generate a new app id and admin token pair without any files.')
|
|
42
|
+
.option('--title <title>', 'Title for the created app.')
|
|
43
|
+
.option('--org-id <org-id>', 'Organization id for app. Cannot be used with --temp flag.')
|
|
44
|
+
.option('--temp', 'Create a temporary app which will automatically delete itself after >24 hours.')
|
|
45
|
+
.action((opts) => {
|
|
46
|
+
return Effect.runPromise(initWithoutFilesCommand(opts).pipe(Effect.provide(AuthLayerLive), printRedErrors));
|
|
47
|
+
});
|
|
48
|
+
export const loginDef = program
|
|
49
|
+
.command('login')
|
|
50
|
+
.description('Log into your account')
|
|
51
|
+
.option('-p --print', 'Prints the auth token into the console.')
|
|
52
|
+
.option('--headless', 'Print the login URL instead of trying to open the browser')
|
|
53
|
+
.action(async (opts) => {
|
|
54
|
+
Effect.runPromise(loginCommand(opts).pipe(Effect.provide(BaseLayerLive), printRedErrors));
|
|
55
|
+
});
|
|
56
|
+
const _logoutDef = program
|
|
57
|
+
.command('logout')
|
|
58
|
+
.description('Log out of your Instant account')
|
|
59
|
+
.action(async () => {
|
|
60
|
+
Effect.runPromise(logoutCommand().pipe(Effect.provide(BaseLayerLive), printRedErrors));
|
|
61
|
+
});
|
|
62
|
+
//// Program setup /////
|
|
63
|
+
function globalOption(flags, description, argParser) {
|
|
64
|
+
const opt = new Option(flags, description);
|
|
65
|
+
if (argParser) {
|
|
66
|
+
opt.argParser(argParser);
|
|
67
|
+
}
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
// __global does not exist on `Option`,
|
|
70
|
+
// but we use it in `getLocalAndGlobalOptions`, to produce
|
|
71
|
+
// our own custom list of local and global options.
|
|
72
|
+
// For more info, see the original PR:
|
|
73
|
+
// https://github.com/instantdb/instant/pull/505
|
|
74
|
+
opt.__global = true;
|
|
75
|
+
return opt;
|
|
76
|
+
}
|
|
77
|
+
function getLocalAndGlobalOptions(cmd, helper) {
|
|
78
|
+
const mixOfLocalAndGlobal = helper.visibleOptions(cmd);
|
|
79
|
+
const localOptionsFromMix = mixOfLocalAndGlobal.filter((option) => !option.__global);
|
|
80
|
+
const globalOptionsFromMix = mixOfLocalAndGlobal.filter((option) => option.__global);
|
|
81
|
+
const globalOptions = helper.visibleGlobalOptions(cmd);
|
|
82
|
+
return [localOptionsFromMix, globalOptionsFromMix.concat(globalOptions)];
|
|
83
|
+
}
|
|
84
|
+
function formatHelp(cmd, helper) {
|
|
85
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
86
|
+
const helpWidth = helper.helpWidth || 80;
|
|
87
|
+
const itemIndentWidth = 2;
|
|
88
|
+
const itemSeparatorWidth = 2; // between term and description
|
|
89
|
+
function formatItem(term, description) {
|
|
90
|
+
if (description) {
|
|
91
|
+
const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
|
|
92
|
+
return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
|
|
93
|
+
}
|
|
94
|
+
return term;
|
|
95
|
+
}
|
|
96
|
+
function formatList(textArray) {
|
|
97
|
+
return textArray.join('\n').replace(/^/gm, ' '.repeat(itemIndentWidth));
|
|
98
|
+
}
|
|
99
|
+
// Usage
|
|
100
|
+
let output = [`${helper.commandUsage(cmd)}`, ''];
|
|
101
|
+
// Description
|
|
102
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
103
|
+
if (commandDescription.length > 0) {
|
|
104
|
+
output = output.concat([helper.wrap(commandDescription, helpWidth, 0), '']);
|
|
105
|
+
}
|
|
106
|
+
// Arguments
|
|
107
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
108
|
+
return formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument));
|
|
109
|
+
});
|
|
110
|
+
if (argumentList.length > 0) {
|
|
111
|
+
output = output.concat([
|
|
112
|
+
chalk.dim.bold('Arguments'),
|
|
113
|
+
formatList(argumentList),
|
|
114
|
+
'',
|
|
115
|
+
]);
|
|
116
|
+
}
|
|
117
|
+
const [visibleOptions, visibleGlobalOptions] = getLocalAndGlobalOptions(cmd, helper);
|
|
118
|
+
// Options
|
|
119
|
+
const optionList = visibleOptions.map((option) => {
|
|
120
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
121
|
+
});
|
|
122
|
+
if (optionList.length > 0) {
|
|
123
|
+
output = output.concat([
|
|
124
|
+
chalk.dim.bold('Options'),
|
|
125
|
+
formatList(optionList),
|
|
126
|
+
'',
|
|
127
|
+
]);
|
|
128
|
+
}
|
|
129
|
+
// Commands
|
|
130
|
+
const commandList = helper.visibleCommands(cmd).map((cmd) => {
|
|
131
|
+
return formatItem(helper.subcommandTerm(cmd), helper.subcommandDescription(cmd));
|
|
132
|
+
});
|
|
133
|
+
if (commandList.length > 0) {
|
|
134
|
+
output = output.concat([
|
|
135
|
+
chalk.dim.bold('Commands'),
|
|
136
|
+
formatList(commandList),
|
|
137
|
+
'',
|
|
138
|
+
]);
|
|
139
|
+
}
|
|
140
|
+
if (this.showGlobalOptions) {
|
|
141
|
+
const globalOptionList = visibleGlobalOptions.map((option) => {
|
|
142
|
+
return formatItem(helper.optionTerm(option), helper.optionDescription(option));
|
|
143
|
+
});
|
|
144
|
+
if (globalOptionList.length > 0) {
|
|
145
|
+
output = output.concat([
|
|
146
|
+
chalk.dim.bold('Global Options'),
|
|
147
|
+
formatList(globalOptionList),
|
|
148
|
+
'',
|
|
149
|
+
]);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return output.join('\n');
|
|
153
|
+
}
|
|
154
|
+
program.configureHelp({
|
|
155
|
+
showGlobalOptions: true,
|
|
156
|
+
formatHelp,
|
|
157
|
+
});
|
|
158
|
+
program.parse(process.argv);
|
|
159
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,EAAE,EAAE;QAC1D,OAAO,UAAU,CACf,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,EAC1B,MAAM,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAClC,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;YACrB,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC;YAC1B,UAAU,CAAC,WAAW,CAAC;YACvB,EAAE;SACH,CAAC,CAAC;IACL,CAAC;IAED,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC3B,MAAM,gBAAgB,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YAC3D,OAAO,UAAU,CACf,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EACzB,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,CACjC,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;gBACrB,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC;gBAChC,UAAU,CAAC,gBAAgB,CAAC;gBAC5B,EAAE;aACH,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,OAAO,CAAC,aAAa,CAAC;IACpB,iBAAiB,EAAE,IAAI;IACvB,UAAU;CACX,CAAC,CAAC;AAEH,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC","sourcesContent":["import { Command, Option, program } from '@commander-js/extra-typings';\nimport chalk from 'chalk';\nimport { Effect } from 'effect';\nimport version from '../version.js';\nimport { initCommand } from './commands/init.js';\nimport { initWithoutFilesCommand } from './commands/initWithoutFiles.js';\nimport { loginCommand } from './commands/login.js';\nimport { logoutCommand } from './commands/logout.js';\nimport { loadEnv } from '../util/loadEnv.js';\nimport {\n AuthLayerLive,\n BaseLayerLive,\n printRedErrors,\n WithAppLayer,\n} from './layer.js';\n\nloadEnv();\n\nexport type ArgsFromCommand<C> =\n C extends Command<any, infer R, any> ? R : never;\n\nprogram\n .name('instant-cli')\n .addOption(globalOption('-t --token <token>', 'Auth token override'))\n .addOption(globalOption('-y --yes', \"Answer 'yes' to all prompts\"))\n .addOption(globalOption('--env <file>', 'Use a specific .env file'))\n .addOption(\n globalOption('-v --version', 'Print the version number', () => {\n console.log(version);\n process.exit(0);\n }),\n )\n .addHelpOption(globalOption('-h --help', 'Print the help text for a command'))\n .usage(`<command> ${chalk.dim('[options] [args]')}`);\n\n// Command List\nexport const initDef = program\n .command('init')\n .description('Set up a new project.')\n .option(\n '-a --app <app-id>',\n 'If you have an existing app ID, we can pull schema and perms from there.',\n )\n .option(\n '-p --package <react|react-native|core|admin>',\n 'Which package to automatically install if there is not one installed already.',\n )\n .option('--title <title>', 'Title for the created app')\n .action((options) => {\n return Effect.runPromise(\n initCommand(options).pipe(\n Effect.provide(\n WithAppLayer({\n coerce: true,\n title: options.title,\n appId: options.app,\n packageName: options.package as any,\n applyEnv: true,\n }),\n ),\n printRedErrors,\n ),\n );\n });\n\nexport const initWithoutFilesDef = program\n .command('init-without-files')\n .description('Generate a new app id and admin token pair without any files.')\n .option('--title <title>', 'Title for the created app.')\n .option(\n '--org-id <org-id>',\n 'Organization id for app. Cannot be used with --temp flag.',\n )\n .option(\n '--temp',\n 'Create a temporary app which will automatically delete itself after >24 hours.',\n )\n .action((opts) => {\n return Effect.runPromise(\n initWithoutFilesCommand(opts).pipe(\n Effect.provide(AuthLayerLive),\n printRedErrors,\n ),\n );\n });\n\nexport const loginDef = program\n .command('login')\n .description('Log into your account')\n .option('-p --print', 'Prints the auth token into the console.')\n .option(\n '--headless',\n 'Print the login URL instead of trying to open the browser',\n )\n .action(async (opts) => {\n Effect.runPromise(\n loginCommand(opts).pipe(Effect.provide(BaseLayerLive), printRedErrors),\n );\n });\n\nconst _logoutDef = program\n .command('logout')\n .description('Log out of your Instant account')\n .action(async () => {\n Effect.runPromise(\n logoutCommand().pipe(Effect.provide(BaseLayerLive), printRedErrors),\n );\n });\n\n//// Program setup /////\n\nfunction globalOption(\n flags: string,\n description?: string,\n argParser?: (value: string, prev?: unknown) => unknown,\n) {\n const opt = new Option(flags, description);\n if (argParser) {\n opt.argParser(argParser);\n }\n // @ts-ignore\n // __global does not exist on `Option`,\n // but we use it in `getLocalAndGlobalOptions`, to produce\n // our own custom list of local and global options.\n // For more info, see the original PR:\n // https://github.com/instantdb/instant/pull/505\n opt.__global = true;\n return opt;\n}\n\nfunction getLocalAndGlobalOptions(cmd, helper) {\n const mixOfLocalAndGlobal = helper.visibleOptions(cmd);\n const localOptionsFromMix = mixOfLocalAndGlobal.filter(\n (option) => !option.__global,\n );\n const globalOptionsFromMix = mixOfLocalAndGlobal.filter(\n (option) => option.__global,\n );\n const globalOptions = helper.visibleGlobalOptions(cmd);\n\n return [localOptionsFromMix, globalOptionsFromMix.concat(globalOptions)];\n}\n\nfunction formatHelp(cmd, helper) {\n const termWidth = helper.padWidth(cmd, helper);\n const helpWidth = helper.helpWidth || 80;\n const itemIndentWidth = 2;\n const itemSeparatorWidth = 2; // between term and description\n function formatItem(term, description) {\n if (description) {\n const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;\n return helper.wrap(\n fullText,\n helpWidth - itemIndentWidth,\n termWidth + itemSeparatorWidth,\n );\n }\n return term;\n }\n function formatList(textArray) {\n return textArray.join('\\n').replace(/^/gm, ' '.repeat(itemIndentWidth));\n }\n\n // Usage\n let output = [`${helper.commandUsage(cmd)}`, ''];\n\n // Description\n const commandDescription = helper.commandDescription(cmd);\n if (commandDescription.length > 0) {\n output = output.concat([helper.wrap(commandDescription, helpWidth, 0), '']);\n }\n\n // Arguments\n const argumentList = helper.visibleArguments(cmd).map((argument) => {\n return formatItem(\n helper.argumentTerm(argument),\n helper.argumentDescription(argument),\n );\n });\n if (argumentList.length > 0) {\n output = output.concat([\n chalk.dim.bold('Arguments'),\n formatList(argumentList),\n '',\n ]);\n }\n const [visibleOptions, visibleGlobalOptions] = getLocalAndGlobalOptions(\n cmd,\n helper,\n );\n\n // Options\n const optionList = visibleOptions.map((option) => {\n return formatItem(\n helper.optionTerm(option),\n helper.optionDescription(option),\n );\n });\n if (optionList.length > 0) {\n output = output.concat([\n chalk.dim.bold('Options'),\n formatList(optionList),\n '',\n ]);\n }\n // Commands\n const commandList = helper.visibleCommands(cmd).map((cmd) => {\n return formatItem(\n helper.subcommandTerm(cmd),\n helper.subcommandDescription(cmd),\n );\n });\n if (commandList.length > 0) {\n output = output.concat([\n chalk.dim.bold('Commands'),\n formatList(commandList),\n '',\n ]);\n }\n\n if (this.showGlobalOptions) {\n const globalOptionList = visibleGlobalOptions.map((option) => {\n return formatItem(\n helper.optionTerm(option),\n helper.optionDescription(option),\n );\n });\n if (globalOptionList.length > 0) {\n output = output.concat([\n chalk.dim.bold('Global Options'),\n formatList(globalOptionList),\n '',\n ]);\n }\n }\n\n return output.join('\\n');\n}\n\nprogram.configureHelp({\n showGlobalOptions: true,\n formatHelp,\n});\n\nprogram.parse(process.argv);\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NodeContext } from '@effect/platform-node';
|
|
2
|
+
import { Effect, Layer } from 'effect';
|
|
3
|
+
import { PlatformApi } from './context/platformApi.js';
|
|
4
|
+
import { PACKAGE_ALIAS_AND_FULL_NAMES } from './context/projectInfo.js';
|
|
5
|
+
export declare const printRedErrors: <A, R>(self: Effect.Effect<A, unknown, R>) => Effect.Effect<void | A, never, R>;
|
|
6
|
+
export declare const BaseLayerLive: Layer.Layer<import("./context/globalOpts.js").GlobalOpts | import("./lib/http.js").InstantHttp | PlatformApi | NodeContext.NodeContext, import("effect/ConfigError").ConfigError, never>;
|
|
7
|
+
export declare const AuthLayerLive: Layer.Layer<import("./context/globalOpts.js").GlobalOpts | import("./lib/http.js").InstantHttp | import("./context/authToken.js").AuthToken | import("./lib/http.js").InstantHttpAuthed | PlatformApi | NodeContext.NodeContext, import("@effect/platform/Error").PlatformError | import("effect/ConfigError").ConfigError | import("./context/authToken.js").NotAuthedError, never>;
|
|
8
|
+
export declare const WithAppLayer: (args: {
|
|
9
|
+
appId?: string;
|
|
10
|
+
title?: string;
|
|
11
|
+
coerce: boolean;
|
|
12
|
+
packageName: keyof typeof PACKAGE_ALIAS_AND_FULL_NAMES;
|
|
13
|
+
applyEnv?: boolean;
|
|
14
|
+
}) => Layer.Layer<import("./context/globalOpts.js").GlobalOpts | import("./context/projectInfo.js").ProjectInfo | import("./lib/http.js").InstantHttp | import("./context/authToken.js").AuthToken | import("./lib/http.js").InstantHttpAuthed | PlatformApi | import("./context/currentApp.js").CurrentApp | NodeContext.NodeContext, import("./lib/ui.js").UIError | import("./context/projectInfo.js").ProjectInfoError | import("@effect/platform/HttpClientError").HttpClientError | import("effect/ParseResult").ParseError | import("@effect/platform/HttpBody").HttpBodyError | import("@effect/platform/Error").PlatformError | import("effect/ConfigError").ConfigError | import("./context/authToken.js").NotAuthedError | import("./context/currentApp.js").CurrentAppContextError | import("./context/currentApp.js").AppNotFoundError, never>;
|
|
15
|
+
//# sourceMappingURL=layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer.d.ts","sourceRoot":"","sources":["../../src/new/layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,uBAAuB,CAAC;AAEpE,OAAO,EAAkB,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAGvD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EACL,4BAA4B,EAE7B,MAAM,0BAA0B,CAAC;AAGlC,eAAO,MAAM,cAAc,iFAkBzB,CAAC;AAcH,eAAO,MAAM,aAAa,0LAGzB,CAAC;AAGF,eAAO,MAAM,aAAa,sXAMzB,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,MAAM;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,MAAM,OAAO,4BAA4B,CAAC;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,0zBAYE,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { NodeContext, NodeHttpClient } from '@effect/platform-node';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { Cause, Console, Effect, Layer } from 'effect';
|
|
4
|
+
import { InstantHttpAuthedLive, InstantHttpLive } from './lib/http.js';
|
|
5
|
+
import { AuthTokenLive } from './context/authToken.js';
|
|
6
|
+
import { PlatformApi } from './context/platformApi.js';
|
|
7
|
+
import { GlobalOptsLive } from './context/globalOpts.js';
|
|
8
|
+
import { ProjectInfoLive, } from './context/projectInfo.js';
|
|
9
|
+
import { CurrentAppLive } from './context/currentApp.js';
|
|
10
|
+
export const printRedErrors = Effect.catchAllCause((cause) => {
|
|
11
|
+
const failure = Cause.failureOption(cause);
|
|
12
|
+
// Print just the message if the error has a message attribute and no cause
|
|
13
|
+
if (failure._tag === 'Some' &&
|
|
14
|
+
typeof failure.value === 'object' &&
|
|
15
|
+
failure.value !== null &&
|
|
16
|
+
'message' in failure.value &&
|
|
17
|
+
!('cause' in failure.value)) {
|
|
18
|
+
return Console.error(chalk.red(failure.value.message));
|
|
19
|
+
}
|
|
20
|
+
return Console.error(chalk.red(Cause.pretty(cause, { renderErrorCause: true })));
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Note:
|
|
24
|
+
Avoid Duplicate Layer Creation
|
|
25
|
+
|
|
26
|
+
Layers are memoized using reference equality. Therefore, if you have a layer that is created by calling a function like f(), you should only call that f once and re-use the resulting layer so that you are always using the same instance.
|
|
27
|
+
*/
|
|
28
|
+
// Base layers
|
|
29
|
+
const AuthTokenLayer = Layer.provide(AuthTokenLive, NodeContext.layer);
|
|
30
|
+
const InstantHttpLayer = Layer.provide(InstantHttpLive, NodeHttpClient.layer);
|
|
31
|
+
// Unauthenticated layer with InstantHttp + PlatformApi + GlobalOpts + NodeContext
|
|
32
|
+
export const BaseLayerLive = Layer.provideMerge(Layer.mergeAll(InstantHttpLayer, PlatformApi.Default, GlobalOptsLive), NodeContext.layer);
|
|
33
|
+
// Authenticated layer extends BaseLayerLive with InstantHttpAuthed
|
|
34
|
+
export const AuthLayerLive = Layer.provideMerge(Layer.provideMerge(InstantHttpAuthedLive, Layer.merge(AuthTokenLayer, InstantHttpLayer)), BaseLayerLive);
|
|
35
|
+
export const WithAppLayer = (args) => Layer.mergeAll(CurrentAppLive({
|
|
36
|
+
coerce: args.coerce,
|
|
37
|
+
appId: args.appId,
|
|
38
|
+
title: args.title,
|
|
39
|
+
applyEnv: args.applyEnv,
|
|
40
|
+
})).pipe(Layer.provideMerge(GlobalOptsLive), Layer.provideMerge(AuthLayerLive), Layer.provideMerge(ProjectInfoLive(args.coerce, args.packageName)));
|
|
41
|
+
//# sourceMappingURL=layer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layer.js","sourceRoot":"","sources":["../../src/new/layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,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AAEF,mEAAmE;AACnE,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC,YAAY,CAC7C,KAAK,CAAC,YAAY,CAChB,qBAAqB,EACrB,KAAK,CAAC,KAAK,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAC9C,EACD,aAAa,CACd,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAM5B,EAAE,EAAE,CACH,KAAK,CAAC,QAAQ,CACZ,cAAc,CAAC;IACb,MAAM,EAAE,IAAI,CAAC,MAAM;IACnB,KAAK,EAAE,IAAI,CAAC,KAAK;IACjB,KAAK,EAAE,IAAI,CAAC,KAAK;IACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;CACxB,CAAC,CACH,CAAC,IAAI,CACJ,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,EAClC,KAAK,CAAC,YAAY,CAAC,aAAa,CAAC,EACjC,KAAK,CAAC,YAAY,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CACnE,CAAC","sourcesContent":["import { NodeContext, NodeHttpClient } from '@effect/platform-node';\nimport chalk from 'chalk';\nimport { Cause, Console, Effect, Layer } from 'effect';\nimport { InstantHttpAuthedLive, InstantHttpLive } from './lib/http.js';\nimport { AuthTokenLive } from './context/authToken.js';\nimport { PlatformApi } from './context/platformApi.js';\nimport { GlobalOptsLive } from './context/globalOpts.js';\nimport {\n PACKAGE_ALIAS_AND_FULL_NAMES,\n ProjectInfoLive,\n} from './context/projectInfo.js';\nimport { CurrentAppLive } from './context/currentApp.js';\n\nexport const printRedErrors = Effect.catchAllCause((cause) => {\n const failure = Cause.failureOption(cause);\n\n // Print just the message if the error has a message attribute and no cause\n if (\n failure._tag === 'Some' &&\n typeof failure.value === 'object' &&\n failure.value !== null &&\n 'message' in failure.value &&\n !('cause' in failure.value)\n ) {\n return Console.error(\n chalk.red((failure.value as { message: string }).message),\n );\n }\n return Console.error(\n chalk.red(Cause.pretty(cause, { renderErrorCause: true })),\n );\n});\n\n/**\n * Note:\n Avoid Duplicate Layer Creation\n\n Layers are memoized using reference equality. Therefore, if you have a layer that is created by calling a function like f(), you should only call that f once and re-use the resulting layer so that you are always using the same instance.\n */\n\n// Base layers\nconst AuthTokenLayer = Layer.provide(AuthTokenLive, NodeContext.layer);\nconst InstantHttpLayer = Layer.provide(InstantHttpLive, NodeHttpClient.layer);\n\n// Unauthenticated layer with InstantHttp + PlatformApi + GlobalOpts + NodeContext\nexport const BaseLayerLive = Layer.provideMerge(\n Layer.mergeAll(InstantHttpLayer, PlatformApi.Default, GlobalOptsLive),\n NodeContext.layer,\n);\n\n// Authenticated layer extends BaseLayerLive with InstantHttpAuthed\nexport const AuthLayerLive = Layer.provideMerge(\n Layer.provideMerge(\n InstantHttpAuthedLive,\n Layer.merge(AuthTokenLayer, InstantHttpLayer),\n ),\n BaseLayerLive,\n);\n\nexport const WithAppLayer = (args: {\n appId?: string;\n title?: string;\n coerce: boolean;\n packageName: keyof typeof PACKAGE_ALIAS_AND_FULL_NAMES;\n applyEnv?: boolean;\n}) =>\n Layer.mergeAll(\n CurrentAppLive({\n coerce: args.coerce,\n appId: args.appId,\n title: args.title,\n applyEnv: args.applyEnv,\n }),\n ).pipe(\n Layer.provideMerge(GlobalOptsLive),\n Layer.provideMerge(AuthLayerLive),\n Layer.provideMerge(ProjectInfoLive(args.coerce, args.packageName)),\n );\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { InstantHttpAuthed } from './http.js';
|
|
3
|
+
export declare const createApp: (title: string, orgId?: string | undefined) => Effect.Effect<unknown, import("@effect/platform/HttpClientError").HttpClientError | import("@effect/platform/HttpBody").HttpBodyError, InstantHttpAuthed>;
|
|
4
|
+
//# sourceMappingURL=createApp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createApp.d.ts","sourceRoot":"","sources":["../../../src/new/lib/createApp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAG9C,eAAO,MAAM,SAAS,0MAYpB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
import { Effect } from 'effect';
|
|
3
|
+
import { InstantHttpAuthed } from './http.js';
|
|
4
|
+
import { HttpClientRequest } from '@effect/platform';
|
|
5
|
+
export const createApp = Effect.fn(function* (title, orgId) {
|
|
6
|
+
const http = yield* InstantHttpAuthed;
|
|
7
|
+
const id = randomUUID();
|
|
8
|
+
const token = randomUUID();
|
|
9
|
+
const app = { id, title, admin_token: token, org_id: orgId };
|
|
10
|
+
const res = yield* HttpClientRequest.post('/dash/apps').pipe(HttpClientRequest.bodyJson(app), Effect.flatMap(http.execute), Effect.flatMap((res) => res.json));
|
|
11
|
+
return res;
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=createApp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createApp.js","sourceRoot":"","sources":["../../../src/new/lib/createApp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAa,EAAE,KAAc;IACzE,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,iBAAiB,CAAC;IACtC,MAAM,EAAE,GAAG,UAAU,EAAE,CAAC;IACxB,MAAM,KAAK,GAAG,UAAU,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAE7D,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAC1D,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAC/B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAC5B,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAClC,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC,CAAC,CAAC","sourcesContent":["import { randomUUID } from 'crypto';\nimport { Effect } from 'effect';\nimport { InstantHttpAuthed } from './http.js';\nimport { HttpClientRequest } from '@effect/platform';\n\nexport const createApp = Effect.fn(function* (title: string, orgId?: string) {\n const http = yield* InstantHttpAuthed;\n const id = randomUUID();\n const token = randomUUID();\n const app = { id, title, admin_token: token, org_id: orgId };\n\n const res = yield* HttpClientRequest.post('/dash/apps').pipe(\n HttpClientRequest.bodyJson(app),\n Effect.flatMap(http.execute),\n Effect.flatMap((res) => res.json),\n );\n return res;\n});\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { CurrentAppInfo } from '../context/currentApp.js';
|
|
3
|
+
import { ProjectInfo } from '../context/projectInfo.js';
|
|
4
|
+
import { GlobalOpts } from '../context/globalOpts.js';
|
|
5
|
+
import { FileSystem, Path } from '@effect/platform';
|
|
6
|
+
export declare const handleEnv: (app: CurrentAppInfo) => Effect.Effect<void, import("@effect/platform/Error").PlatformError | import("effect/ConfigError").ConfigError, GlobalOpts | ProjectInfo | FileSystem.FileSystem | Path.Path>;
|
|
7
|
+
//# sourceMappingURL=handleEnv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleEnv.d.ts","sourceRoot":"","sources":["../../../src/new/lib/handleEnv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,cAAc,EAAiB,MAAM,0BAA0B,CAAC;AACzE,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;AAMpD,eAAO,MAAM,SAAS,uMAmDpB,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { potentialEnvs } from '../context/currentApp.js';
|
|
3
|
+
import { ProjectInfo, ProjectInfoError } from '../context/projectInfo.js';
|
|
4
|
+
import { readPackage } from 'pkg-types';
|
|
5
|
+
import { GlobalOpts } from '../context/globalOpts.js';
|
|
6
|
+
import { FileSystem, Path } from '@effect/platform';
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import terminalLink from 'terminal-link';
|
|
9
|
+
import { getDashUrl } from './http.js';
|
|
10
|
+
import { promptOk } from './ui.js';
|
|
11
|
+
export const handleEnv = Effect.fn(function* (app) {
|
|
12
|
+
const opts = yield* GlobalOpts;
|
|
13
|
+
const { pkgDir } = yield* ProjectInfo;
|
|
14
|
+
const envType = yield* detectEnvType;
|
|
15
|
+
const envName = potentialEnvs[envType];
|
|
16
|
+
const envFile = opts.env ?? '.env';
|
|
17
|
+
const fs = yield* FileSystem.FileSystem;
|
|
18
|
+
const path = yield* Path.Path;
|
|
19
|
+
const hasEnvFile = yield* fs.exists(path.join(pkgDir, envFile));
|
|
20
|
+
const dashOrigin = yield* getDashUrl;
|
|
21
|
+
if (hasEnvFile) {
|
|
22
|
+
return printDotEnvInfo(envType, app.appId, dashOrigin);
|
|
23
|
+
}
|
|
24
|
+
console.log(`\nLooks like you don't have a ${chalk.green(`\`${envFile}\``)} file yet.`);
|
|
25
|
+
console.log(`If we set ${chalk.green(envName)} & ${chalk.green('INSTANT_APP_ADMIN_TOKEN')}, we can remember the app that you chose for all future commands.`);
|
|
26
|
+
const saveExtraInfo = envFile !== '.env' ? chalk.green(' (will create `' + envFile + '`)') : '';
|
|
27
|
+
const ok = yield* promptOk({
|
|
28
|
+
inline: true,
|
|
29
|
+
promptText: 'Want us to create this env file for you?' + saveExtraInfo,
|
|
30
|
+
modifyOutput: (a) => a,
|
|
31
|
+
}, true);
|
|
32
|
+
if (!ok) {
|
|
33
|
+
console.log(`No .env file created. You can always set ${chalk.green('`' + envName + '`')} later. \n`);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const content = [
|
|
37
|
+
[envName, app.appId],
|
|
38
|
+
['INSTANT_APP_ADMIN_TOKEN', app.adminToken],
|
|
39
|
+
]
|
|
40
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
41
|
+
.join('\n') + '\n';
|
|
42
|
+
yield* fs.writeFileString(path.join(pkgDir, envFile), content);
|
|
43
|
+
if (envFile !== '.env') {
|
|
44
|
+
console.log(`Created ${chalk.green(envFile)}!`);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.log(`Created ${chalk.green('.env')} file!`);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
const detectEnvType = Effect.gen(function* () {
|
|
51
|
+
const pkgJson = yield* Effect.tryPromise({
|
|
52
|
+
try: () => readPackage(),
|
|
53
|
+
catch: () => new ProjectInfoError({ message: "Couldn't read package.json" }),
|
|
54
|
+
});
|
|
55
|
+
if (pkgJson.dependencies?.next) {
|
|
56
|
+
return 'next';
|
|
57
|
+
}
|
|
58
|
+
if (pkgJson.devDependencies?.svelte) {
|
|
59
|
+
return 'svelte';
|
|
60
|
+
}
|
|
61
|
+
if (pkgJson.devDependencies?.vite) {
|
|
62
|
+
return 'vite';
|
|
63
|
+
}
|
|
64
|
+
if (pkgJson.dependencies?.expo) {
|
|
65
|
+
return 'expo';
|
|
66
|
+
}
|
|
67
|
+
if (pkgJson.dependencies?.nuxt) {
|
|
68
|
+
return 'nuxt';
|
|
69
|
+
}
|
|
70
|
+
return 'catchall';
|
|
71
|
+
}).pipe(Effect.catchTag('ProjectInfoError', () => Effect.succeed('catchall')));
|
|
72
|
+
function printDotEnvInfo(envType, appId, dashOrigin) {
|
|
73
|
+
console.log(`\nPicked app ${chalk.green(appId)}!\n`);
|
|
74
|
+
console.log(`To use this app automatically from now on, update your ${chalk.green('`.env`')} file:`);
|
|
75
|
+
const picked = potentialEnvs[envType];
|
|
76
|
+
const rest = { ...potentialEnvs };
|
|
77
|
+
delete rest[envType];
|
|
78
|
+
console.log(` ${chalk.green(picked)}=${appId}`);
|
|
79
|
+
const otherEnvs = Object.values(rest);
|
|
80
|
+
otherEnvs.sort();
|
|
81
|
+
const otherEnvStr = otherEnvs.map((x) => ' ' + chalk.green(x)).join('\n');
|
|
82
|
+
console.log(`Alternative names: \n${otherEnvStr} \n`);
|
|
83
|
+
console.log(terminalLink('Dashboard:', appDashUrl(appId, dashOrigin)) + '\n');
|
|
84
|
+
}
|
|
85
|
+
function appDashUrl(id, instantOrigin) {
|
|
86
|
+
return `${instantOrigin}/dash?s=main&t=home&app=${id}`;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=handleEnv.js.map
|