@cyberskill/shared 3.13.0 → 3.15.0

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.
Files changed (97) hide show
  1. package/dist/config/env/env.util.d.ts +5 -0
  2. package/dist/config/env/env.util.js +20 -16
  3. package/dist/config/env/env.util.js.map +1 -1
  4. package/dist/config/env/index.js +2 -2
  5. package/dist/config/vitest/vitest.e2e.js +4 -4
  6. package/dist/config/vitest/vitest.e2e.js.map +1 -1
  7. package/dist/config/vitest/vitest.unit.js +5 -5
  8. package/dist/config/vitest/vitest.unit.js.map +1 -1
  9. package/dist/config/vitest/vitest.unit.setup.js +10 -0
  10. package/dist/config/vitest/vitest.unit.setup.js.map +1 -0
  11. package/dist/node/apollo-server/apollo-server.type.d.ts +13 -1
  12. package/dist/node/apollo-server/apollo-server.util.d.ts +1 -0
  13. package/dist/node/apollo-server/apollo-server.util.js +40 -16
  14. package/dist/node/apollo-server/apollo-server.util.js.map +1 -1
  15. package/dist/node/cli/index.js +26 -28
  16. package/dist/node/cli/index.js.map +1 -1
  17. package/dist/node/command/command.util.d.ts +5 -0
  18. package/dist/node/command/command.util.js +49 -48
  19. package/dist/node/command/command.util.js.map +1 -1
  20. package/dist/node/command/index.js +2 -2
  21. package/dist/node/express/express.type.d.ts +11 -0
  22. package/dist/node/express/express.util.d.ts +34 -6
  23. package/dist/node/express/express.util.js +81 -56
  24. package/dist/node/express/express.util.js.map +1 -1
  25. package/dist/node/express/index.js +2 -2
  26. package/dist/node/log/log.type.d.ts +17 -0
  27. package/dist/node/log/log.type.js.map +1 -1
  28. package/dist/node/log/log.util.js +25 -11
  29. package/dist/node/log/log.util.js.map +1 -1
  30. package/dist/node/mongo/index.d.ts +2 -1
  31. package/dist/node/mongo/index.js +7 -8
  32. package/dist/node/mongo/mongo.constant.d.ts +5 -0
  33. package/dist/node/mongo/mongo.constant.js +2 -2
  34. package/dist/node/mongo/mongo.constant.js.map +1 -1
  35. package/dist/node/mongo/mongo.controller.mongoose.d.ts +3 -0
  36. package/dist/node/mongo/mongo.controller.mongoose.js +41 -55
  37. package/dist/node/mongo/mongo.controller.mongoose.js.map +1 -1
  38. package/dist/node/mongo/mongo.controller.native.d.ts +29 -2
  39. package/dist/node/mongo/mongo.controller.native.js +31 -14
  40. package/dist/node/mongo/mongo.controller.native.js.map +1 -1
  41. package/dist/node/mongo/mongo.type.d.ts +3 -1
  42. package/dist/node/mongo/mongo.util.d.ts +1 -0
  43. package/dist/node/mongo/mongo.util.js +38 -17
  44. package/dist/node/mongo/mongo.util.js.map +1 -1
  45. package/dist/node/package/package.util.js +47 -47
  46. package/dist/node/path/index.js +2 -2
  47. package/dist/node/path/path.constant.d.ts +4 -0
  48. package/dist/node/path/path.constant.js +75 -72
  49. package/dist/node/path/path.constant.js.map +1 -1
  50. package/dist/node/storage/storage.util.d.ts +50 -1
  51. package/dist/node/storage/storage.util.js +79 -54
  52. package/dist/node/storage/storage.util.js.map +1 -1
  53. package/dist/node/upload/upload.type.d.ts +2 -0
  54. package/dist/node/upload/upload.type.js.map +1 -1
  55. package/dist/node/upload/upload.util.d.ts +1 -0
  56. package/dist/node/upload/upload.util.js +62 -52
  57. package/dist/node/upload/upload.util.js.map +1 -1
  58. package/dist/node/ws/ws.util.d.ts +7 -0
  59. package/dist/node/ws/ws.util.js +20 -19
  60. package/dist/node/ws/ws.util.js.map +1 -1
  61. package/dist/react/apollo-client/apollo-client.component.js.map +1 -1
  62. package/dist/react/apollo-client/apollo-client.type.d.ts +2 -0
  63. package/dist/react/apollo-client/apollo-client.util.js +6 -6
  64. package/dist/react/apollo-client/apollo-client.util.js.map +1 -1
  65. package/dist/react/apollo-error/apollo-error.component.js +1 -1
  66. package/dist/react/apollo-error/apollo-error.component.js.map +1 -1
  67. package/dist/react/apollo-error/apollo-error.util.js.map +1 -1
  68. package/dist/react/i18next/i18next.server.d.ts +17 -0
  69. package/dist/react/i18next/i18next.server.js +9 -0
  70. package/dist/react/i18next/i18next.server.js.map +1 -0
  71. package/dist/react/next-intl/next-intl.hoc.d.ts +4 -8
  72. package/dist/react/next-intl/next-intl.hoc.js +14 -10
  73. package/dist/react/next-intl/next-intl.hoc.js.map +1 -1
  74. package/dist/react/next-intl/next-intl.server.d.ts +10 -0
  75. package/dist/react/next-intl/next-intl.server.js +7 -0
  76. package/dist/react/next-intl/next-intl.server.js.map +1 -0
  77. package/dist/react/storage/storage.util.d.ts +34 -1
  78. package/dist/react/storage/storage.util.js +30 -5
  79. package/dist/react/storage/storage.util.js.map +1 -1
  80. package/dist/react/userback/userback.component.js.map +1 -1
  81. package/dist/typescript/common.type.d.ts +4 -0
  82. package/dist/typescript/common.type.js +2 -2
  83. package/dist/typescript/common.type.js.map +1 -1
  84. package/dist/typescript/index.js +2 -2
  85. package/dist/util/object/object.util.js +29 -18
  86. package/dist/util/object/object.util.js.map +1 -1
  87. package/dist/util/serializer/serializer.util.d.ts +8 -0
  88. package/dist/util/serializer/serializer.util.js +51 -64
  89. package/dist/util/serializer/serializer.util.js.map +1 -1
  90. package/dist/util/storage/storage-envelope.d.ts +25 -0
  91. package/dist/util/storage/storage-envelope.js +18 -0
  92. package/dist/util/storage/storage-envelope.js.map +1 -0
  93. package/package.json +33 -12
  94. package/dist/node/mongo/mongo.type.js +0 -8
  95. package/dist/node/mongo/mongo.type.js.map +0 -1
  96. package/dist/node_modules/.pnpm/vitest@4.1.2_@types_node@25.5.0_jsdom@29.0.1_@noble_hashes@1.8.0__vite@8.0.3_@types_nod_0827261ede788764a5d99ac6bdf44bde/node_modules/vitest/dist/config.js +0 -8
  97. package/dist/node_modules/.pnpm/vitest@4.1.2_@types_node@25.5.0_jsdom@29.0.1_@noble_hashes@1.8.0__vite@8.0.3_@types_nod_0827261ede788764a5d99ac6bdf44bde/node_modules/vitest/dist/config.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"serializer.util.js","names":[],"sources":["../../../src/util/serializer/serializer.util.ts"],"sourcesContent":["import type {\n I_Serializer,\n I_SerializerTypeWrapper,\n I_SerializerValueMap,\n T_SerializerKnownTypes,\n} from './serializer.type.js';\n\n/**\n * Interface for handling serialization and deserialization of specific types.\n * Each handler provides methods to check if a value is of the specific type,\n * serialize it to a format that can be JSON stringified, and deserialize it back.\n */\ninterface I_Handler<T extends T_SerializerKnownTypes> {\n /** Checks if a value is of the specific type */\n is: (value: unknown) => value is I_SerializerValueMap[T];\n /** Serializes a value of the specific type to a format that can be JSON stringified */\n serialize: (value: I_SerializerValueMap[T]) => I_SerializerTypeWrapper<T>;\n /** Deserializes a value back to the specific type */\n deserialize: (value: unknown) => I_SerializerValueMap[T];\n}\n\n/**\n * Type handlers for different JavaScript types that cannot be directly serialized to JSON.\n * Each handler provides methods to serialize and deserialize specific types like Date, Map, Set, etc.\n */\nconst typeHandlers: {\n [K in T_SerializerKnownTypes]: I_Handler<K>;\n} = {\n Date: {\n is: (v): v is Date => v instanceof Date,\n serialize: v => ({ __type: 'Date', value: v.toISOString() }),\n deserialize: v => new Date(v as string),\n },\n Map: {\n is: (v): v is Map<unknown, unknown> => v instanceof Map,\n serialize: v => ({ __type: 'Map', value: [...v.entries()] }),\n deserialize: v => new Map(v as [unknown, unknown][]),\n },\n Set: {\n is: (v): v is Set<unknown> => v instanceof Set,\n serialize: v => ({ __type: 'Set', value: [...v] }),\n deserialize: v => new Set(v as unknown[]),\n },\n RegExp: {\n is: (v): v is RegExp => v instanceof RegExp,\n serialize: v => ({\n __type: 'RegExp',\n value: { source: v.source, flags: v.flags },\n }),\n deserialize: (v) => {\n const { source, flags } = v as { source: string; flags: string };\n return new RegExp(source, flags);\n },\n },\n BigInt: {\n is: (v): v is bigint => typeof v === 'bigint',\n serialize: v => ({ __type: 'BigInt', value: v.toString() }),\n deserialize: v => BigInt(v as string),\n },\n};\n\nconst typeHandlersValues = (Object.entries(typeHandlers) as [\n T_SerializerKnownTypes,\n I_Handler<T_SerializerKnownTypes>,\n][])\n .filter(([key]) => key !== 'Date')\n .map(([, handler]) => handler);\n\n/**\n * A serializer that can handle complex JavaScript types that cannot be directly JSON stringified.\n * This serializer extends JSON.stringify and JSON.parse to handle types like Date, Map, Set, RegExp, and BigInt.\n *\n * The serializer works by:\n * 1. During serialization: Wrapping special types with type information before JSON stringification\n * 2. During deserialization: Detecting wrapped types and reconstructing them to their original form\n *\n * @remarks\n * **Wire format protocol:** Non-JSON-native types are serialized as wrapper objects with the shape\n * `{ __type: string, value: unknown }`. For example:\n * - Date → `{ __type: 'Date', value: '2024-01-01T00:00:00.000Z' }`\n * - Map → `{ __type: 'Map', value: [['key', 'val']] }`\n * - Set → `{ __type: 'Set', value: [1, 2, 3] }`\n * - RegExp → `{ __type: 'RegExp', value: { source: '...', flags: '...' } }`\n * - BigInt → `{ __type: 'BigInt', value: '12345' }`\n *\n * **Cross-service compatibility:** Any service that deserializes data produced by this serializer\n * must use the same `__type` protocol. Plain `JSON.parse` will return the wrapper objects as-is\n * without reconstructing the original types.\n */\nexport const serializer: I_Serializer<unknown> = {\n /**\n * Serializes a value to a JSON string.\n * If the value is of a known type (Date, Map, Set, RegExp, BigInt),\n * it will be serialized using the corresponding handler.\n * Otherwise, it will be serialized as is.\n *\n * @param value - The value to serialize to a JSON string.\n * @returns The serialized JSON string that can be safely stored or transmitted.\n */\n serialize(value) {\n return JSON.stringify(value, function (_key, val) {\n // eslint-disable-next-line ts/no-this-alias\n const context = this;\n const originalValue = context[_key];\n\n if (originalValue instanceof Date) {\n return typeHandlers.Date.serialize(originalValue);\n }\n\n for (let i = 0; i < typeHandlersValues.length; i++) {\n const handler = typeHandlersValues[i]!;\n\n if (handler.is(val)) {\n return handler.serialize(val as I_SerializerValueMap[T_SerializerKnownTypes]);\n }\n }\n\n return val;\n });\n },\n /**\n * Deserializes a JSON string to its original value.\n * If the value is of a known type (Date, Map, Set, RegExp, BigInt),\n * it will be deserialized using the corresponding handler.\n * Otherwise, it will be deserialized as is.\n *\n * @param json - The JSON string to deserialize back to its original form.\n * @returns The deserialized value with all special types reconstructed.\n */\n deserialize(json) {\n return JSON.parse(json, (_key, val) => {\n if (\n val\n && typeof val === 'object'\n && '__type' in val\n && typeof val.__type === 'string'\n ) {\n const type = val.__type as T_SerializerKnownTypes;\n const handler = typeHandlers[type];\n\n if (handler) {\n return handler.deserialize(val.value);\n }\n }\n return val;\n });\n },\n};\n"],"mappings":";AAyBA,IAAM,IAEF;CACA,MAAM;EACF,KAAK,MAAiB,aAAa;EACnC,YAAW,OAAM;GAAE,QAAQ;GAAQ,OAAO,EAAE,aAAa;GAAE;EAC3D,cAAa,MAAK,IAAI,KAAK,EAAY;EAC1C;CACD,KAAK;EACD,KAAK,MAAkC,aAAa;EACpD,YAAW,OAAM;GAAE,QAAQ;GAAO,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC;GAAE;EAC3D,cAAa,MAAK,IAAI,IAAI,EAA0B;EACvD;CACD,KAAK;EACD,KAAK,MAAyB,aAAa;EAC3C,YAAW,OAAM;GAAE,QAAQ;GAAO,OAAO,CAAC,GAAG,EAAE;GAAE;EACjD,cAAa,MAAK,IAAI,IAAI,EAAe;EAC5C;CACD,QAAQ;EACJ,KAAK,MAAmB,aAAa;EACrC,YAAW,OAAM;GACb,QAAQ;GACR,OAAO;IAAE,QAAQ,EAAE;IAAQ,OAAO,EAAE;IAAO;GAC9C;EACD,cAAc,MAAM;GAChB,IAAM,EAAE,WAAQ,aAAU;AAC1B,UAAO,IAAI,OAAO,GAAQ,EAAM;;EAEvC;CACD,QAAQ;EACJ,KAAK,MAAmB,OAAO,KAAM;EACrC,YAAW,OAAM;GAAE,QAAQ;GAAU,OAAO,EAAE,UAAU;GAAE;EAC1D,cAAa,MAAK,OAAO,EAAY;EACxC;CACJ,EAEK,IAAsB,OAAO,QAAQ,EAAa,CAInD,QAAQ,CAAC,OAAS,MAAQ,OAAO,CACjC,KAAK,GAAG,OAAa,EAAQ,EAuBrB,IAAoC;CAU7C,UAAU,GAAO;AACb,SAAO,KAAK,UAAU,GAAO,SAAU,GAAM,GAAK;GAG9C,IAAM,IADU,KACc;AAE9B,OAAI,aAAyB,KACzB,QAAO,EAAa,KAAK,UAAU,EAAc;AAGrD,QAAK,IAAI,IAAI,GAAG,IAAI,EAAmB,QAAQ,KAAK;IAChD,IAAM,IAAU,EAAmB;AAEnC,QAAI,EAAQ,GAAG,EAAI,CACf,QAAO,EAAQ,UAAU,EAAoD;;AAIrF,UAAO;IACT;;CAWN,YAAY,GAAM;AACd,SAAO,KAAK,MAAM,IAAO,GAAM,MAAQ;AACnC,OACI,KACG,OAAO,KAAQ,YACf,YAAY,KACZ,OAAO,EAAI,UAAW,UAC3B;IAEE,IAAM,IAAU,EADH,EAAI;AAGjB,QAAI,EACA,QAAO,EAAQ,YAAY,EAAI,MAAM;;AAG7C,UAAO;IACT;;CAET"}
