@liquidmetal-ai/raindrop 0.2.6 → 0.2.8

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/dist/deploy.js ADDED
@@ -0,0 +1,175 @@
1
+ import { create } from '@bufbuild/protobuf';
2
+ import { Code, ConnectError } from '@connectrpc/connect';
3
+ import { valueOf } from '@liquidmetal-ai/drizzle/appify/build';
4
+ import { listEnvVars } from '@liquidmetal-ai/drizzle/appify/index';
5
+ import { archive } from '@liquidmetal-ai/drizzle/codestore';
6
+ import { BundleArchiveType, ReleaseRequest_LockSchema, } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/catalog_pb';
7
+ import { FileSystemBundle } from '@liquidmetal-ai/drizzle/unsafe/codestore';
8
+ import fs from 'node:fs/promises';
9
+ import * as path from 'node:path';
10
+ import { buildHandlers } from './build.js';
11
+ export async function deploy(options) {
12
+ const { command, root, manifest, output } = options;
13
+ // Build paths
14
+ const manifestPath = path.isAbsolute(manifest) ? manifest : path.join(root, manifest);
15
+ const buildDir = path.isAbsolute(output) ? output : path.join(root, output);
16
+ // Load applications from manifest
17
+ const apps = await command.loadManifest();
18
+ if (apps[0] === undefined) {
19
+ command.error('There are no applications in the manifest');
20
+ // Unreachable but here to satisfy TypeScript
21
+ return '';
22
+ }
23
+ const app = apps[0];
24
+ const manifestContents = await fs.readFile(manifestPath, 'utf8');
25
+ // Build handlers
26
+ await buildHandlers(command, apps, buildDir, root);
27
+ // Prepare deployment parameters
28
+ const runtimeVersion = await command.raindropFrameworkVersion();
29
+ const { client: catalogService, userId, organizationId: defaultOrganizationId } = await command.catalogService();
30
+ const organizationId = options.impersonate ?? defaultOrganizationId;
31
+ // Deploy the application
32
+ let deployResp;
33
+ try {
34
+ deployResp = await catalogService.deploy({
35
+ userId,
36
+ organizationId,
37
+ applications: [
38
+ {
39
+ application: valueOf(app.name),
40
+ previousVersionId: options.previousVersionId,
41
+ currentVersionId: options.currentVersionId,
42
+ branch: options.branch,
43
+ amend: options.amend,
44
+ metadata: {
45
+ runtimeVersion,
46
+ },
47
+ manifest: manifestContents,
48
+ lock: options.lock,
49
+ },
50
+ ],
51
+ });
52
+ }
53
+ catch (err) {
54
+ if (err instanceof ConnectError && err.code === Code.FailedPrecondition) {
55
+ command.error(`Failed to ${options.amend ? 'amend' : 'deploy'} ${valueOf(app.name)}@${options.previousVersionId}=>${options.currentVersionId}: ${err.message}`);
56
+ }
57
+ throw err;
58
+ }
59
+ if (deployResp.applications[0] === undefined) {
60
+ command.error('Failed to deploy application');
61
+ }
62
+ // Get the version ID from the response
63
+ const currentVersionId = deployResp.applications[0].currentVersionId;
64
+ if (!currentVersionId) {
65
+ command.error('Failed to retrieve current version ID from deployment response.');
66
+ }
67
+ // Get the lock from the response
68
+ const lock = deployResp.applications[0].lock;
69
+ // Save config
70
+ const config = await command.loadConfig();
71
+ config.versionId = currentVersionId;
72
+ config.lock = lock;
73
+ await command.saveConfig(config);
74
+ // Check environment variables
75
+ await checkEnvironmentVariables(command, app, catalogService, userId, organizationId, currentVersionId);
76
+ // Upload bundles
77
+ await uploadBundles(command, app, buildDir, catalogService, userId, organizationId, currentVersionId);
78
+ // Upload DB bundle if it exists
79
+ await uploadDbBundle(command, root, catalogService, userId, organizationId, app, currentVersionId);
80
+ // Set application active if requested
81
+ if (options.start) {
82
+ await catalogService.setActive({
83
+ userId,
84
+ organizationId,
85
+ applications: deployResp.applications.map((a) => ({
86
+ applicationName: a.applicationName,
87
+ currentVersionId: a.currentVersionId,
88
+ isActive: options.start,
89
+ })),
90
+ });
91
+ }
92
+ // Release locks
93
+ await catalogService.release({
94
+ userId,
95
+ organizationId,
96
+ locks: deployResp.applications.map((a) => create(ReleaseRequest_LockSchema, {
97
+ applicationName: a.applicationName,
98
+ currentVersionId: a.currentVersionId,
99
+ lock: a.lock,
100
+ })),
101
+ });
102
+ // Clear the lock in the config
103
+ config.lock = undefined;
104
+ await command.saveConfig(config);
105
+ return currentVersionId;
106
+ }
107
+ async function checkEnvironmentVariables(command, app, catalogService, userId, organizationId, currentVersionId) {
108
+ const envVars = listEnvVars(app);
109
+ if (Object.keys(envVars).length > 0) {
110
+ const getEnvsResp = await catalogService.getEnvs({
111
+ userId,
112
+ organizationId,
113
+ envs: Object.keys(envVars).map((key) => ({
114
+ applicationName: valueOf(app.name),
115
+ currentVersionId,
116
+ key,
117
+ })),
118
+ });
119
+ let unset = false;
120
+ const remoteEnvVars = Object.fromEntries(getEnvsResp.envs.map((env) => [env.key, env.value]));
121
+ for (const key of Object.keys(envVars)) {
122
+ const manifestDefault = envVars[key]?.default;
123
+ const remoteValue = remoteEnvVars[key];
124
+ if (remoteValue === undefined && manifestDefault === undefined) {
125
+ if (!unset) {
126
+ command.warn(`The following environment variables were not set and are required for deployment:`);
127
+ }
128
+ unset = true;
129
+ command.warn(key);
130
+ }
131
+ }
132
+ if (unset) {
133
+ command.error('Please set the above environment variables before deploying. You can resume using `raindrop build deploy --resume`');
134
+ }
135
+ }
136
+ }
137
+ async function uploadBundles(command, app, buildDir, catalogService, userId, organizationId, currentVersionId) {
138
+ for (const handler of app.handlers()) {
139
+ const bundle = new FileSystemBundle(path.join(buildDir, valueOf(handler.name)));
140
+ await catalogService.uploadBundle({
141
+ userId,
142
+ organizationId,
143
+ applicationName: valueOf(app.name),
144
+ applicationVersionId: currentVersionId,
145
+ archiveType: BundleArchiveType.ZIP,
146
+ bundleName: valueOf(handler.name),
147
+ archive: Buffer.from(await archive(bundle)),
148
+ });
149
+ command.log(`Uploaded bundle "${valueOf(handler.name)}"`);
150
+ }
151
+ }
152
+ async function uploadDbBundle(command, root, catalogService, userId, organizationId, app, currentVersionId) {
153
+ const dbDir = path.join(root, 'db');
154
+ let dbExists = false;
155
+ try {
156
+ const stat = await fs.lstat(dbDir);
157
+ dbExists = stat.isDirectory();
158
+ }
159
+ catch (_e) {
160
+ // Nothing to do
161
+ }
162
+ if (dbExists) {
163
+ const dbBundle = new FileSystemBundle(dbDir);
164
+ await catalogService.uploadBundle({
165
+ userId,
166
+ organizationId,
167
+ applicationName: valueOf(app.name),
168
+ applicationVersionId: currentVersionId,
169
+ archiveType: BundleArchiveType.ZIP,
170
+ bundleName: 'db',
171
+ archive: Buffer.from(await archive(dbBundle)),
172
+ });
173
+ command.log(`Uploaded bundle "db"`);
174
+ }
175
+ }
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { ServiceType } from '@bufbuild/protobuf';
2
- import { Interceptor, PromiseClient } from '@connectrpc/connect';
1
+ import { type DescService } from '@bufbuild/protobuf';
2
+ import { type Client, Interceptor } from '@connectrpc/connect';
3
3
  import { Application } from '@liquidmetal-ai/drizzle/appify/build';
