@aouda/client 0.1.11 → 0.1.13

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/index.cjs CHANGED
@@ -64,6 +64,7 @@ __export(index_exports, {
64
64
  NamedMutationsApi: () => NamedMutationsApi,
65
65
  NamedQueriesApi: () => NamedQueriesApi,
66
66
  NodeAdminApi: () => NodeAdminApi,
67
+ PolicyApi: () => PolicyApi,
67
68
  ReplicationAdminApi: () => ReplicationAdminApi,
68
69
  RetryPolicy: () => RetryPolicy,
69
70
  ServerAdminApi: () => ServerAdminApi,
@@ -86,7 +87,7 @@ module.exports = __toCommonJS(index_exports);
86
87
  // package.json
87
88
  var package_default = {
88
89
  name: "@aouda/client",
89
- version: "0.1.11",
90
+ version: "0.1.13",
90
91
  description: "Official TypeScript/JavaScript client library for Aouda",
91
92
  type: "module",
92
93
  main: "./dist/index.cjs",
@@ -1132,7 +1133,9 @@ var BulkLoadCoordinator = class {
1132
1133
  replicationMode: options.replicationMode,
1133
1134
  forceSingleNodeReplicationBypass: options.forceSingleNodeReplicationBypass,
1134
1135
  postLoadMqBehavior: options.postLoadMqBehavior,
1135
- ...options.identityInsert === true ? { identityInsert: true } : {}
1136
+ ...options.identityInsert === true ? { identityInsert: true } : {},
1137
+ ...options.applyTransforms === true ? { applyTransforms: true } : {},
1138
+ ...options.preTransformed === true ? { preTransformed: true } : {}
1136
1139
  }
1137
1140
  };
1138
1141
  const beginResp = await this.transport.post(
@@ -1225,7 +1228,11 @@ var ERROR_CODE_MAP = {
1225
1228
  NAMED_QUERY_BATCH_MUTATION: AoudaValidationError,
1226
1229
  NAMED_QUERY_BIND_FAILED: AoudaValidationError,
1227
1230
  NAMED_QUERY_PARAM_REQUIRED: AoudaValidationError,
1228
- NAMED_MUTATION_BIND_FAILED: AoudaValidationError
1231
+ NAMED_MUTATION_BIND_FAILED: AoudaValidationError,
1232
+ AUTH_IDENTITY_INVALID: AoudaValidationError,
1233
+ AUTH_IDENTITY_NOT_FOUND: AoudaValidationError,
1234
+ BULK_LOAD_TRANSFORM_INTENT_REQUIRED: AoudaValidationError,
1235
+ BULK_LOAD_TRANSFORM_INTENT_CONFLICT: AoudaValidationError
1229
1236
  };
1230
1237
  function createComposedAbortController(...signals) {
1231
1238
  const controller = new AbortController();
@@ -2112,7 +2119,7 @@ var AsyncEventQueue = class {
2112
2119
  }
2113
2120
  };
2114
2121
  var TableSubscription = class {
2115
- constructor(transport, tableName, options = {}, baseFilter) {
2122
+ constructor(transport, identity, options = {}, onWarnings) {
2116
2123
  this._queue = new AsyncEventQueue();
2117
2124
  this._active = true;
2118
2125
  this._started = false;
@@ -2122,11 +2129,11 @@ var TableSubscription = class {
2122
2129
  this._forceFreshSubscribe = false;
2123
2130
  this.id = createStreamingId("sub");
2124
2131
  this._transport = transport;
2125
- this._tableName = tableName;
2126
- this._baseFilter = baseFilter;
2132
+ this._identity = identity;
2127
2133
  this._onSnapshot = options.onSnapshot;
2128
2134
  this._onChange = options.onChange;
2129
2135
  this._onError = options.onError;
2136
+ this._onWarnings = onWarnings;
2130
2137
  this._conflate = options.conflate;
2131
2138
  this._reconnectHandlerKey = `${this.id}::reconnect`;
2132
2139
  }
@@ -2189,12 +2196,18 @@ var TableSubscription = class {
2189
2196
  async _sendSubscribe(resumeFrom) {
2190
2197
  const message = {
2191
2198
  type: "subscribe",
2192
- id: this.id,
2193
- target: this._tableName
2199
+ id: this.id
2194
2200
  };
2195
- const filter = this._baseFilter;
2196
- if (filter !== void 0) {
2197
- message.filter = filter;
2201
+ if (this._identity.kind === "named") {
2202
+ message.hash = this._identity.hash;
2203
+ if (this._identity.args !== void 0) {
2204
+ message.args = this._identity.args;
2205
+ }
2206
+ } else {
2207
+ message.target = this._identity.target;
2208
+ if (this._identity.filter !== void 0) {
2209
+ message.filter = this._identity.filter;
2210
+ }
2198
2211
  }
2199
2212
  if (resumeFrom !== void 0) {
2200
2213
  message.resume_from = resumeFrom;
@@ -2233,6 +2246,9 @@ var TableSubscription = class {
2233
2246
  }
2234
2247
  _handleSnapshotComplete(message) {
2235
2248
  this._lastVersion = message.version;
2249
+ if (message.warnings != null && message.warnings.length > 0) {
2250
+ this._onWarnings?.(message.warnings);
2251
+ }
2236
2252
  const rows = this._pendingSnapshotRows;
2237
2253
  this._pendingSnapshotRows = [];
2238
2254
  this._onSnapshot?.(rows, message.version);
@@ -2982,17 +2998,16 @@ var TableQuery = class _TableQuery {
2982
2998
  const whereClause = this.buildWhereClause();
2983
2999
  const queryFilter = buildSubscriptionFilter(whereClause);
2984
3000
  const mergedFilter = mergeFilterObjects(queryFilter, options.filter);
2985
- const subscription = new TableSubscription(
2986
- wsTransport,
2987
- this.tableName,
2988
- {
2989
- onSnapshot: options.onSnapshot,
2990
- onChange: options.onChange,
2991
- onError: options.onError,
2992
- conflate: options.conflate
2993
- },
2994
- mergedFilter
2995
- );
3001
+ const subscription = new TableSubscription(wsTransport, {
3002
+ kind: "table",
3003
+ target: this.tableName,
3004
+ filter: mergedFilter
3005
+ }, {
3006
+ onSnapshot: options.onSnapshot,
3007
+ onChange: options.onChange,
3008
+ onError: options.onError,
3009
+ conflate: options.conflate
3010
+ });
2996
3011
  subscription.start();
2997
3012
  return subscription;
2998
3013
  }
@@ -3578,10 +3593,84 @@ function serializeUpdateValue(col, val) {
3578
3593
  else: toNode(cond.else)
3579
3594
  };
3580
3595
  }
3596
+ if ("$upper" in val) {
3597
+ return { type: "call", fn: "upper", args: [unaryCallArg(col, val.$upper)] };
3598
+ }
3599
+ if ("$lower" in val) {
3600
+ return { type: "call", fn: "lower", args: [unaryCallArg(col, val.$lower)] };
3601
+ }
3602
+ if ("$trim" in val) {
3603
+ return { type: "call", fn: "trim", args: [unaryCallArg(col, val.$trim)] };
3604
+ }
3605
+ if ("$concat" in val) {
3606
+ const parts = val.$concat;
3607
+ return {
3608
+ type: "call",
3609
+ fn: "concat",
3610
+ args: parts.map((p) => valueToExprNode(p))
3611
+ };
3612
+ }
3613
+ if ("$substring" in val) {
3614
+ const spec = val.$substring;
3615
+ if (Array.isArray(spec)) {
3616
+ return {
3617
+ type: "call",
3618
+ fn: "substring",
3619
+ args: [{ type: "colRef", col }, ...spec.map((p) => valueToExprNode(p))]
3620
+ };
3621
+ }
3622
+ return {
3623
+ type: "call",
3624
+ fn: "substring",
3625
+ args: [{ type: "colRef", col }, { type: "literal", value: spec }]
3626
+ };
3627
+ }
3628
+ if ("$round" in val) {
3629
+ return {
3630
+ type: "call",
3631
+ fn: "round",
3632
+ args: [
3633
+ { type: "colRef", col },
3634
+ { type: "literal", value: val.$round }
3635
+ ]
3636
+ };
3637
+ }
3638
+ if ("$roundTo" in val) {
3639
+ return {
3640
+ type: "call",
3641
+ fn: "roundTo",
3642
+ args: [
3643
+ { type: "colRef", col },
3644
+ { type: "literal", value: val.$roundTo }
3645
+ ]
3646
+ };
3647
+ }
3648
+ if ("$cast" in val) {
3649
+ return {
3650
+ type: "call",
3651
+ fn: "cast",
3652
+ args: [
3653
+ { type: "colRef", col },
3654
+ { type: "literal", value: val.$cast }
3655
+ ]
3656
+ };
3657
+ }
3581
3658
  throw new Error(
3582
3659
  `Unknown expression operator in update() for column '${col}': ${JSON.stringify(val)}`
3583
3660
  );
3584
3661
  }
3662
+ function unaryCallArg(col, operand) {
3663
+ if (operand === true || operand === 1) {
3664
+ return { type: "colRef", col };
3665
+ }
3666
+ return valueToExprNode(operand);
3667
+ }
3668
+ function valueToExprNode(v) {
3669
+ if (typeof v === "string" && v.startsWith("$")) {
3670
+ return { type: "colRef", col: v.slice(1) };
3671
+ }
3672
+ return { type: "literal", value: v };
3673
+ }
3585
3674
 
3586
3675
  // src/tables.ts
3587
3676
  function validateNonEmptyString(value, name) {
@@ -4742,10 +4831,11 @@ function emptyStats() {
4742
4831
  };
4743
4832
  }
4744
4833
  var NamedQueriesApi = class {
4745
- constructor(transport, database, onWarning) {
4834
+ constructor(transport, database, onWarning, getStreamingTransport) {
4746
4835
  this.transport = transport;
4747
4836
  this.database = database;
4748
4837
  this.onWarning = onWarning;
4838
+ this.getStreamingTransport = getStreamingTransport;
4749
4839
  }
4750
4840
  async execute(hash, args, options) {
4751
4841
  if (typeof hash !== "string" || hash.trim().length === 0) {
@@ -4813,6 +4903,26 @@ var NamedQueriesApi = class {
4813
4903
  return { isError: false, result };
4814
4904
  });
4815
4905
  }
4906
+ subscribe(hash, args, options = {}) {
4907
+ if (typeof hash !== "string" || hash.trim().length === 0) {
4908
+ throw new Error("Named query hash must be a non-empty string");
4909
+ }
4910
+ const subscription = new TableSubscription(
4911
+ this.getStreamingTransport(),
4912
+ { kind: "named", hash, args },
4913
+ {
4914
+ onSnapshot: options.onSnapshot,
4915
+ onChange: options.onChange,
4916
+ onError: options.onError,
4917
+ conflate: options.conflate
4918
+ },
4919
+ (warnings) => {
4920
+ raiseDeprecationWarnings(this.onWarning, warnings);
4921
+ }
4922
+ );
4923
+ subscription.start();
4924
+ return subscription;
4925
+ }
4816
4926
  };
4817
4927
  var NamedMutationsApi = class {
4818
4928
  constructor(transport, database, onWarning) {
@@ -4856,6 +4966,20 @@ var NamedMutationsApi = class {
4856
4966
  }
4857
4967
  };
4858
4968
 
4969
+ // src/policy.ts
4970
+ var PolicyApi = class {
4971
+ constructor(transport, database) {
4972
+ this.transport = transport;
4973
+ this.database = database;
4974
+ }
4975
+ inspect(body, options) {
4976
+ const path = `${databasePath2(this.database)}/policy/inspect`;
4977
+ return this.transport.post(path, body, {
4978
+ signal: options?.signal
4979
+ });
4980
+ }
4981
+ };
4982
+
4859
4983
  // src/streaming/websocket-transport.ts
4860
4984
  var import_msgpack = require("@msgpack/msgpack");
4861
4985
  var DEFAULT_PING_INTERVAL_MS = 2e4;
@@ -5636,13 +5760,15 @@ var AoudaClient = class {
5636
5760
  this._namedQueries = new NamedQueriesApi(
5637
5761
  this.transport,
5638
5762
  this.database,
5639
- onNamedArtifactWarning
5763
+ onNamedArtifactWarning,
5764
+ () => this._getOrCreateWebSocketTransport()
5640
5765
  );
5641
5766
  this._namedMutations = new NamedMutationsApi(
5642
5767
  this.transport,
5643
5768
  this.database,
5644
5769
  onNamedArtifactWarning
5645
5770
  );
5771
+ this._policy = new PolicyApi(this.transport, this.database);
5646
5772
  }
5647
5773
  /**
5648
5774
  * Connects to the Aouda server.
@@ -5797,6 +5923,12 @@ var AoudaClient = class {
5797
5923
  get namedMutations() {
5798
5924
  return this._namedMutations;
5799
5925
  }
5926
+ /**
5927
+ * Policy inspect (`POST …/policy/inspect`). Admin on the data DB.
5928
+ */
5929
+ get policy() {
5930
+ return this._policy;
5931
+ }
5800
5932
  /**
5801
5933
  * Access auth operations (signUp, signIn, signOut, refresh, me, changePassword).
5802
5934
  * @returns The auth API.
@@ -6221,6 +6353,7 @@ var version = package_default.version;
6221
6353
  NamedMutationsApi,
6222
6354
  NamedQueriesApi,
6223
6355
  NodeAdminApi,
6356
+ PolicyApi,
6224
6357
  ReplicationAdminApi,
6225
6358
  RetryPolicy,
6226
6359
  ServerAdminApi,