qstd 0.3.85 → 0.3.87

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.
@@ -2,6 +2,7 @@ import { parse, format, formatISO, formatDistanceToNow, isSameYear, isSameMonth,
2
2
  import awaitSpawn from 'await-spawn';
3
3
  import { promises } from 'fs';
4
4
  import { ArkErrors } from 'arktype';
5
+ import { ApiGatewayManagementApiClient, PostToConnectionCommand, DeleteConnectionCommand } from '@aws-sdk/client-apigatewaymanagementapi';
5
6
  import { DynamoDBDocumentClient, ScanCommand, QueryCommand, DeleteCommand, PutCommand, UpdateCommand, BatchGetCommand, TransactWriteCommand, BatchWriteCommand } from '@aws-sdk/lib-dynamodb';
6
7
  import { ReturnValue, DynamoDBClient, DeleteTableCommand, DescribeTableCommand, DynamoDBServiceException, CreateTableCommand, DescribeContinuousBackupsCommand, UpdateContinuousBackupsCommand, waitUntilTableExists } from '@aws-sdk/client-dynamodb';
7
8
  import signale from 'signale';
@@ -1093,6 +1094,126 @@ function remove(path, body, opts) {
1093
1094
  );
1094
1095
  }
1095
1096
 
1097
+ // src/shared/lexorank/index.ts
1098
+ var lexorank_exports = {};
1099
+ __export(lexorank_exports, {
1100
+ checkBalance: () => checkBalance,
1101
+ createOrderStr: () => createOrderStr,
1102
+ createRebalancedOrderList: () => createRebalancedOrderList,
1103
+ rebalance: () => rebalance,
1104
+ sortByOrder: () => sortByOrder
1105
+ });
1106
+
1107
+ // src/shared/lexorank/literals.ts
1108
+ var LOWER_BOUND = 96;
1109
+ var UPPER_BOUND = 123;
1110
+ var CHAR_A = 97;
1111
+ var CHAR_Z = 122;
1112
+ var ALPHABET_SIZE = 26;
1113
+ var DISTRIBUTION_TABLE = [
1114
+ 0,
1115
+ 4096,
1116
+ 65792,
1117
+ 528416,
1118
+ 1081872,
1119
+ 2167048,
1120
+ 2376776,
1121
+ 4756004,
1122
+ 4794660,
1123
+ 5411476,
1124
+ 9775442,
1125
+ 11097386,
1126
+ 11184810,
1127
+ 22369621
1128
+ ];
1129
+
1130
+ // src/shared/lexorank/fns.ts
1131
+ var stripTrailingAs = (str) => {
1132
+ let last = str.length - 1;
1133
+ while (str.charAt(last) === "a") --last;
1134
+ return str.slice(0, last + 1);
1135
+ };
1136
+ var partialAlphabet = (num2) => {
1137
+ let bits = num2 < 13 ? DISTRIBUTION_TABLE[num2] ?? 0 : 33554431 - (DISTRIBUTION_TABLE[25 - num2] ?? 0);
1138
+ const chars = [];
1139
+ for (let i = 1; i < ALPHABET_SIZE; i++, bits >>= 1) {
1140
+ if (bits & 1) chars.push(String.fromCharCode(CHAR_A + i));
1141
+ }
1142
+ return chars;
1143
+ };
1144
+
1145
+ // src/shared/lexorank/domain.ts
1146
+ var createOrderStr = (prev = "", next = "") => {
1147
+ let p;
1148
+ let n;
1149
+ let pos;
1150
+ let str;
1151
+ for (pos = 0; p === n; pos++) {
1152
+ p = pos < prev.length ? prev.charCodeAt(pos) : LOWER_BOUND;
1153
+ n = pos < next.length ? next.charCodeAt(pos) : UPPER_BOUND;
1154
+ }
1155
+ str = prev.slice(0, pos - 1);
1156
+ if (p === LOWER_BOUND) {
1157
+ while (n === CHAR_A) {
1158
+ n = pos < next.length ? next.charCodeAt(pos++) : UPPER_BOUND;
1159
+ str += "a";
1160
+ }
1161
+ if (n === CHAR_A + 1) {
1162
+ str += "a";
1163
+ n = UPPER_BOUND;
1164
+ }
1165
+ } else if (p !== void 0 && n !== void 0 && p + 1 === n) {
1166
+ str += String.fromCharCode(p);
1167
+ n = UPPER_BOUND;
1168
+ while ((p = pos < prev.length ? prev.charCodeAt(pos++) : LOWER_BOUND) === CHAR_Z) {
1169
+ str += "z";
1170
+ }
1171
+ }
1172
+ return str + String.fromCharCode(
1173
+ Math.ceil(((p ?? LOWER_BOUND) + (n ?? UPPER_BOUND)) / 2)
1174
+ );
1175
+ };
1176
+ var createRebalancedOrderList = (num2) => {
1177
+ const chars = Math.floor(Math.log(num2) / Math.log(ALPHABET_SIZE)) + 1;
1178
+ const prev = Math.pow(ALPHABET_SIZE, chars - 1);
1179
+ const ratio = chars > 1 ? (num2 + 1 - prev) / prev : num2;
1180
+ const part = Math.floor(ratio);
1181
+ const alpha = [partialAlphabet(part), partialAlphabet(part + 1)];
1182
+ const leapStep = ratio % 1;
1183
+ let leapTotal = 0.5;
1184
+ let first = true;
1185
+ const strings = [];
1186
+ const generate = (full, str) => {
1187
+ if (full) {
1188
+ for (let i = 0; i < ALPHABET_SIZE; i++) {
1189
+ generate(full - 1, str + String.fromCharCode(CHAR_A + i));
1190
+ }
1191
+ } else {
1192
+ if (!first) strings.push(stripTrailingAs(str));
1193
+ else first = false;
1194
+ const leap = Math.floor(leapTotal += leapStep);
1195
+ leapTotal %= 1;
1196
+ for (let i = 0; i < part + leap; i++) {
1197
+ strings.push(str + (alpha[leap]?.[i] ?? ""));
1198
+ }
1199
+ }
1200
+ };
1201
+ generate(chars - 1, "");
1202
+ return strings;
1203
+ };
1204
+ var checkBalance = (xs) => {
1205
+ let largestOrderStr = 0;
1206
+ xs.forEach(
1207
+ (x) => largestOrderStr = Math.max(largestOrderStr, x.order.length)
1208
+ );
1209
+ return largestOrderStr > xs.length / 2;
1210
+ };
1211
+ var rebalance = (xs) => {
1212
+ const rebalancedOrderList = createRebalancedOrderList(xs.length);
1213
+ return xs.map((x, i) => ({ ...x, order: rebalancedOrderList[i] ?? x.order }));
1214
+ };
1215
+ var sortByOrder = (xs) => xs.toSorted((a, b) => (a.order ?? "").localeCompare(b.order ?? ""));
1216
+
1096
1217
  // src/server/os/index.ts
