@dexyn/common-library 1.0.2 → 1.0.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/.github/workflows/publish.yml +37 -0
- package/package.json +1 -1
- package/dexyn-common-library-1.0.1.tgz +0 -0
- package/package/dist/date/dateUtils.d.ts +0 -11
- package/package/dist/date/dateUtils.js +0 -16
- package/package/dist/result/httpResultUtils.d.ts +0 -10
- package/package/dist/result/httpResultUtils.js +0 -18
- package/package/dist/result/resultUtils.d.ts +0 -29
- package/package/dist/result/resultUtils.js +0 -29
- package/package/dist/validation/numberIdSchema.d.ts +0 -11
- package/package/dist/validation/numberIdSchema.js +0 -15
- package/package/dist/validation/validationUtils.d.ts +0 -4
- package/package/dist/validation/validationUtils.js +0 -8
@@ -0,0 +1,37 @@
|
|
1
|
+
name: Build and Publish to NPM
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master # Trigger on pushes to the `main` branch
|
7
|
+
workflow_dispatch: # Allow manual triggering
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build-and-publish:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
# Step 1: Check out the code
|
15
|
+
- name: Checkout code
|
16
|
+
uses: actions/checkout@v3
|
17
|
+
|
18
|
+
# Step 2: Set up Node.js
|
19
|
+
- name: Set up Node.js
|
20
|
+
uses: actions/setup-node@v3
|
21
|
+
with:
|
22
|
+
node-version: '16' # Specify Node.js version
|
23
|
+
registry-url: 'https://registry.npmjs.org/'
|
24
|
+
|
25
|
+
# Step 3: Install dependencies
|
26
|
+
- name: Install dependencies
|
27
|
+
run: npm ci
|
28
|
+
|
29
|
+
# Step 4: Build the library
|
30
|
+
- name: Build the library
|
31
|
+
run: npm run build
|
32
|
+
|
33
|
+
# Step 5: Publish to NPM
|
34
|
+
- name: Publish to NPM
|
35
|
+
run: npm publish --access public
|
36
|
+
env:
|
37
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/package.json
CHANGED
Binary file
|
@@ -1,11 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Formats a date as a time string.
|
3
|
-
* @param date The `Date` object to format.
|
4
|
-
* @param locale The locale for formatting. Defaults to "en-US".
|
5
|
-
* @param options Additional time formatting options.
|
6
|
-
* @returns The formatted time string.
|
7
|
-
* @example
|
8
|
-
* DateFormatter.formatTime(new Date("2024-12-03T10:30:00"), "en-US", { hour: "2-digit", minute: "2-digit" });
|
9
|
-
* // Output: "10:30 AM"
|
10
|
-
*/
|
11
|
-
export declare function formatDateTime(date: Date, locale?: string, options?: Intl.DateTimeFormatOptions): string;
|
@@ -1,16 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.formatDateTime = formatDateTime;
|
4
|
-
/**
|
5
|
-
* Formats a date as a time string.
|
6
|
-
* @param date The `Date` object to format.
|
7
|
-
* @param locale The locale for formatting. Defaults to "en-US".
|
8
|
-
* @param options Additional time formatting options.
|
9
|
-
* @returns The formatted time string.
|
10
|
-
* @example
|
11
|
-
* DateFormatter.formatTime(new Date("2024-12-03T10:30:00"), "en-US", { hour: "2-digit", minute: "2-digit" });
|
12
|
-
* // Output: "10:30 AM"
|
13
|
-
*/
|
14
|
-
function formatDateTime(date, locale = "en-US", options = { hour: "numeric", minute: "numeric", second: "numeric" }) {
|
15
|
-
return new Intl.DateTimeFormat(locale, options).format(date);
|
16
|
-
}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.HttpResult = void 0;
|
4
|
-
const createHTTPResult = () => {
|
5
|
-
function Accepted() {
|
6
|
-
return {
|
7
|
-
status: 202,
|
8
|
-
};
|
9
|
-
}
|
10
|
-
function BadRequest(error) {
|
11
|
-
return {
|
12
|
-
status: 400,
|
13
|
-
jsonBody: JSON.stringify(error)
|
14
|
-
};
|
15
|
-
}
|
16
|
-
return { Accepted, BadRequest };
|
17
|
-
};
|
18
|
-
exports.HttpResult = createHTTPResult();
|
@@ -1,29 +0,0 @@
|
|
1
|
-
type SuccessResult<T> = {
|
2
|
-
success: true;
|
3
|
-
data: T;
|
4
|
-
};
|
5
|
-
export type ErrorResult = {
|
6
|
-
success: false;
|
7
|
-
error: StandardError;
|
8
|
-
};
|
9
|
-
export interface StandardError {
|
10
|
-
name: string;
|
11
|
-
message: string;
|
12
|
-
code?: string;
|
13
|
-
statusCode?: number;
|
14
|
-
details?: Record<string, unknown>;
|
15
|
-
timestamp?: string;
|
16
|
-
stack?: string;
|
17
|
-
}
|
18
|
-
export type Result<T> = SuccessResult<T> | ErrorResult;
|
19
|
-
/**
|
20
|
-
* Converts a promise into a ResultUtils type, wrapping its success and error outcomes.
|
21
|
-
*
|
22
|
-
* @param data - Data to be wrapped in ResultUtils type
|
23
|
-
* @returns A ResultUtils<T, E> representing the outcome of the promise.
|
24
|
-
*/
|
25
|
-
export declare function toResult<T>(data: T): Result<T>;
|
26
|
-
export declare function errorToErrorResult(error: Error): ErrorResult;
|
27
|
-
export type ErrorName = "UnhandledError" | "Duplicate" | "NotFound" | "ApiError" | "ValidationError";
|
28
|
-
export declare function toErrorResult(name: ErrorName, message: string, details?: Record<string, unknown>, code?: string, statusCode?: number): ErrorResult;
|
29
|
-
export {};
|
@@ -1,29 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
// ResultUtils type for consistent responses
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
-
exports.toResult = toResult;
|
5
|
-
exports.errorToErrorResult = errorToErrorResult;
|
6
|
-
exports.toErrorResult = toErrorResult;
|
7
|
-
const dateUtils_1 = require("../date/dateUtils");
|
8
|
-
/**
|
9
|
-
* Converts a promise into a ResultUtils type, wrapping its success and error outcomes.
|
10
|
-
*
|
11
|
-
* @param data - Data to be wrapped in ResultUtils type
|
12
|
-
* @returns A ResultUtils<T, E> representing the outcome of the promise.
|
13
|
-
*/
|
14
|
-
function toResult(data) {
|
15
|
-
return { success: true, data: data };
|
16
|
-
}
|
17
|
-
function errorToErrorResult(error) {
|
18
|
-
return { success: false, error: error };
|
19
|
-
}
|
20
|
-
function toErrorResult(name, message, details, code, statusCode) {
|
21
|
-
return { success: false, error: {
|
22
|
-
name: name,
|
23
|
-
message: message,
|
24
|
-
code: code,
|
25
|
-
details: details,
|
26
|
-
statusCode: statusCode,
|
27
|
-
timestamp: (0, dateUtils_1.formatDateTime)(new Date())
|
28
|
-
} };
|
29
|
-
}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.idSchema = void 0;
|
4
|
-
const zod_1 = require("zod");
|
5
|
-
exports.idSchema = zod_1.z.object({
|
6
|
-
id: zod_1.z.preprocess((val) => {
|
7
|
-
// Convert strings and numbers to a number
|
8
|
-
if (typeof val === 'string' || typeof val === 'number') {
|
9
|
-
return Number(val);
|
10
|
-
}
|
11
|
-
throw new Error("Unsupported type for id"); // Explicitly throw for unsupported types
|
12
|
-
}, zod_1.z.number().positive({
|
13
|
-
message: 'must be a positive number',
|
14
|
-
})),
|
15
|
-
});
|
@@ -1,8 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.formatZodErrorsToString = formatZodErrorsToString;
|
4
|
-
function formatZodErrorsToString(errors) {
|
5
|
-
return errors
|
6
|
-
.map((err) => `${err.path.join(".")}: ${err.message}`)
|
7
|
-
.join("\n");
|
8
|
-
}
|