4
- import { CatalogService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/catalog_connect';
5
- import { RainbowAuthService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/rainbow_auth_connect';
6
- import { RainbowPublicService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/rainbow_public_connect';
7
- import { RaindropState } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/raindrop_pb';
8
- import { ObjectService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/resource_interface_connect';
9
- import { SearchAgentService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/search_agent_connect';
4
+ import { CatalogService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/catalog_pb';
5
+ import { RainbowAuthService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/rainbow_auth_pb';
6
+ import { type RaindropState } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/raindrop_pb';
7
+ import { ObjectService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/resource_interface_pb';
8
+ import { SearchAgentService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/search_agent_pb';
10
9
  export { run } from '@oclif/core';
10
+ export declare const EPOCH_TS: import("@bufbuild/protobuf/wkt").Timestamp;
11
11
  export declare function configFromAppFile(appFile: string): Promise<Application[]>;
12
12
  export declare function joinPath(...parts: string[]): string;
13
13
  export type ServiceIdentity = {
@@ -16,29 +16,28 @@ export type ServiceIdentity = {
16
16
  userId: string;
17
17
  };
18
18
  export declare function selectedOrganization(configDir: string): Promise<ServiceIdentity>;
19
- export declare function createAuthenticateInterceptor(configDir: string, rainbowAuth: PromiseClient<typeof RainbowAuthService>, overrideAuthToken?: string): {
19
+ export declare function createAuthenticateInterceptor(configDir: string, rainbowAuth: Client<typeof RainbowAuthService>, overrideAuthToken?: string): {
20
20
  authenticate: Interceptor;
21
21
  };
22
22
  export declare function readState(configDir: string): Promise<RaindropState>;
23
23
  export declare function replaceState(configDir: string, state: RaindropState): Promise<void>;
24
24
  export declare function ensureDirectory(dir: string): Promise<void>;
25
25
  export declare function rainbowAuthService(baseUrl: string): Promise<{
26
- client: PromiseClient<typeof RainbowAuthService>;
26
+ client: Client<typeof RainbowAuthService>;
27
27
  }>;
28
28
  export declare function catalogService(opts: ServiceClientOptions): Promise<ServiceClient<typeof CatalogService>>;
29
29
  export declare function searchAgentService(opts: ServiceClientOptions): Promise<ServiceClient<typeof SearchAgentService>>;
30
- export declare function rainbowPublicService(opts: ServiceClientOptions): Promise<ServiceClient<typeof RainbowPublicService>>;
31
30
  export declare function objectService(opts: ServiceClientOptions): Promise<ServiceClient<typeof ObjectService>>;
32
31
  export type ServiceClientOptions = {
33
- rainbowAuth: PromiseClient<typeof RainbowAuthService>;
32
+ rainbowAuth: Client<typeof RainbowAuthService>;
34
33
  configDir: string;
35
34
  identity: ServiceIdentity;
36
35
  overrideAuthToken?: string;
37
36
  };
38
- export type ServiceClient<T extends ServiceType> = {
39
- client: PromiseClient<T>;
37
+ export type ServiceClient<T extends DescService> = {
38
+ client: Client<T>;
40
39
  userId: string;
41
40
  organizationId: string;
42
41
  };
43
- export declare function serviceClient<T extends ServiceType>(service: T, { rainbowAuth, configDir, identity, overrideAuthToken }: ServiceClientOptions): Promise<ServiceClient<T>>;
42
+ export declare function serviceClient<T extends DescService>(service: T, { rainbowAuth, configDir, identity, overrideAuthToken }: ServiceClientOptions): Promise<ServiceClient<T>>;
44
43
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAuB,WAAW,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEtF,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAE,MAAM,8DAA8D,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,MAAM,mEAAmE,CAAC;AAEvG,OAAO,EAAE,oBAAoB,EAAE,MAAM,qEAAqE,CAAC;AAC3G,OAAO,EAAE,aAAa,EAAE,MAAM,0DAA0D,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,yEAAyE,CAAC;AACxG,OAAO,EAAE,kBAAkB,EAAE,MAAM,mEAAmE,CAAC;AAKvG,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAG/E;AAGD,wBAAgB,QAAQ,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAEnD;AAwDD,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAgBtF;AAKD,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,aAAa,CAAC,OAAO,kBAAkB,CAAC,EACrD,iBAAiB,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B,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAsB,aAAa,CAAC,CAAC,SAAS,WAAW,EACvD,OAAO,EAAE,CAAC,EACV,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,iBAAiB,EAAE,EAAE,oBAAoB,GAC5E,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAe3B"}
package/dist/index.js CHANGED
@@ -1,17 +1,19 @@
1
- import { createPromiseClient } from '@connectrpc/connect';
1
+ import { create, toJsonString, fromJsonString } from '@bufbuild/protobuf';
2
+ import { timestampDate, timestampFromDate } from '@bufbuild/protobuf/wkt';
3
+ import { createClient } from '@connectrpc/connect';
2
4
  import { createConnectTransport } from '@connectrpc/connect-web';
3
5
  import { mustManifestFromString } from '@liquidmetal-ai/drizzle/appify/index';
4
- import { CatalogService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/catalog_connect';
5
- import { RainbowAuthService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/rainbow_auth_connect';
6
- import { RainbowPublicService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/rainbow_public_connect';
7
- import { RaindropState } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/raindrop_pb';
8
- import { ObjectService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/resource_interface_connect';
9
- import { SearchAgentService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/search_agent_connect';
6
+ import { CatalogService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/catalog_pb';
7
+ import { RainbowAuthService, RefreshAccessTokenRequestSchema, } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/rainbow_auth_pb';
8
+ import { RaindropStateSchema } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/raindrop_pb';
9
+ import { ObjectService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/resource_interface_pb';
10
+ import { SearchAgentService } from '@liquidmetal-ai/drizzle/liquidmetal/v1alpha1/search_agent_pb';
10
11
  import { Mutex } from 'async-mutex';
11
12
  import { subSeconds, isAfter } from 'date-fns';
12
13
  import * as fs from 'node:fs/promises';
13
14
  import * as path from 'node:path';
14
15
  export { run } from '@oclif/core';
16
+ export const EPOCH_TS = timestampFromDate(new Date(0));
15
17
  export async function configFromAppFile(appFile) {
16
18
  const contents = await fs.readFile(appFile, 'utf8');
17
19
  return mustManifestFromString(contents);
@@ -43,15 +45,16 @@ async function bearerTokenAndRefresh(configDir, rainbowAuth) {
43
45
  }
44
46
  // Add 60 second buffer before expiration to ensure smooth token refresh
45
47
  const EXPIRATION_BUFFER_SECONDS = 60; // 1 minute
46
- const expirationDate = token.accessTokenExpiresAt.toDate();
48
+ const expirationDate = timestampDate(token.accessTokenExpiresAt);
47
49
  const earlierExpirationDate = subSeconds(expirationDate, EXPIRATION_BUFFER_SECONDS);
48
50
  const now = new Date();
49
51
  // expired is true if the current time is after the earlier expiration date
50
52
  const expired = isAfter(now, earlierExpirationDate);
51
53
  if (expired) {
52
- const next = await rainbowAuth.refreshAccessToken({
53
- ...token,
54
- });
54
+ const next = await rainbowAuth.refreshAccessToken(create(RefreshAccessTokenRequestSchema, {
55
+ refreshToken: token.refreshToken,
56
+ organizationId: token.organizationId,
57
+ }));
55
58
  if (!next.bearerToken) {
56
59
  throw new Error('unable to refresh login');
57
60
  }
@@ -99,14 +102,14 @@ export async function readState(configDir) {
99
102
  await fs.access(filename, fs.constants.F_OK);
100
103
  }
101
104
  catch {
102
- await replaceState(configDir, new RaindropState({}));
105
+ await replaceState(configDir, create(RaindropStateSchema, {}));
103
106
  }
104
107
  const data = await fs.readFile(filename, { encoding: 'utf8' });
105
- return RaindropState.fromJsonString(data);
108
+ return fromJsonString(RaindropStateSchema, data);
106
109
  }
107
110
  export async function replaceState(configDir, state) {
108
111
  const filename = path.join(configDir, configBasename);
109
- const data = state.toJsonString({
112
+ const data = toJsonString(RaindropStateSchema, state, {
110
113
  prettySpaces: 2,
111
114
  });
112
115
  // Ensure config directory exists as well
@@ -129,7 +132,7 @@ export async function ensureDirectory(dir) {
129
132
  }
130
133
  export async function rainbowAuthService(baseUrl) {
131
134
  return {
132
- client: createPromiseClient(RainbowAuthService, createConnectTransport({
135
+ client: createClient(RainbowAuthService, createConnectTransport({
133
136
  baseUrl,
134
137
  })),
135
138
  };
@@ -140,9 +143,6 @@ export async function catalogService(opts) {
140
143
  export async function searchAgentService(opts) {
141
144
  return serviceClient(SearchAgentService, opts);
142
145
  }
143
- export async function rainbowPublicService(opts) {
144
- return serviceClient(RainbowPublicService, opts);
145
- }
146
146
  export async function objectService(opts) {
147
147
  return serviceClient(ObjectService, opts);
148
148
  }
@@ -150,7 +150,7 @@ export async function serviceClient(service, { rainbowAuth, configDir, identity,
150
150
  const { baseUrl, organizationId, userId } = identity;
151
151
  const { authenticate } = createAuthenticateInterceptor(configDir, rainbowAuth, overrideAuthToken);
152
152
  return {
153
- client: createPromiseClient(service, createConnectTransport({
153
+ client: createClient(service, createConnectTransport({
154
154
  baseUrl,
155
155
  interceptors: [authenticate],
156
156
  })),
@@ -1 +1 @@
1
- {"root":["../src/base-command.ts","../src/build.test.ts","../src/build.ts","../src/codegen.test.ts","../src/codegen.ts","../src/config.test.ts","../src/config.ts","../src/index.test.ts","../src/index.ts","../src/commands/tail.ts","../src/commands/auth/list.ts","../src/commands/auth/login.ts","../src/commands/auth/logout.ts","../src/commands/auth/select.ts","../src/commands/build/branch.ts","../src/commands/build/checkout.ts","../src/commands/build/delete.ts","../src/commands/build/deploy.ts","../src/commands/build/find.ts","../src/commands/build/generate.ts","../src/commands/build/init.ts","../src/commands/build/list.ts","../src/commands/build/sandbox.ts","../src/commands/build/start.ts","../src/commands/build/status.ts","../src/commands/build/stop.ts","../src/commands/build/unsandbox.ts","../src/commands/build/upload.ts","../src/commands/build/validate.ts","../src/commands/build/env/get.ts","../src/commands/build/env/set.ts","../src/commands/build/tools/check.ts","../src/commands/build/tools/fmt.ts","../src/commands/object/delete.ts","../src/commands/object/get.ts","../src/commands/object/list.ts","../src/commands/object/put.ts","../src/commands/query/chunk-search.ts","../src/commands/query/register-retriever.ts","../src/commands/query/search.ts"],"version":"5.6.2"}
1
+ {"root":["../src/base-command.ts","../src/build.test.ts","../src/build.ts","../src/codegen.test.ts","../src/codegen.ts","../src/config.test.ts","../src/config.ts","../src/deploy.ts","../src/index.test.ts","../src/index.ts","../src/commands/tail.ts","../src/commands/auth/list.ts","../src/commands/auth/login.ts","../src/commands/auth/logout.ts","../src/commands/auth/select.ts","../src/commands/build/branch.ts","../src/commands/build/checkout.ts","../src/commands/build/delete.ts","../src/commands/build/deploy.ts","../src/commands/build/find.ts","../src/commands/build/generate.ts","../src/commands/build/init.ts","../src/commands/build/list.ts","../src/commands/build/sandbox.ts","../src/commands/build/start.ts","../src/commands/build/status.ts","../src/commands/build/stop.ts","../src/commands/build/unsandbox.ts","../src/commands/build/upload.ts","../src/commands/build/validate.ts","../src/commands/build/env/get.ts","../src/commands/build/env/set.ts","../src/commands/build/tools/check.ts","../src/commands/build/tools/fmt.ts","../src/commands/object/delete.ts","../src/commands/object/get.ts","../src/commands/object/list.ts","../src/commands/object/put.ts","../src/commands/query/chunk-search.ts","../src/commands/query/register-retriever.ts","../src/commands/query/search.ts"],"version":"5.8.2"}