@okf/ootils 1.28.1 → 1.28.3

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/universal.js CHANGED
@@ -35,8 +35,6 @@ __export(universal_exports, {
35
35
  extractAllBlocksFromTpl: () => extractAllBlocksFromTpl,
36
36
  extractAndOrganizeBlocks: () => extractAndOrganizeBlocks,
37
37
  genCleanCamelCaseId: () => genCleanCamelCaseId,
38
- genCleanContentTypeId: () => genCleanContentTypeId,
39
- genCleanValuePath: () => genCleanValuePath,
40
38
  genTagId: () => genTagId,
41
39
  generateFilterKey: () => generateFilterKey,
42
40
  getFilterKeyForBlock: () => getFilterKeyForBlock,
@@ -739,6 +737,30 @@ var BASE_BULLMQ_CONFIG = {
739
737
  maxStalledCount: 3
740
738
  }
741
739
  },
740
+ USERS_ELASTIC_SYNC_QUEUE: {
741
+ id: "users-elastic-sync-queue",
742
+ queueConfig: {
743
+ defaultJobOptions: {
744
+ attempts: 3,
745
+ backoff: {
746
+ type: "exponential",
747
+ delay: 2e3
748
+ },
749
+ removeOnComplete: 30,
750
+ removeOnFail: 100
751
+ },
752
+ streams: {
753
+ events: {
754
+ maxLen: 10
755
+ }
756
+ }
757
+ },
758
+ workerConfig: {
759
+ concurrency: 50,
760
+ lockDuration: 9e4,
761
+ maxStalledCount: 3
762
+ }
763
+ },
742
764
  CONTENT_ELASTIC_SYNC_QUEUE: {
743
765
  id: "content-elastic-sync-queue",
744
766
  queueConfig: {
@@ -2128,54 +2150,28 @@ var autoGenFilterConfigsFromTpl = ({
2128
2150
  };
2129
2151
 
2130
2152
  // src/utils/genCleanCamelCaseId.ts
2131
- var genCleanCamelCaseId = (id, options) => {
2153
+ var MAX_LENGTH = 40;
2154
+ function fnv1a(str, length = 8) {
2155
+ let hash = 2166136261;
2156
+ for (let i = 0; i < str.length; i++) {
2157
+ hash ^= str.charCodeAt(i);
2158
+ hash = hash * 16777619 >>> 0;
2159
+ }
2160
+ return hash.toString(36).slice(0, length);
2161
+ }
2162
+ var genCleanCamelCaseId = (id) => {
2132
2163
  if (!id || typeof id !== "string") return id;
2133
- const { stripNonAlphanumeric = false, maxLength } = options || {};
2134
- const baseClean = /^\p{Ll}[\p{L}\p{N}]*$/u.test(id) || /^a\d[\p{L}\p{N}]*$/u.test(id);
2135
- const withinMaxLength = maxLength ? id.length <= maxLength : true;
2136
- const hasNoNonAlpha = stripNonAlphanumeric ? /^[a-zA-Z0-9]+$/.test(id) : true;
2137
- if (baseClean && withinMaxLength && hasNoNonAlpha) return id;
2164
+ if ((/^[a-z][a-zA-Z0-9]*$/.test(id) || /^a\d[a-zA-Z0-9]*$/.test(id)) && id.length <= MAX_LENGTH) return id;
2138
2165
  const words = id.split(/[^\p{L}\p{N}]+/u).filter(Boolean);
2139
2166
  if (words.length === 0) return "a";
2140
2167
  let result = words.map((word, i) => {
2141
2168
  const lower = word.toLowerCase();
2142
2169
  return i === 0 ? lower : lower.charAt(0).toUpperCase() + lower.slice(1);
2143
2170
  }).join("");
2171
+ const strippedResult = result.replace(/[^a-zA-Z0-9]/g, "");
2172
+ result = strippedResult || fnv1a(result);
2144
2173
  if (/^\d/.test(result)) result = "a" + result;
2145
- if (stripNonAlphanumeric) {
2146
- result = result.replace(/[^a-zA-Z0-9]/g, "");
2147
- }
2148
- if (maxLength) {
2149
- result = result.slice(0, maxLength);
2150
- }
2151
- return result;
2152
- };
2153
-
2154
- // src/utils/genCleanContentTypeId.ts
2155
- var genCleanContentTypeId = (text) => genCleanCamelCaseId(text, { stripNonAlphanumeric: true, maxLength: 40 });
2156
-
2157
- // src/utils/genCleanValuePath.ts
2158
- var CHARS = "abcdefghijklmnopqrstuvwxyz0123456789";
2159
- function genShortId(length = 4) {
2160
- let result = "";
2161
- for (let i = 0; i < length; i++) {
2162
- result += CHARS[Math.floor(Math.random() * CHARS.length)];
2163
- }
2164
- return result;
2165
- }
2166
- var genCleanValuePath = (text) => {
2167
- const maxLength = 10;
2168
- const shortIdLength = 4;
2169
- if (!text || typeof text !== "string") return text;
2170
- const idempotencyPattern = new RegExp(`^[a-z][a-z0-9]*_[a-z0-9]{${shortIdLength}}$`);
2171
- if (idempotencyPattern.test(text)) return text;
2172
- let cleaned = text.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
2173
- if (!cleaned) {
2174
- throw new Error(`[genCleanValuePath] Input "${text}" contains no alphanumeric characters`);
2175
- }
2176
- if (/^\d/.test(cleaned)) cleaned = "a" + cleaned;
2177
- const truncated = cleaned.slice(0, maxLength);
2178
- return `${truncated}_${genShortId(shortIdLength)}`;
2174
+ return result.slice(0, MAX_LENGTH);
2179
2175
  };
2180
2176
  // Annotate the CommonJS export names for ESM import in node:
2181
2177
  0 && (module.exports = {
@@ -2194,8 +2190,6 @@ var genCleanValuePath = (text) => {
2194
2190
  extractAllBlocksFromTpl,
2195
2191
  extractAndOrganizeBlocks,
2196
2192
  genCleanCamelCaseId,
2197
- genCleanContentTypeId,
2198
- genCleanValuePath,
2199
2193
  genTagId,
2200
2194
  generateFilterKey,
2201
2195
  getFilterKeyForBlock,
@@ -681,6 +681,30 @@ var BASE_BULLMQ_CONFIG = {
681
681
  maxStalledCount: 3
682
682
  }
683
683
  },
684
+ USERS_ELASTIC_SYNC_QUEUE: {
685
+ id: "users-elastic-sync-queue",
686
+ queueConfig: {
687
+ defaultJobOptions: {
688
+ attempts: 3,
689
+ backoff: {
690
+ type: "exponential",
691
+ delay: 2e3
692
+ },
693
+ removeOnComplete: 30,
694
+ removeOnFail: 100
695
+ },
696
+ streams: {
697
+ events: {
698
+ maxLen: 10
699
+ }
700
+ }
701
+ },
702
+ workerConfig: {
703
+ concurrency: 50,
704
+ lockDuration: 9e4,
705
+ maxStalledCount: 3
706
+ }
707
+ },
684
708
  CONTENT_ELASTIC_SYNC_QUEUE: {
685
709
  id: "content-elastic-sync-queue",
686
710
  queueConfig: {
@@ -2070,54 +2094,28 @@ var autoGenFilterConfigsFromTpl = ({
2070
2094
  };
2071
2095
 
2072
2096
  // src/utils/genCleanCamelCaseId.ts
2073
- var genCleanCamelCaseId = (id, options) => {
2097
+ var MAX_LENGTH = 40;
2098
+ function fnv1a(str, length = 8) {
2099
+ let hash = 2166136261;
2100
+ for (let i = 0; i < str.length; i++) {
2101
+ hash ^= str.charCodeAt(i);
2102
+ hash = hash * 16777619 >>> 0;
2103
+ }
2104
+ return hash.toString(36).slice(0, length);
2105
+ }
2106
+ var genCleanCamelCaseId = (id) => {
2074
2107
  if (!id || typeof id !== "string") return id;
2075
- const { stripNonAlphanumeric = false, maxLength } = options || {};
2076
- const baseClean = /^\p{Ll}[\p{L}\p{N}]*$/u.test(id) || /^a\d[\p{L}\p{N}]*$/u.test(id);
2077
- const withinMaxLength = maxLength ? id.length <= maxLength : true;
2078
- const hasNoNonAlpha = stripNonAlphanumeric ? /^[a-zA-Z0-9]+$/.test(id) : true;
2079
- if (baseClean && withinMaxLength && hasNoNonAlpha) return id;
2108
+ if ((/^[a-z][a-zA-Z0-9]*$/.test(id) || /^a\d[a-zA-Z0-9]*$/.test(id)) && id.length <= MAX_LENGTH) return id;
2080
2109
  const words = id.split(/[^\p{L}\p{N}]+/u).filter(Boolean);
2081
2110
  if (words.length === 0) return "a";
2082
2111
  let result = words.map((word, i) => {
2083
2112
  const lower = word.toLowerCase();
2084
2113
  return i === 0 ? lower : lower.charAt(0).toUpperCase() + lower.slice(1);
2085
2114
  }).join("");
2115
+ const strippedResult = result.replace(/[^a-zA-Z0-9]/g, "");
2116
+ result = strippedResult || fnv1a(result);
2086
2117
  if (/^\d/.test(result)) result = "a" + result;
2087
- if (stripNonAlphanumeric) {
2088
- result = result.replace(/[^a-zA-Z0-9]/g, "");
2089
- }
2090
- if (maxLength) {
2091
- result = result.slice(0, maxLength);
2092
- }
2093
- return result;
2094
- };
2095
-
2096
- // src/utils/genCleanContentTypeId.ts
2097
- var genCleanContentTypeId = (text) => genCleanCamelCaseId(text, { stripNonAlphanumeric: true, maxLength: 40 });
2098
-
2099
- // src/utils/genCleanValuePath.ts
2100
- var CHARS = "abcdefghijklmnopqrstuvwxyz0123456789";
2101
- function genShortId(length = 4) {
2102
- let result = "";
2103
- for (let i = 0; i < length; i++) {
2104
- result += CHARS[Math.floor(Math.random() * CHARS.length)];
2105
- }
2106
- return result;
2107
- }
2108
- var genCleanValuePath = (text) => {
2109
- const maxLength = 10;
2110
- const shortIdLength = 4;
2111
- if (!text || typeof text !== "string") return text;
2112
- const idempotencyPattern = new RegExp(`^[a-z][a-z0-9]*_[a-z0-9]{${shortIdLength}}$`);
2113
- if (idempotencyPattern.test(text)) return text;
2114
- let cleaned = text.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
2115
- if (!cleaned) {
2116
- throw new Error(`[genCleanValuePath] Input "${text}" contains no alphanumeric characters`);
2117
- }
2118
- if (/^\d/.test(cleaned)) cleaned = "a" + cleaned;
2119
- const truncated = cleaned.slice(0, maxLength);
2120
- return `${truncated}_${genShortId(shortIdLength)}`;
2118
+ return result.slice(0, MAX_LENGTH);
2121
2119
  };
2122
2120
  export {
2123
2121
  BASE_BULLMQ_CONFIG,
@@ -2135,8 +2133,6 @@ export {
2135
2133
  extractAllBlocksFromTpl,
2136
2134
  extractAndOrganizeBlocks,
2137
2135
  genCleanCamelCaseId,
2138
- genCleanContentTypeId,
2139
- genCleanValuePath,
2140
2136
  genTagId,
2141
2137
  generateFilterKey,
2142
2138
  getFilterKeyForBlock,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.28.1",
6
+ "version": "1.28.3",
7
7
  "description": "Utility functions for both browser and Node.js",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.mjs",