@valon-technologies/gestalt 0.0.1-alpha.18 → 0.0.1-alpha.19

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/src/s3.ts CHANGED
@@ -28,7 +28,8 @@ import {
28
28
  WriteObjectResponseSchema,
29
29
  } from "./internal/gen/v1/s3_pb.ts";
30
30
  import { errorMessage, type MaybePromise } from "./api.ts";
31
- import { RuntimeProvider, type RuntimeProviderOptions } from "./provider.ts";
31
+ import { ProviderBase, type ProviderBaseOptions } from "./provider.ts";
32
+ import { dateFromTimestamp, timestampFromDate } from "./protocol.ts";
32
33
 
33
34
  /** Base environment variable for discovering S3 runtime sockets. */
34
35
  export const ENV_S3_SOCKET = "GESTALT_S3_SOCKET";
@@ -245,7 +246,7 @@ export interface ProviderReadResult {
245
246
  /**
246
247
  * Runtime hooks required to implement a Gestalt S3 provider.
247
248
  */
248
- export interface S3ProviderOptions extends RuntimeProviderOptions {
249
+ export interface S3ProviderOptions extends ProviderBaseOptions {
249
250
  headObject: (ref: ObjectRef) => MaybePromise<ObjectMeta>;
250
251
  readObject: (ref: ObjectRef, options?: ReadOptions) => MaybePromise<ProviderReadResult>;
251
252
  writeObject: (
@@ -269,7 +270,7 @@ export interface S3ProviderOptions extends RuntimeProviderOptions {
269
270
  /**
270
271
  * S3 provider implementation consumed by the Gestalt runtime.
271
272
  */
272
- export class S3Provider extends RuntimeProvider {
273
+ export class S3Provider extends ProviderBase {
273
274
  readonly kind = "s3" as const;
274
275
 
275
276
  private readonly headObjectHandler: S3ProviderOptions["headObject"];
@@ -517,7 +518,7 @@ export function createS3Service(
517
518
  expiresAt?: { seconds: bigint; nanos: number };
518
519
  };
519
520
  if (result.expiresAt) {
520
- response.expiresAt = toProtoTimestamp(result.expiresAt);
521
+ response.expiresAt = timestampFromDate(result.expiresAt);
521
522
  }
522
523
  return create(PresignObjectResponseSchema, response);
523
524
  },
@@ -693,7 +694,7 @@ export class S3 {
693
694
  headers: cloneStringMap(response.headers),
694
695
  };
695
696
  if (response.expiresAt) {
696
- result.expiresAt = fromProtoTimestamp(response.expiresAt);
697
+ result.expiresAt = dateFromTimestamp(response.expiresAt);
697
698
  }
698
699
  return result;
699
700
  }
@@ -722,7 +723,7 @@ export class S3 {
722
723
  headers: cloneStringMap(response.headers),
723
724
  };
724
725
  if (response.expiresAt) {
725
- result.expiresAt = fromProtoTimestamp(response.expiresAt);
726
+ result.expiresAt = dateFromTimestamp(response.expiresAt);
726
727
  }
727
728
  return result;
728
729
  }
@@ -1185,7 +1186,7 @@ function toProtoObjectMeta(meta: ObjectMeta) {
1185
1186
  storageClass: meta.storageClass,
1186
1187
  };
1187
1188
  if (meta.lastModified) {
1188
- value.lastModified = toProtoTimestamp(meta.lastModified);
1189
+ value.lastModified = timestampFromDate(meta.lastModified);
1189
1190
  }
1190
1191
  return value;
1191
1192
  }
@@ -1200,7 +1201,7 @@ function fromProtoObjectMeta(meta: ProtoS3ObjectMeta | undefined): ObjectMeta {
1200
1201
  storageClass: meta?.storageClass ?? "",
1201
1202
  };
1202
1203
  if (meta?.lastModified) {
1203
- value.lastModified = fromProtoTimestamp(meta.lastModified);
1204
+ value.lastModified = dateFromTimestamp(meta.lastModified);
1204
1205
  }
1205
1206
  return value;
1206
1207
  }
@@ -1214,10 +1215,10 @@ function toProtoReadOptions(options?: ReadOptions) {
1214
1215
  proto.range = toProtoByteRange(options.range);
1215
1216
  }
1216
1217
  if (options?.ifModifiedSince) {
1217
- proto.ifModifiedSince = toProtoTimestamp(options.ifModifiedSince);
1218
+ proto.ifModifiedSince = timestampFromDate(options.ifModifiedSince);
1218
1219
  }
1219
1220
  if (options?.ifUnmodifiedSince) {
1220
- proto.ifUnmodifiedSince = toProtoTimestamp(options.ifUnmodifiedSince);
1221
+ proto.ifUnmodifiedSince = timestampFromDate(options.ifUnmodifiedSince);
1221
1222
  }
1222
1223
  return proto;
1223
1224
  }
@@ -1234,10 +1235,10 @@ function fromProtoReadOptions(request: ProtoReadObjectRequest | undefined): Read
1234
1235
  options.ifNoneMatch = request.ifNoneMatch;
1235
1236
  }