1097
1218
  var os_exports = {};
1098
1219
  __export(os_exports, {
@@ -1220,6 +1341,176 @@ var createSqsHandler = (fn) => async (event) => {
1220
1341
  return result;
1221
1342
  };
1222
1343
 
1344
+ // src/server/aws/apigw/index.ts
1345
+ var apigw_exports = {};
1346
+ __export(apigw_exports, {
1347
+ broadcast: () => broadcast,
1348
+ create: () => create2,
1349
+ createFromRequestContext: () => createFromRequestContext,
1350
+ createPublisher: () => createPublisher,
1351
+ deleteConnection: () => deleteConnection,
1352
+ send: () => send
1353
+ });
1354
+
1355
+ // src/server/aws/apigw/fns.ts
1356
+ var normalizePath = (path) => path.replace(/^\/+|\/+$/g, "");
1357
+ var getManagementEndpoint = (props) => {
1358
+ const domainName = props.domainName;
1359
+ if (!domainName) {
1360
+ throw new Error("Missing websocket domain name");
1361
+ }
1362
+ const rawPath = props.basePath ?? props.stage;
1363
+ if (rawPath == null) {
1364
+ throw new Error("Missing websocket stage or base path");
1365
+ }
1366
+ const protocol = props.protocol ?? "https";
1367
+ const path = normalizePath(rawPath);
1368
+ return path ? `${protocol}://${domainName}/${path}` : `${protocol}://${domainName}`;
1369
+ };
1370
+ var isGoneConnectionError = (error2) => {
1371
+ return !!(error2 && typeof error2 === "object" && "$metadata" in error2 && error2.$metadata?.httpStatusCode === 410);
1372
+ };
1373
+ var encodeData = (data) => {
1374
+ if (typeof data === "string") {
1375
+ return data;
1376
+ }
1377
+ if (data instanceof Uint8Array) {
1378
+ return data;
1379
+ }
1380
+ if (data instanceof ArrayBuffer) {
1381
+ return new Uint8Array(data);
1382
+ }
1383
+ if (ArrayBuffer.isView(data)) {
1384
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
1385
+ }
1386
+ const encoded = JSON.stringify(data);
1387
+ if (encoded === void 0) {
1388
+ throw new Error("Websocket payload must be JSON serializable");
1389
+ }
1390
+ return encoded;
1391
+ };
1392
+ var runWithConcurrency = async (items, concurrency, fn) => {
1393
+ const limit = Math.max(1, concurrency);
1394
+ let nextIndex = 0;
1395
+ await Promise.all(
1396
+ Array.from({ length: Math.min(limit, items.length) }, async () => {
1397
+ while (nextIndex < items.length) {
1398
+ const currentIndex = nextIndex;
1399
+ nextIndex += 1;
1400
+ await fn(items[currentIndex]);
1401
+ }
1402
+ })
1403
+ );
1404
+ };
1405
+
1406
+ // src/server/aws/apigw/domain.ts
1407
+ var create2 = (props) => {
1408
+ const client = new ApiGatewayManagementApiClient({
1409
+ endpoint: props.endpoint
1410
+ });
1411
+ return { client, endpoint: props.endpoint };
1412
+ };
1413
+ var createFromRequestContext = (props) => {
1414
+ return create2({ endpoint: getManagementEndpoint(props) });
1415
+ };
1416
+ var createPublisher = (apigw, props) => {
1417
+ const getConnectionId = props.getConnectionId;
1418
+ const onGone = props.onGone;
1419
+ return {
1420
+ send: (target, sendProps) => {
1421
+ return send(apigw, {
1422
+ connectionId: getConnectionId(target),
1423
+ data: sendProps.data,
1424
+ onGone: onGone ? () => onGone(target) : void 0
1425
+ });
1426
+ },
1427
+ broadcast: (broadcastProps) => {
1428
+ return broadcast(apigw, {
1429
+ ...broadcastProps,
1430
+ getConnectionId,
1431
+ onGone
1432
+ });
1433
+ }
1434
+ };
1435
+ };
1436
+ var send = async (apigw, props) => {
1437
+ try {
1438
+ await apigw.client.send(
1439
+ new PostToConnectionCommand({
1440
+ ConnectionId: props.connectionId,
1441
+ Data: encodeData(props.data)
1442
+ })
1443
+ );
1444
+ } catch (error2) {
1445
+ if (isGoneConnectionError(error2)) {
1446
+ await props.onGone?.(props.connectionId);
1447
+ return false;
1448
+ }
1449
+ throw error2;
1450
+ }
1451
+ return true;
1452
+ };
1453
+ var deleteConnection = (apigw, props) => {
1454
+ return apigw.client.send(
1455
+ new DeleteConnectionCommand({
1456
+ ConnectionId: props.connectionId
1457
+ })
1458
+ );
1459
+ };
1460
+ var broadcast = async (apigw, props) => {
1461
+ const result = {
1462
+ failed: [],
1463
+ stale: [],
1464
+ sent: 0
1465
+ };
1466
+ const sharedData = "data" in props ? encodeData(props.data) : null;
1467
+ const getData = "getData" in props ? props.getData : null;
1468
+ const getCacheKey = "getCacheKey" in props ? props.getCacheKey : void 0;
1469
+ const onGone = props.onGone;
1470
+ const cache = /* @__PURE__ */ new Map();
1471
+ const resolveData = async (target) => {
1472
+ if (sharedData !== null) {
1473
+ return sharedData;
1474
+ }
1475
+ if (!getData) {
1476
+ throw new Error("Missing websocket broadcast payload builder");
1477
+ }
1478
+ const cacheKey = getCacheKey?.(target);
1479
+ if (cacheKey == null) {
1480
+ return encodeData(await getData(target));
1481
+ }
1482
+ const existing = cache.get(cacheKey);
1483
+ if (existing) {
1484
+ return existing;
1485
+ }
1486
+ const promise = Promise.resolve(getData(target)).then(encodeData);
1487
+ cache.set(cacheKey, promise);
1488
+ return promise;
1489
+ };
1490
+ await runWithConcurrency(
1491
+ props.targets,
1492
+ props.concurrency ?? 25,
1493
+ async (target) => {
1494
+ const connectionId = props.getConnectionId(target);
1495
+ try {
1496
+ const delivered = await send(apigw, {
1497
+ connectionId,
1498
+ data: await resolveData(target),
1499
+ onGone: onGone ? () => onGone(target) : void 0
1500
+ });
1501
+ if (!delivered) {
1502
+ result.stale.push({ connectionId, target });
1503
+ return;
1504
+ }
1505
+ result.sent += 1;
1506
+ } catch (error2) {
1507
+ result.failed.push({ connectionId, error: error2, target });
1508
+ }
1509
+ }
1510
+ );
1511
+ return result;
1512
+ };
1513
+
1223
1514
  // src/server/aws/ddb/index.ts
1224
1515
  var ddb_exports = {};
1225
1516
  __export(ddb_exports, {
@@ -1227,7 +1518,7 @@ __export(ddb_exports, {
1227
1518
  batchGet: () => batchGet,
1228
1519
  batchWrite: () => batchWrite,
1229
1520
  copyTable: () => copyTable,
1230
- create: () => create2,
1521
+ create: () => create3,
1231
1522
  deleteTable: () => deleteTable,
1232
1523
  find: () => find,
1233
1524
  lsi1: () => lsi1,
@@ -1511,7 +1802,7 @@ var buildUpdateExpression = (ops, names, values) => {
1511
1802
  };
1512
1803
 
1513
1804
  // src/server/aws/ddb/domain.ts
1514
- var create2 = (props) => {
1805
+ var create3 = (props) => {
1515
1806
  const tableName = props?.tableName;
1516
1807
  const credentials = props?.credentials;
1517
1808
  const client = DynamoDBDocumentClient.from(
@@ -2393,11 +2684,11 @@ var copyTable = async (props) => {
2393
2684
  // src/server/aws/sns/index.ts
2394
2685
  var sns_exports = {};
2395
2686
  __export(sns_exports, {
2396
- create: () => create3,
2687
+ create: () => create4,
2397
2688
  publish: () => publish,
2398
2689
  publishError: () => publishError
2399
2690
  });
2400
- var create3 = (props) => {
2691
+ var create4 = (props) => {
2401
2692
  const client = new SNSClient({});
2402
2693
  return { client, topicArn: props?.topicArn };
2403
2694
  };
@@ -2432,8 +2723,8 @@ var publishError = (sns, props) => {
2432
2723
  // src/server/aws/sqs/index.ts
2433
2724
  var sqs_exports = {};
2434
2725
  __export(sqs_exports, {
2435
- create: () => create4,
2436
- send: () => send
2726
+ create: () => create5,
2727
+ send: () => send2
2437
2728
  });
2438
2729
 
2439
2730
  // src/server/aws/sqs/fns.ts
@@ -2447,12 +2738,12 @@ var getQueueUrlOrThrow = (...candidates) => {
2447
2738
  };
2448
2739
 
2449
2740
  // src/server/aws/sqs/domain.ts
2450
- var create4 = (props) => {
2741
+ var create5 = (props) => {
2451
2742
  const client = new SQSClient({});
2452
2743
  const queueUrl = props?.queueUrl;
2453
2744
  return { client, queueUrl };
2454
2745
  };
2455
- var send = (sqs, props) => sqs.client.send(
2746
+ var send2 = (sqs, props) => sqs.client.send(
2456
2747
  new SendMessageCommand({
2457
2748
  MessageBody: JSON.stringify(props.body),
2458
2749
  MessageGroupId: props.messageGroupId,
@@ -2463,16 +2754,16 @@ var send = (sqs, props) => sqs.client.send(
2463
2754
  // src/server/aws/ses/index.ts
2464
2755
  var ses_exports = {};
2465
2756
  __export(ses_exports, {
2466
- create: () => create5,
2467
- send: () => send2
2757
+ create: () => create6,
2758
+ send: () => send3
2468
2759
  });
2469
2760
 
2470
2761
  // src/server/aws/ses/fns.ts
2471
2762
  var stripHtml = (html) => html.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, "").replace(/<script[^>]*>[\s\S]*?<\/script>/gi, "").replace(/<[^>]+>/g, " ").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/\s+/g, " ").trim();
2472
2763
 
2473
2764
  // src/server/aws/ses/index.ts
2474
- var create5 = () => new SESClient({ apiVersion: "2010-12-01" });
2475
- var send2 = (ses, email) => {
2765
+ var create6 = () => new SESClient({ apiVersion: "2010-12-01" });
2766
+ var send3 = (ses, email) => {
2476
2767
  const Source = `"${email.fromName}" <${email.from}>`;
2477
2768
  console.log(`[ses] Sending email to ${email.to} from ${email.from}`);
2478
2769
  const Destination = { ToAddresses: [email.to] };
@@ -2497,7 +2788,7 @@ var s3_exports = {};
2497
2788
  __export(s3_exports, {
2498
2789
  bucketExists: () => bucketExists,
2499
2790
  copyFile: () => copyFile,
2500
- create: () => create6,
2791
+ create: () => create7,
2501
2792
  createBucket: () => createBucket,
2502
2793
  createSignedUrl: () => createSignedUrl,
2503
2794
  deleteBucket: () => deleteBucket,
@@ -2524,7 +2815,7 @@ var getBucketNameOrThrow = (...candidates) => {
2524
2815
  };
2525
2816
 
2526
2817
  // src/server/aws/s3/domain.ts
2527
- var create6 = (props = {}) => {
2818
+ var create7 = (props = {}) => {
2528
2819
  const { cdn } = props;
2529
2820
  const client = new S3Client({});
2530
2821
  const bucketName = getBucketNameOrThrow(props.bucketName);
@@ -2779,4 +3070,4 @@ var recordsFromSqs = (body) => {
2779
3070
  }
2780
3071
  };
2781
3072
 
2782
- export { api_exports as Api, ddb_exports as DDB, dict_exports as Dict, file_exports as File, flow_exports as Flow, int_exports as Int, lambda_exports as Lambda, list_exports as List, log_exports as Log, money_exports as Money, os_exports as Os, random_exports as Random, s3_exports as S3, ses_exports as SES, sns_exports as SNS, sqs_exports as SQS, str_exports as Str, time_exports as Time };
3073
+ export { api_exports as Api, apigw_exports as ApiGw, ddb_exports as DDB, dict_exports as Dict, file_exports as File, flow_exports as Flow, int_exports as Int, lambda_exports as Lambda, lexorank_exports as LexoRank, list_exports as List, log_exports as Log, money_exports as Money, os_exports as Os, random_exports as Random, s3_exports as S3, ses_exports as SES, sns_exports as SNS, sqs_exports as SQS, str_exports as Str, time_exports as Time };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qstd",
3
- "version": "0.3.85",
3
+ "version": "0.3.87",
4
4
  "description": "Standard Block component and utilities library with Panda CSS",
5
5
  "author": "malin1",
6
6
  "license": "MIT",
@@ -66,6 +66,7 @@
66
66
  "react-dom": "^18.0.0 || ^19.0.0"
67
67
  },
68
68
  "dependencies": {
69
+ "@aws-sdk/client-apigatewaymanagementapi": "latest",
69
70
  "@aws-sdk/client-dynamodb": "latest",
70
71
  "@aws-sdk/client-s3": "latest",
71
72
  "@aws-sdk/client-ses": "latest",