1
+ {"version":3,"file":"serializer.util.js","names":[],"sources":["../../../src/util/serializer/serializer.util.ts"],"sourcesContent":["import type {\n I_Serializer,\n} from './serializer.type.js';\n\nconst ALLOWED_TYPES = new Set(['Date', 'Map', 'Set', 'RegExp', 'BigInt']);\nconst MAX_REGEXP_SOURCE_LENGTH = 1_000;\nconst VALID_REGEXP_FLAGS = /^[dgimsuvy]*$/;\n\n/**\n * A serializer that can handle complex JavaScript types that cannot be directly JSON stringified.\n * This serializer extends JSON.stringify and JSON.parse to handle types like Date, Map, Set, RegExp, and BigInt.\n *\n * The serializer works by:\n * 1. During serialization: Wrapping special types with type information before JSON stringification\n * 2. During deserialization: Detecting wrapped types and reconstructing them to their original form\n *\n * @remarks\n * **Wire format protocol:** Non-JSON-native types are serialized as wrapper objects with the shape\n * `{ __type: string, value: unknown }`. For example:\n * - Date → `{ __type: 'Date', value: '2024-01-01T00:00:00.000Z' }`\n * - Map → `{ __type: 'Map', value: [['key', 'val']] }`\n * - Set → `{ __type: 'Set', value: [1, 2, 3] }`\n * - RegExp → `{ __type: 'RegExp', value: { source: '...', flags: '...' } }`\n * - BigInt → `{ __type: 'BigInt', value: '12345' }`\n *\n * **Security:** Only types in the `ALLOWED_TYPES` allowlist are reconstructed during\n * deserialization. Unknown `__type` values are returned as-is to prevent prototype pollution.\n * RegExp sources are length-limited (1000 chars) and flags are validated to mitigate ReDoS.\n *\n * **⚠️ NOT for untrusted input:** This serializer is designed for internal service-to-service\n * communication. Do NOT use it to deserialize user-controlled payloads (e.g., raw WebSocket\n * messages, API request bodies from external clients) without additional validation.\n *\n * **Cross-service compatibility:** Any service that deserializes data produced by this serializer\n * must use the same `__type` protocol. Plain `JSON.parse` will return the wrapper objects as-is\n * without reconstructing the original types.\n */\nexport const serializer: I_Serializer<unknown> = {\n /**\n * Serializes a value to a JSON string.\n * If the value is of a known type (Date, Map, Set, RegExp, BigInt),\n * it will be serialized using the corresponding handler.\n * Otherwise, it will be serialized as is.\n *\n * @param value - The value to serialize to a JSON string.\n * @returns The serialized JSON string that can be safely stored or transmitted.\n */\n serialize(value) {\n return JSON.stringify(value, function (this: Record<string, unknown>, _key, val) {\n // Date#toJSON fires before the replacer, converting a Date to an ISO string.\n // We must read this[_key] to detect the original Date object.\n const originalValue = this[_key];\n if (originalValue instanceof Date) {\n return { __type: 'Date', value: originalValue.toISOString() };\n }\n\n // For all other special types, val is already the original value\n // (they have no toJSON), so use val directly to avoid the extra property access.\n if (val !== null && typeof val === 'object') {\n if (val instanceof Map) {\n return { __type: 'Map', value: Array.from(val.entries()) };\n }\n if (val instanceof Set) {\n return { __type: 'Set', value: Array.from(val) };\n }\n if (val instanceof RegExp) {\n return { __type: 'RegExp', value: { source: val.source, flags: val.flags } };\n }\n }\n else if (typeof val === 'bigint') {\n return { __type: 'BigInt', value: val.toString() };\n }\n\n return val;\n });\n },\n /**\n * Deserializes a JSON string to its original value.\n * If the value is of a known type (Date, Map, Set, RegExp, BigInt),\n * it will be deserialized using the corresponding handler.\n * Otherwise, it will be deserialized as is.\n * Unknown `__type` values are ignored (returned as-is) for security.\n *\n * @param json - The JSON string to deserialize back to its original form.\n * @returns The deserialized value with all special types reconstructed.\n */\n deserialize(json) {\n return JSON.parse(json, (_key, val) => {\n if (val !== null && typeof val === 'object' && typeof val.__type === 'string') {\n const type = val.__type;\n\n // Security: Only reconstruct types in the allowlist\n if (!ALLOWED_TYPES.has(type)) {\n return val;\n }\n\n const value = val.value;\n\n if (type === 'Date') {\n return new Date(value as string);\n }\n if (type === 'Map') {\n return new Map(value as [unknown, unknown][]);\n }\n if (type === 'Set') {\n return new Set(value as unknown[]);\n }\n if (type === 'RegExp') {\n const { source, flags } = value as { source: string; flags: string };\n if (\n typeof source !== 'string'\n || typeof flags !== 'string'\n || source.length > MAX_REGEXP_SOURCE_LENGTH\n || !VALID_REGEXP_FLAGS.test(flags)\n ) {\n return val;\n }\n return new RegExp(source, flags);\n }\n if (type === 'BigInt') {\n return BigInt(value as string);\n }\n }\n return val;\n });\n },\n};\n"],"mappings":";AAIA,IAAM,IAAgB,IAAI,IAAI;CAAC;CAAQ;CAAO;CAAO;CAAU;CAAS,CAAC,EACnE,IAA2B,KAC3B,IAAqB,iBA+Bd,IAAoC;CAU7C,UAAU,GAAO;AACb,SAAO,KAAK,UAAU,GAAO,SAAyC,GAAM,GAAK;GAG7E,IAAM,IAAgB,KAAK;AAC3B,OAAI,aAAyB,KACzB,QAAO;IAAE,QAAQ;IAAQ,OAAO,EAAc,aAAa;IAAE;AAKjE,OAAoB,OAAO,KAAQ,YAA/B,GAAyC;AACzC,QAAI,aAAe,IACf,QAAO;KAAE,QAAQ;KAAO,OAAO,MAAM,KAAK,EAAI,SAAS,CAAC;KAAE;AAE9D,QAAI,aAAe,IACf,QAAO;KAAE,QAAQ;KAAO,OAAO,MAAM,KAAK,EAAI;KAAE;AAEpD,QAAI,aAAe,OACf,QAAO;KAAE,QAAQ;KAAU,OAAO;MAAE,QAAQ,EAAI;MAAQ,OAAO,EAAI;MAAO;KAAE;cAG3E,OAAO,KAAQ,SACpB,QAAO;IAAE,QAAQ;IAAU,OAAO,EAAI,UAAU;IAAE;AAGtD,UAAO;IACT;;CAYN,YAAY,GAAM;AACd,SAAO,KAAK,MAAM,IAAO,GAAM,MAAQ;AACnC,OAAoB,OAAO,KAAQ,YAA/B,KAA2C,OAAO,EAAI,UAAW,UAAU;IAC3E,IAAM,IAAO,EAAI;AAGjB,QAAI,CAAC,EAAc,IAAI,EAAK,CACxB,QAAO;IAGX,IAAM,IAAQ,EAAI;AAElB,QAAI,MAAS,OACT,QAAO,IAAI,KAAK,EAAgB;AAEpC,QAAI,MAAS,MACT,QAAO,IAAI,IAAI,EAA8B;AAEjD,QAAI,MAAS,MACT,QAAO,IAAI,IAAI,EAAmB;AAEtC,QAAI,MAAS,UAAU;KACnB,IAAM,EAAE,WAAQ,aAAU;AAS1B,YAPI,OAAO,KAAW,YACf,OAAO,KAAU,YACjB,EAAO,SAAS,KAChB,CAAC,EAAmB,KAAK,EAAM,GAE3B,IAEJ,IAAI,OAAO,GAAQ,EAAM;;AAEpC,QAAI,MAAS,SACT,QAAO,OAAO,EAAgB;;AAGtC,UAAO;IACT;;CAET"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Represents a wrapped storage value that includes Time-to-Live (TTL) expiration metadata.
3
+ * @since 3.13.0
4
+ */
5
+ export interface I_StorageEnvelope<T> {
6
+ __isTtlEnvelope: true;
7
+ expiresAt?: number;
8
+ value: T;
9
+ }
10
+ /**
11
+ * Checks whether an unknown storage payload is a valid TTL envelope.
12
+ * @since 3.13.0
13
+ */
14
+ export declare function isTtlEnvelope<T>(payload: unknown): payload is I_StorageEnvelope<T>;
15
+ /**
16
+ * Checks if a TTL envelope has expired based on its timestamp.
17
+ * Returns true if the envelope has an expiration time and that time has passed.
18
+ * @since 3.13.0
19
+ */
20
+ export declare function isExpiredEnvelope<T>(envelope: I_StorageEnvelope<T>): boolean;
21
+ /**
22
+ * Wraps a value in a TTL envelope with the specified expiration duration.
23
+ * @since 3.13.0
24
+ */
25
+ export declare function createTtlEnvelope<T>(value: T, ttlMs: number): I_StorageEnvelope<T>;
@@ -0,0 +1,18 @@
1
+ //#region src/util/storage/storage-envelope.ts
2
+ function e(e) {
3
+ return typeof e == "object" && !!e && "__isTtlEnvelope" in e;
4
+ }
5
+ function t(e) {
6
+ return !!(e.expiresAt && Date.now() > e.expiresAt);
7
+ }
8
+ function n(e, t) {
9
+ return {
10
+ __isTtlEnvelope: !0,
11
+ expiresAt: Date.now() + t,
12
+ value: e
13
+ };
14
+ }
15
+ //#endregion
16
+ export { n as createTtlEnvelope, t as isExpiredEnvelope, e as isTtlEnvelope };
17
+
18
+ //# sourceMappingURL=storage-envelope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-envelope.js","names":[],"sources":["../../../src/util/storage/storage-envelope.ts"],"sourcesContent":["/**\n * Represents a wrapped storage value that includes Time-to-Live (TTL) expiration metadata.\n * @since 3.13.0\n */\nexport interface I_StorageEnvelope<T> {\n __isTtlEnvelope: true;\n expiresAt?: number;\n value: T;\n}\n\n/**\n * Checks whether an unknown storage payload is a valid TTL envelope.\n * @since 3.13.0\n */\nexport function isTtlEnvelope<T>(payload: unknown): payload is I_StorageEnvelope<T> {\n return (\n typeof payload === 'object'\n && payload !== null\n && '__isTtlEnvelope' in payload\n );\n}\n\n/**\n * Checks if a TTL envelope has expired based on its timestamp.\n * Returns true if the envelope has an expiration time and that time has passed.\n * @since 3.13.0\n */\nexport function isExpiredEnvelope<T>(envelope: I_StorageEnvelope<T>): boolean {\n return Boolean(envelope.expiresAt && Date.now() > envelope.expiresAt);\n}\n\n/**\n * Wraps a value in a TTL envelope with the specified expiration duration.\n * @since 3.13.0\n */\nexport function createTtlEnvelope<T>(value: T, ttlMs: number): I_StorageEnvelope<T> {\n return {\n __isTtlEnvelope: true,\n expiresAt: Date.now() + ttlMs,\n value,\n };\n}\n"],"mappings":";AAcA,SAAgB,EAAiB,GAAmD;AAChF,QACI,OAAO,KAAY,cAChB,KACA,qBAAqB;;AAShC,SAAgB,EAAqB,GAAyC;AAC1E,QAAO,GAAQ,EAAS,aAAa,KAAK,KAAK,GAAG,EAAS;;AAO/D,SAAgB,EAAqB,GAAU,GAAqC;AAChF,QAAO;EACH,iBAAiB;EACjB,WAAW,KAAK,KAAK,GAAG;EACxB;EACH"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cyberskill/shared",
3
3
  "type": "module",
4
- "version": "3.13.0",
4
+ "version": "3.15.0",
5
5
  "description": "CyberSkill Shared",
6
6
  "author": "Stephen Cheng",
7
7
  "license": "MIT",
@@ -107,6 +107,9 @@
107
107
  "import": "./dist/node/mongo/index.js",
108
108
  "default": "./dist/node/mongo/index.js"
109
109
  },