1236
1237
  if (request?.ifModifiedSince) {
1237
- options.ifModifiedSince = fromProtoTimestamp(request.ifModifiedSince);
1238
+ options.ifModifiedSince = dateFromTimestamp(request.ifModifiedSince);
1238
1239
  }
1239
1240
  if (request?.ifUnmodifiedSince) {
1240
- options.ifUnmodifiedSince = fromProtoTimestamp(request.ifUnmodifiedSince);
1241
+ options.ifUnmodifiedSince = dateFromTimestamp(request.ifUnmodifiedSince);
1241
1242
  }
1242
1243
  return options;
1243
1244
  }
@@ -1330,22 +1331,6 @@ function fromProtoPresignMethod(method: ProtoPresignMethod): PresignMethod {
1330
1331
  }
1331
1332
  }
1332
1333
 
1333
- function toProtoTimestamp(value: Date) {
1334
- const millis = value.getTime();
1335
- const seconds = Math.floor(millis / 1000);
1336
- const nanos = Math.trunc((millis - (seconds * 1000)) * 1_000_000);
1337
- return {
1338
- seconds: BigInt(seconds),
1339
- nanos,
1340
- };
1341
- }
1342
-
1343
- function fromProtoTimestamp(value: { seconds?: bigint; nanos?: number }): Date {
1344
- const seconds = Number(value.seconds ?? 0n);
1345
- const nanos = Number(value.nanos ?? 0);
1346
- return new Date((seconds * 1000) + Math.trunc(nanos / 1_000_000));
1347
- }
1348
-
1349
1334
  function normalizeProtoInt(value: number | bigint | undefined): bigint {
1350
1335
  if (typeof value === "bigint") {
1351
1336
  return value;
package/src/secrets.ts CHANGED
@@ -1,17 +1,17 @@
1
- import { RuntimeProvider, type RuntimeProviderOptions } from "./provider.ts";
1
+ import { ProviderBase, type ProviderBaseOptions } from "./provider.ts";
2
2
  import type { MaybePromise } from "./api.ts";
3
3
 
4
4
  /**
5
5
  * Runtime hooks required to implement a Gestalt secrets provider.
6
6
  */
7
- export interface SecretsProviderOptions extends RuntimeProviderOptions {
7
+ export interface SecretsProviderOptions extends ProviderBaseOptions {
8
8
  getSecret: (name: string) => MaybePromise<string>;
9
9
  }
10
10
 
11
11
  /**
12
12
  * Secrets provider implementation consumed by the Gestalt runtime.
13
13
  */
14
- export class SecretsProvider extends RuntimeProvider {
14
+ export class SecretsProvider extends ProviderBase {
15
15
  readonly kind = "secrets" as const;
16
16
 
17
17
  private readonly getSecretHandler: SecretsProviderOptions["getSecret"];