110
+ "./node/mongo/types": {
111
+ "types": "./dist/node/mongo/index.d.ts"
112
+ },
110
113
  "./node/package": {
111
114
  "types": "./dist/node/package/index.d.ts",
112
115
  "import": "./dist/node/package/index.js",
@@ -157,6 +160,11 @@
157
160
  "import": "./dist/react/i18next/index.js",
158
161
  "default": "./dist/react/i18next/index.js"
159
162
  },
163
+ "./react/i18next/server": {
164
+ "types": "./dist/react/i18next/i18next.server.d.ts",
165
+ "import": "./dist/react/i18next/i18next.server.js",
166
+ "default": "./dist/react/i18next/i18next.server.js"
167
+ },
160
168
  "./react/loading": {
161
169
  "types": "./dist/react/loading/index.d.ts",
162
170
  "import": "./dist/react/loading/index.js",
@@ -172,6 +180,11 @@
172
180
  "import": "./dist/react/next-intl/index.js",
173
181
  "default": "./dist/react/next-intl/index.js"
174
182
  },
183
+ "./react/next-intl/server": {
184
+ "types": "./dist/react/next-intl/next-intl.server.d.ts",
185
+ "import": "./dist/react/next-intl/next-intl.server.js",
186
+ "default": "./dist/react/next-intl/next-intl.server.js"
187
+ },
175
188
  "./react/storage": {
176
189
  "types": "./dist/react/storage/index.d.ts",
177
190
  "import": "./dist/react/storage/index.js",
@@ -192,6 +205,9 @@
192
205
  "import": "./dist/typescript/index.js",
193
206
  "default": "./dist/typescript/index.js"
194
207
  },
208
+ "./types": {
209
+ "types": "./dist/typescript/index.d.ts"
210
+ },
195
211
  "./util": {
196
212
  "types": "./dist/util/index.d.ts",
197
213
  "import": "./dist/util/index.js",
@@ -229,14 +245,14 @@
229
245
  "typecheck": "tsc --noEmit"
230
246
  },
231
247
  "dependencies": {
232
- "@antfu/eslint-config": "7.7.3",
248
+ "@antfu/eslint-config": "8.0.0",
233
249
  "@apollo/client": "4.1.6",
234
250
  "@apollo/client-integration-nextjs": "0.14.4",
235
251
  "@apollo/server": "5.5.0",
236
252
  "@as-integrations/express5": "1.1.2",
237
- "@dotenvx/dotenvx": "1.58.0",
253
+ "@dotenvx/dotenvx": "1.59.1",
238
254
  "@eddeee888/gcg-typescript-resolver-files": "0.15.0",
239
- "@eslint-react/eslint-plugin": "2.13.0",
255
+ "@eslint-react/eslint-plugin": "3.0.0",
240
256
  "@graphql-codegen/cli": "6.2.1",
241
257
  "@graphql-codegen/client-preset": "5.2.4",
242
258
  "@nestjs/common": "11.1.17",
@@ -252,12 +268,12 @@
252
268
  "cors": "2.8.6",
253
269
  "date-fns": "4.1.0",
254
270
  "envalid": "8.1.1",
255
- "eslint-config-next": "16.2.1",
271
+ "eslint-config-next": "16.2.2",
256
272
  "eslint-plugin-format": "2.0.1",
257
273
  "eslint-plugin-react-hooks": "7.0.1",
258
274
  "eslint-plugin-react-refresh": "0.5.2",
259
275
  "express": "5.2.1",
260
- "express-rate-limit": "8.3.1",
276
+ "express-rate-limit": "8.3.2",
261
277
  "express-session": "1.19.0",
262
278
  "express-useragent": "2.1.0",
263
279
  "extract-files": "13.0.0",
@@ -267,18 +283,19 @@
267
283
  "graphql-upload": "17.0.0",
268
284
  "graphql-ws": "6.0.8",
269
285
  "helmet": "8.1.0",
270
- "i18next": "25.10.10",
286
+ "i18next": "26.0.3",
271
287
  "migrate-mongo": "14.0.7",
272
288
  "mongodb": "7.1.1",
273
289
  "mongoose": "9.3.3",
274
290
  "mongoose-aggregate-paginate-v2": "1.1.4",
275
291
  "mongoose-paginate-v2": "1.9.4",
276
- "next-intl": "4.8.3",
292
+ "next-intl": "4.8.4",
293
+ "path-to-regexp": "8.4.1",
277
294
  "qs": "6.15.0",
278
295
  "react": "19.2.4",
279
296
  "react-dom": "19.2.4",
280
297
  "react-hot-toast": "2.6.0",
281
- "react-i18next": "16.6.6",
298
+ "react-i18next": "17.0.2",
282
299
  "rxjs": "7.8.2",
283
300
  "ws": "8.20.0",
284
301
  "yargs": "18.0.0"
@@ -286,8 +303,9 @@
286
303
  "devDependencies": {
287
304
  "@commitlint/cli": "20.5.0",
288
305
  "@commitlint/config-conventional": "20.5.0",
306
+ "@cyclonedx/cyclonedx-npm": "4.2.1",
289
307
  "@eslint/config-inspector": "1.5.0",
290
- "@next/eslint-plugin-next": "16.2.1",
308
+ "@next/eslint-plugin-next": "16.2.2",
291
309
  "@semantic-release/changelog": "6.0.3",
292
310
  "@semantic-release/git": "10.0.1",
293
311
  "@semantic-release/github": "12.0.6",
@@ -314,10 +332,11 @@
314
332
  "@types/yargs": "17.0.35",
315
333
  "@vitest/browser": "4.1.2",
316
334
  "@vitest/coverage-istanbul": "4.1.2",
317
- "conventional-changelog-conventionalcommits": "9.3.0",
335
+ "conventional-changelog-conventionalcommits": "9.3.1",
318
336
  "eslint": "10.1.0",
319
337
  "glob": "13.0.6",
320
338
  "jsdom": "29.0.1",
339
+ "license-checker": "25.0.1",
321
340
  "lint-staged": "16.4.0",
322
341
  "node-modules-inspector": "1.4.2",
323
342
  "npm-run-all2": "8.0.4",
@@ -337,7 +356,9 @@
337
356
  },
338
357
  "pnpm": {
339
358
  "overrides": {
340
- "minimatch": ">=10.2.4"
359
+ "lodash": ">=4.17.23",
360
+ "minimatch": ">=10.2.4",
361
+ "path-to-regexp": "8.4.1"
341
362
  }
342
363
  }
343
364
  }
@@ -1,8 +0,0 @@
1
- import { Collection as e, Db as t } from "mongodb";
2
- import { Document as n, Model as r } from "mongoose";
3
- //#region src/node/mongo/mongo.type.ts
4
- var i = class extends t {}, a = class extends n {}, o = class extends r {}, s = class extends e {};
5
- //#endregion
6
- export { s as C_Collection, i as C_Db, a as C_Document, o as C_Model };
7
-
8
- //# sourceMappingURL=mongo.type.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mongo.type.js","names":[],"sources":["../../../src/node/mongo/mongo.type.ts"],"sourcesContent":["import type {\n DeleteResult,\n Filter,\n InsertManyResult,\n InsertOneResult,\n OptionalUnlessRequiredId,\n UpdateResult,\n WithId,\n} from 'mongodb';\nimport type {\n AggregatePaginateModel,\n AggregatePaginateResult,\n ClientSession,\n ErrorHandlingMiddlewareFunction,\n ErrorHandlingMiddlewareWithOption,\n InsertManyOptions,\n PaginateModel,\n PaginateOptions,\n PaginateResult,\n PipelineStage,\n PopulateOption,\n PopulateOptions,\n PostMiddlewareFunction,\n PreMiddlewareFunction,\n PreSaveMiddlewareFunction,\n ProjectionType,\n QueryFilter,\n QueryOptions,\n QueryWithHelpers,\n Schema,\n SchemaDefinition,\n UpdateQuery,\n UpdateWriteOpResult,\n} from 'mongoose';\nimport type mongoose from 'mongoose';\n\nimport { Collection, Db } from 'mongodb';\nimport {\n Document,\n Model,\n} from 'mongoose';\n\nexport class C_Db extends Db { }\n\nexport type T_Filter<T> = Filter<T>;\n\nexport type T_InsertOneResult<T> = InsertOneResult<T>;\n\nexport type T_InsertManyResult<T> = InsertManyResult<T>;\n\nexport type T_UpdateResult = UpdateResult | UpdateWriteOpResult;\n\nexport type T_DeleteResult = DeleteResult;\n\nexport type T_WithId<T> = WithId<T>;\n\nexport type T_OptionalUnlessRequiredId<T> = OptionalUnlessRequiredId<T>;\n\nexport class C_Document extends Document { }\n\nexport class C_Model extends Model { }\n\nexport class C_Collection<\n T extends Partial<C_Document>,\n> extends Collection<T> { }\n\nexport interface I_ExtendedModel<T extends Partial<C_Document>>\n extends Model<T>, PaginateModel<T>,\n AggregatePaginateModel<T> { }\n\nexport type T_QueryFilter<T> = QueryFilter<T>;\n\nexport type T_ProjectionType<T> = ProjectionType<T>;\n\nexport type T_QueryOptions<T> = QueryOptions<T>;\n\nexport type T_PaginateOptions = PaginateOptions;\n\nexport type T_PopulateOption = PopulateOption;\n\nexport type T_PopulateOptions = PopulateOptions;\n\nexport type T_PipelineStage = PipelineStage;\n\nexport type T_PaginateResult<T> = PaginateResult<T>;\n\nexport type T_AggregatePaginateResult<T> = AggregatePaginateResult<T>;\n\nexport type T_InsertManyOptions = InsertManyOptions;\n\nexport type T_UpdateQuery<T> = UpdateQuery<T>;\n\nexport type T_QueryWithHelpers<T> = QueryWithHelpers<T, T>;\n\nexport type T_PreMiddlewareFunction<T> = PreMiddlewareFunction<T>;\n\nexport type T_PreSaveMiddlewareFunction<T> = PreSaveMiddlewareFunction<T>;\n\nexport type T_PostMiddlewareFunction<T> = PostMiddlewareFunction<T>;\n\nexport type T_ErrorHandlingMiddlewareFunction<T> = ErrorHandlingMiddlewareFunction<T>;\n\nexport type T_ErrorHandlingMiddlewareWithOption<T> = ErrorHandlingMiddlewareWithOption<T>;\n\nexport type T_MongooseSchema<T> = mongoose.Schema<T>;\n\nexport type T_Input_MongooseSchema<T> = SchemaDefinition<T>;\n\nexport type T_MongoosePlugin = (schema: Schema, options?: Record<string, unknown>) => void;\n\nexport interface I_GenericDocument extends Partial<C_Document> {\n id: string;\n isDel: boolean;\n createdAt: string | Date;\n updatedAt: string | Date;\n}\n\nexport type T_Omit_Create = 'id' | 'isDel' | 'createdAt' | 'updatedAt';\n\nexport type T_Omit_Update = 'id' | 'createdAt' | 'updatedAt';\n\ninterface I_VirtualNestedOptions {\n [key: string]: I_VirtualNestedOptions | number | string | boolean;\n}\n\n/**\n * Function type for dynamically determining the reference model name.\n * Can return either a string (model name) or an enum value that represents the model.\n * The function can also return undefined, which will be handled gracefully.\n * This allows for optional properties in documents without requiring non-null assertions.\n *\n * @template T - The document type\n * @template R - The return type (string or enum)\n */\ntype T_DynamicRefFunction<T = unknown, R extends string = string> = (doc: T) => R | undefined;\n\ninterface I_VirtualBaseOptions {\n localField: string;\n foreignField: string;\n count?: boolean;\n justOne?: boolean;\n options?: I_VirtualNestedOptions;\n}\n\ninterface I_VirtualOptions extends I_VirtualBaseOptions {\n ref: string;\n}\n\nexport interface I_DynamicVirtualOptions<T, R extends string = string> extends I_VirtualBaseOptions {\n ref: T_DynamicRefFunction<T, R>;\n}\n\nexport type T_VirtualOptions<T, R extends string = string> = I_VirtualOptions | I_DynamicVirtualOptions<T, R>;\n\nexport interface I_DynamicVirtualConfig<T, R extends string = string> {\n name: string;\n options: I_DynamicVirtualOptions<T, R>;\n}\n\ninterface I_MongooseOptions<T, R extends string = string> {\n mongoose: typeof mongoose;\n virtuals?: {\n name: keyof T | string;\n options?: T_VirtualOptions<T, R>;\n get?: (this: T) => void;\n }[];\n}\n\nexport interface I_CreateSchemaOptions<T, R extends string = string>\n extends I_MongooseOptions<T, R> {\n schema: T_Input_MongooseSchema<T>;\n standalone?: boolean;\n}\n\nexport type T_MongooseMiddlewareMethod = string | RegExp;\n\nexport type T_MongooseMiddlewarePreFunction<T> = T_PreMiddlewareFunction<T> & T_PreSaveMiddlewareFunction<T>;\n\nexport type T_MongooseMiddlewarePostFunction<T> = T_PostMiddlewareFunction<T> & T_ErrorHandlingMiddlewareFunction<T> & T_ErrorHandlingMiddlewareWithOption<T>;\n\nexport interface I_MongooseModelMiddleware<T extends Partial<C_Document>> {\n method: T_MongooseMiddlewareMethod;\n pre?: T_MongooseMiddlewarePreFunction<T & T_QueryWithHelpers<T>>;\n post?: T_MongooseMiddlewarePostFunction<T>;\n}\n\nexport interface I_CreateModelOptions<T extends Partial<C_Document>, R extends string = string>\n extends I_MongooseOptions<T, R> {\n schema: T_Input_MongooseSchema<T>;\n name: string;\n pagination?: boolean;\n aggregate?: boolean;\n middlewares?: I_MongooseModelMiddleware<T>[];\n}\n\nexport type T_Input_Populate = string | string[] | T_PopulateOptions | T_PopulateOptions[];\n\nexport interface I_PaginateOptionsWithPopulate\n extends T_PaginateOptions,\n Omit<T_PopulateOption, 'populate'> {\n populate?: T_Input_Populate;\n}\n\nexport interface I_Input_FindOne<T> extends T_PopulateOption {\n filter: T_QueryFilter<T>;\n projection?: T_ProjectionType<T>;\n options?: T_QueryOptions<T>;\n}\n\nexport interface I_Input_FindAll<T> extends T_PopulateOption {\n filter: T_QueryFilter<T>;\n projection?: T_ProjectionType<T>;\n options?: T_QueryOptions<T>;\n}\n\nexport interface I_Input_FindPaging<T = undefined> {\n filter?: T_QueryFilter<T>;\n options?: I_PaginateOptionsWithPopulate;\n};\n\nexport interface I_Input_FindPagingAggregate {\n pipeline: T_PipelineStage[];\n options?: I_PaginateOptionsWithPopulate;\n}\n\nexport interface I_Input_CreateOne<T> {\n doc: T;\n}\n\nexport interface I_Input_CreateMany<T> {\n docs: T[];\n}\n\nexport interface I_UpdateOptionsExtended extends Omit<QueryOptions, 'session'> {\n session?: ClientSession;\n}\n\nexport interface I_Input_UpdateOne<T> extends T_PopulateOption {\n filter: T_QueryFilter<T>;\n update: T_UpdateQuery<T>;\n options?: I_UpdateOptionsExtended;\n}\n\nexport interface I_Input_UpdateMany<T> extends T_PopulateOption {\n filter: T_QueryFilter<T>;\n update: T_UpdateQuery<T>;\n options?: I_UpdateOptionsExtended;\n}\n\nexport interface I_DeleteOptionsExtended extends Omit<QueryOptions, 'session'> {\n session?: ClientSession;\n}\n\nexport interface I_Input_DeleteOne<T> {\n filter: T_QueryFilter<T>;\n options?: I_DeleteOptionsExtended;\n}\n\nexport interface I_Input_DeleteMany<T> {\n filter: T_QueryFilter<T>;\n options?: I_DeleteOptionsExtended;\n}\n\nexport interface I_InputSlug<T> {\n field: string;\n filter?: T_QueryFilter<T>;\n haveHistory?: boolean;\n}\n\nexport interface I_Input_CreateSlug<T> extends I_InputSlug<T> {\n from: T;\n}\n\nexport interface I_Input_CheckSlug<T> extends I_InputSlug<T> {\n slug: string;\n from: T;\n}\n\nexport interface I_Input_GenerateSlug<T> extends I_InputSlug<T> {\n slug: string;\n isObject: boolean;\n haveHistory?: boolean;\n}\n"],"mappings":";;;AA0CA,IAAa,IAAb,cAA0B,EAAG,IAgBhB,IAAb,cAAgC,EAAS,IAE5B,IAAb,cAA6B,EAAM,IAEtB,IAAb,cAEU,EAAc"}
@@ -1,8 +0,0 @@
1
- //#region node_modules/.pnpm/vitest@4.1.2_@types+node@25.5.0_jsdom@29.0.1_@noble+hashes@1.8.0__vite@8.0.3_@types+nod_0827261ede788764a5d99ac6bdf44bde/node_modules/vitest/dist/config.js
2
- function e(e) {
3
- return e;
4
- }
5
- //#endregion
6
- export { e as defineConfig };
7
-
8
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","names":[],"sources":["../../../../../../../node_modules/.pnpm/vitest@4.1.2_@types+node@25.5.0_jsdom@29.0.1_@noble+hashes@1.8.0__vite@8.0.3_@types+nod_0827261ede788764a5d99ac6bdf44bde/node_modules/vitest/dist/config.js"],"sourcesContent":["export { c as configDefaults, a as coverageConfigDefaults, d as defaultExclude, b as defaultInclude } from './chunks/defaults.9aQKnqFk.js';\nexport { mergeConfig } from 'vite';\nexport { d as defaultBrowserPort } from './chunks/constants.CPYnjOGj.js';\nimport 'node:os';\nimport './chunks/env.D4Lgay0q.js';\nimport 'std-env';\n\nfunction defineConfig(config) {\n\treturn config;\n}\nfunction defineProject(config) {\n\treturn config;\n}\n\nexport { defineConfig, defineProject };\n"],"x_google_ignoreList":[0],"mappings":";AAOA,SAAS,EAAa,GAAQ;AAC7B,QAAO"}