0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor: schema export and id generator

This commit is contained in:
Gao Sun 2022-12-20 00:01:40 +08:00
parent 5dd2eef34c
commit 3a3a107811
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
72 changed files with 109 additions and 127 deletions

View file

@ -43,6 +43,7 @@
"url": "https://github.com/logto-io/logto/issues"
},
"dependencies": {
"@logto/core-kit": "workspace:*",
"@logto/schemas": "workspace:*",
"@logto/shared": "workspace:*",
"@silverhand/essentials": "^1.3.0",

View file

@ -1,8 +1,16 @@
import { readdir, readFile } from 'fs/promises';
import path from 'path';
import { logtoConfigGuards, LogtoOidcConfigKey, seeds } from '@logto/schemas';
import { buildApplicationSecret } from '@logto/shared';
import { generateStandardId } from '@logto/core-kit';
import {
logtoConfigGuards,
LogtoOidcConfigKey,
managementResource,
defaultSignInExperience,
createDefaultSetting,
createDemoAppApplication,
defaultRole,
} from '@logto/schemas';
import chalk from 'chalk';
import type { DatabasePool, DatabaseTransactionConnection } from 'slonik';
import { sql } from 'slonik';
@ -40,21 +48,11 @@ const createTables = async (connection: DatabaseTransactionConnection) => {
};
const seedTables = async (connection: DatabaseTransactionConnection) => {
const {
managementResource,
defaultSignInExperience,
createDefaultSetting,
createDemoAppApplication,
defaultRole,
} = seeds;
await Promise.all([
connection.query(insertInto(managementResource, 'resources')),
connection.query(insertInto(createDefaultSetting(), 'settings')),
connection.query(insertInto(defaultSignInExperience, 'sign_in_experiences')),
connection.query(
insertInto(createDemoAppApplication(buildApplicationSecret()), 'applications')
),
connection.query(insertInto(createDemoAppApplication(generateStandardId()), 'applications')),
connection.query(insertInto(defaultRole, 'roles')),
updateDatabaseTimestamp(connection, await getLatestAlterationTimestamp()),
]);

View file

@ -1,6 +1,6 @@
import { UserScope } from '@logto/core-kit';
import { LogtoProvider } from '@logto/react';
import { adminConsoleApplicationId, managementResource } from '@logto/schemas/lib/seeds';
import { adminConsoleApplicationId, managementResource } from '@logto/schemas';
import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom';
import { SWRConfig } from 'swr';

View file

@ -1,5 +1,5 @@
import type { Application } from '@logto/schemas';
import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds';
import { adminConsoleApplicationId } from '@logto/schemas';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import useSWR from 'swr';

View file

@ -1,5 +1,5 @@
import type { Application } from '@logto/schemas';
import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds';
import { adminConsoleApplicationId } from '@logto/schemas';
import { useTranslation } from 'react-i18next';
import useSWR from 'swr';

View file

@ -1,6 +1,6 @@
import { useLogto } from '@logto/react';
import type { RequestErrorBody } from '@logto/schemas';
import { managementResource } from '@logto/schemas/lib/seeds';
import { managementResource } from '@logto/schemas';
import ky from 'ky';
import { useCallback, useMemo } from 'react';
import { toast } from 'react-hot-toast';

View file

@ -1,6 +1,5 @@
import type { Resource } from '@logto/schemas';
import { AppearanceMode } from '@logto/schemas';
import { managementResource } from '@logto/schemas/lib/seeds';
import { AppearanceMode, managementResource } from '@logto/schemas';
import { useEffect, useState } from 'react';
import { useForm } from 'react-hook-form';
import { toast } from 'react-hot-toast';

View file

@ -1,7 +1,6 @@
import type { AdminConsoleKey } from '@logto/phrases';
import type { Application } from '@logto/schemas';
import { AppearanceMode } from '@logto/schemas';
import { demoAppApplicationId } from '@logto/schemas/lib/seeds';
import { AppearanceMode, demoAppApplicationId } from '@logto/schemas';
import { useMemo } from 'react';
import { useNavigate } from 'react-router-dom';
import useSWR from 'swr';

View file

@ -5,7 +5,7 @@ import {
adminConsoleApplicationId,
adminConsoleSignInExperience,
demoAppApplicationId,
} from '@logto/schemas/lib/seeds/index.js';
} from '@logto/schemas';
import { deduplicate } from '@silverhand/essentials';
import i18next from 'i18next';

View file

@ -1,6 +1,6 @@
import { buildIdGenerator } from '@logto/core-kit';
import type { User, CreateUser } from '@logto/schemas';
import { Users, UsersPasswordEncryptionMethod } from '@logto/schemas';
import { buildIdGenerator } from '@logto/shared';
import type { Nullable } from '@silverhand/essentials';
import { deduplicate } from '@silverhand/essentials';
import { argon2Verify } from 'hash-wasm';

View file

@ -1,7 +1,7 @@
import type { IncomingHttpHeaders } from 'http';
import { UserRole } from '@logto/schemas';
import { managementResource } from '@logto/schemas/lib/seeds/index.js';
import { managementResource } from '@logto/schemas';
import type { Optional } from '@silverhand/essentials';
import { conditional } from '@silverhand/essentials';
import { jwtVerify } from 'jose';

View file

@ -1,4 +1,4 @@
import { demoAppApplicationId } from '@logto/schemas/lib/seeds/index.js';
import { demoAppApplicationId } from '@logto/schemas';
import type { MiddlewareType } from 'koa';
import { findApplicationById } from '#src/queries/application.js';

View file

@ -30,6 +30,11 @@ export default function koaErrorHandler<StateT, ContextT, BodyT>(): Middleware<
return;
}
// Should log 500 errors in prod anyway
if (envSet.values.isProduction) {
console.error(error);
}
ctx.status = 500;
ctx.body = { message: 'Internal server error.' };
}

View file

@ -1,6 +1,6 @@
import type { CreateApplication, OidcClientMetadata } from '@logto/schemas';
import { ApplicationType } from '@logto/schemas';
import { adminConsoleApplicationId, demoAppApplicationId } from '@logto/schemas/lib/seeds/index.js';
import { adminConsoleApplicationId, demoAppApplicationId } from '@logto/schemas';
import { tryThat } from '@logto/shared';
import { deduplicate } from '@silverhand/essentials';
import { addSeconds } from 'date-fns';

View file

@ -29,10 +29,10 @@ const { findApplicationById } = mockEsm('#src/queries/application.js', () => ({
),
}));
mockEsm('@logto/shared', () => ({
mockEsm('@logto/core-kit', () => ({
// eslint-disable-next-line unicorn/consistent-function-scoping
buildIdGenerator: jest.fn(() => () => 'randomId'),
buildApplicationSecret: jest.fn(() => 'randomId'),
generateStandardId: jest.fn(() => 'randomId'),
}));
const { createRequester } = await import('#src/utils/test-utils.js');

View file

@ -1,5 +1,5 @@
import { generateStandardId, buildIdGenerator } from '@logto/core-kit';
import { Applications } from '@logto/schemas';
import { buildApplicationSecret, buildIdGenerator } from '@logto/shared';
import { object, string } from 'zod';
import koaGuard from '#src/middleware/koa-guard.js';
@ -47,7 +47,7 @@ export default function applicationRoutes<T extends AuthedRouter>(router: T) {
ctx.body = await insertApplication({
id: applicationId(),
secret: buildApplicationSecret(),
secret: generateStandardId(),
oidcClientMetadata: buildOidcClientMetadata(oidcClientMetadata),
...rest,
});

View file

@ -1,8 +1,7 @@
import { MessageTypes } from '@logto/connector-kit';
import { emailRegEx, phoneRegEx } from '@logto/core-kit';
import { emailRegEx, phoneRegEx, buildIdGenerator } from '@logto/core-kit';
import type { ConnectorFactoryResponse, ConnectorResponse } from '@logto/schemas';
import { arbitraryObjectGuard, Connectors, ConnectorType } from '@logto/schemas';
import { buildIdGenerator } from '@logto/shared';
import cleanDeep from 'clean-deep';
import { object, string } from 'zod';

View file

@ -1,6 +1,5 @@
import { ConnectorType } from '@logto/connector-kit';
import { Event } from '@logto/schemas';
import { demoAppApplicationId } from '@logto/schemas/lib/seeds/application.js';
import { Event, demoAppApplicationId } from '@logto/schemas';
import { mockEsm, mockEsmDefault, mockEsmWithActual, pickDefault } from '@logto/shared/esm';
import { mockSignInExperience } from '#src/__mocks__/sign-in-experience.js';

View file

@ -1,14 +1,12 @@
import zhCN from '@logto/phrases-ui/lib/locales/zh-cn.js';
import type { SignInExperience } from '@logto/schemas';
import {
adminConsoleApplicationId,
adminConsoleSignInExperience,
} from '@logto/schemas/lib/seeds/index.js';
import { adminConsoleApplicationId, adminConsoleSignInExperience } from '@logto/schemas';
import { mockEsm, mockEsmWithActual, pickDefault } from '@logto/shared/esm';
import { createMockProvider } from '#src/test-utils/oidc-provider.js';
import { zhCnTag } from '#src/__mocks__/custom-phrase.js';
import { mockSignInExperience } from '#src/__mocks__/index.js';
import { createMockProvider } from '#src/test-utils/oidc-provider.js';
const { jest } = import.meta;

View file

@ -1,8 +1,5 @@
import { isBuiltInLanguageTag } from '@logto/phrases-ui';
import {
adminConsoleApplicationId,
adminConsoleSignInExperience,
} from '@logto/schemas/lib/seeds/index.js';
import { adminConsoleApplicationId, adminConsoleSignInExperience } from '@logto/schemas';
import type { Provider } from 'oidc-provider';
import detectLanguage from '#src/i18n/detect-language.js';

View file

@ -1,5 +1,5 @@
import { buildIdGenerator } from '@logto/core-kit';
import { Resources } from '@logto/schemas';
import { buildIdGenerator } from '@logto/shared';
import { object, string } from 'zod';
import koaGuard from '#src/middleware/koa-guard.js';

View file

@ -1,12 +1,13 @@
import type { User } from '@logto/schemas';
import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds/index.js';
import { adminConsoleApplicationId } from '@logto/schemas';
import { Provider } from 'oidc-provider';
import { mockUser } from '#src/__mocks__/index.js';
import { createRequester } from '#src/utils/test-utils.js';
import sessionRoutes from './index.js';
import { mockUser } from '#src/__mocks__/index.js';
const findUserById = jest.fn(async (): Promise<User> => mockUser);
const updateUserById = jest.fn(async (..._args: unknown[]) => ({ id: 'id' }));

View file

@ -2,7 +2,7 @@ import path from 'path';
import type { LogtoErrorCode } from '@logto/phrases';
import { UserRole } from '@logto/schemas';
import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds/index.js';
import { adminConsoleApplicationId } from '@logto/schemas';
import { conditional } from '@silverhand/essentials';
import type { Provider } from 'oidc-provider';
import { object, string } from 'zod';

View file

@ -1,5 +1,5 @@
import { SignInMode } from '@logto/schemas';
import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds/index.js';
import { adminConsoleApplicationId } from '@logto/schemas';
import type { MiddlewareType } from 'koa';
import type { Provider } from 'oidc-provider';
import { errors } from 'oidc-provider';

View file

@ -1,13 +1,14 @@
import type { User } from '@logto/schemas';
import { UserRole, SignInIdentifier } from '@logto/schemas';
import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds/index.js';
import { adminConsoleApplicationId } from '@logto/schemas';
import { Provider } from 'oidc-provider';
import { mockSignInExperience, mockUser } from '#src/__mocks__/index.js';
import { createRequester } from '#src/utils/test-utils.js';
import passwordRoutes, { registerRoute, signInRoute } from './password.js';
import { mockSignInExperience, mockUser } from '#src/__mocks__/index.js';
const insertUser = jest.fn(async (..._args: unknown[]) => mockUser);
const hasUser = jest.fn(async (username: string) => username === 'username1');
const findUserById = jest.fn(async (): Promise<User> => mockUser);

View file

@ -1,6 +1,6 @@
import { passwordRegEx, usernameRegEx } from '@logto/core-kit';
import { SignInIdentifier, UserRole } from '@logto/schemas';
import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds/index.js';
import { adminConsoleApplicationId } from '@logto/schemas';
import type { Provider } from 'oidc-provider';
import { object, string } from 'zod';

View file

@ -1,10 +1,10 @@
import { SignInMode } from '@logto/schemas';
import {
adminConsoleApplicationId,
adminConsoleSignInExperience,
} from '@logto/schemas/lib/seeds/index.js';
import { adminConsoleApplicationId, adminConsoleSignInExperience } from '@logto/schemas';
import { mockEsm, mockEsmWithActual, pickDefault } from '@logto/shared/esm';
import { createMockProvider } from '#src/test-utils/oidc-provider.js';
import { createRequester } from '#src/utils/test-utils.js';
import {
mockAliyunDmConnector,
mockAliyunSmsConnector,
@ -15,8 +15,6 @@ import {
mockWechatConnector,
mockWechatNativeConnector,
} from '#src/__mocks__/index.js';
import { createMockProvider } from '#src/test-utils/oidc-provider.js';
import { createRequester } from '#src/utils/test-utils.js';
const { jest } = import.meta;
await mockEsmWithActual('i18next', () => ({

View file

@ -1,6 +1,6 @@
import type { ConnectorMetadata } from '@logto/connector-kit';
import { ConnectorType } from '@logto/connector-kit';
import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds/index.js';
import { adminConsoleApplicationId } from '@logto/schemas';
import etag from 'etag';
import type { Provider } from 'oidc-provider';

View file

@ -1,6 +1,6 @@
import type { IdTokenClaims } from '@logto/react';
import { LogtoProvider, useLogto, Prompt } from '@logto/react';
import { demoAppApplicationId } from '@logto/schemas/lib/seeds';
import { demoAppApplicationId } from '@logto/schemas';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';

View file

@ -1,6 +1,6 @@
import type { LogtoConfig } from '@logto/node';
import LogtoClient from '@logto/node';
import { demoAppApplicationId } from '@logto/schemas/lib/seeds/index.js';
import { demoAppApplicationId } from '@logto/schemas';
import type { Optional } from '@silverhand/essentials';
import { assert } from '@silverhand/essentials';
import { got } from 'got';

View file

@ -1,5 +1,4 @@
import { SignInIdentifier } from '@logto/schemas';
import { demoAppApplicationId } from '@logto/schemas/lib/seeds';
import { SignInIdentifier, demoAppApplicationId } from '@logto/schemas';
import { assertEnv } from '@silverhand/essentials';
export const logtoUrl = assertEnv('INTEGRATION_TESTS_LOGTO_URL');

View file

@ -1,5 +1,5 @@
import { ApplicationType } from '@logto/schemas';
import { demoAppApplicationId } from '@logto/schemas/lib/seeds';
import { demoAppApplicationId } from '@logto/schemas';
import { HTTPError } from 'got';
import {

View file

@ -1,7 +1,7 @@
import path from 'path';
import { fetchTokenByRefreshToken } from '@logto/js';
import { managementResource } from '@logto/schemas/lib/seeds';
import { managementResource } from '@logto/schemas';
import { assert } from '@silverhand/essentials';
import fetch from 'node-fetch';

View file

@ -1,4 +1,4 @@
import { managementResource } from '@logto/schemas/lib/seeds';
import { managementResource } from '@logto/schemas';
import { HTTPError } from 'got';
import { createResource, getResource, updateResource, deleteResource } from '#src/api/index.js';

View file

@ -1,5 +1,5 @@
import { SignInIdentifier } from '@logto/schemas';
import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds';
import { adminConsoleApplicationId } from '@logto/schemas';
import { assert } from '@silverhand/essentials';
import {

View file

@ -1,4 +1,4 @@
import { adminConsoleApplicationId } from '@logto/schemas/lib/seeds';
import { adminConsoleApplicationId } from '@logto/schemas';
import { assert } from '@silverhand/essentials';
import { getWellKnownSignInExperience } from '#src/api/index.js';

View file

@ -1,6 +1,7 @@
const errors = {
request: {
invalid_input: 'Input is invalid. {{details}}', // UNTRANSLATED
general: 'Request error occurred.', // UNTRANSLATED
},
auth: {
authorization_header_missing: 'Autorisierungs-Header fehlt.',

View file

@ -1,6 +1,7 @@
const errors = {
request: {
invalid_input: 'Input is invalid. {{details}}',
general: 'Request error occurred.',
},
auth: {
authorization_header_missing: 'Authorization header is missing.',

View file

@ -1,6 +1,7 @@
const errors = {
request: {
invalid_input: 'Input is invalid. {{details}}', // UNTRANSLATED
general: 'Request error occurred.', // UNTRANSLATED
},
auth: {
authorization_header_missing: "L'en-tête d'autorisation est manquant.",

View file

@ -1,6 +1,7 @@
const errors = {
request: {
invalid_input: 'Input is invalid. {{details}}', // UNTRANSLATED
general: 'Request error occurred.', // UNTRANSLATED
},
auth: {
authorization_header_missing: '인증 헤더가 존재하지 않아요.',

View file

@ -1,6 +1,7 @@
const errors = {
request: {
invalid_input: 'Input is invalid. {{details}}', // UNTRANSLATED
general: 'Request error occurred.', // UNTRANSLATED
},
auth: {
authorization_header_missing: 'O cabeçalho de autorização está ausente.',

View file

@ -1,6 +1,7 @@
const errors = {
request: {
invalid_input: 'Input is invalid. {{details}}', // UNTRANSLATED
general: 'Request error occurred.', // UNTRANSLATED
},
auth: {
authorization_header_missing: 'O cabeçalho de autorização está ausente.',

View file

@ -1,6 +1,7 @@
const errors = {
request: {
invalid_input: 'Input is invalid. {{details}}', // UNTRANSLATED
general: 'Request error occurred.', // UNTRANSLATED
},
auth: {
authorization_header_missing: 'Yetkilendirme başlığı eksik.',

View file

@ -1,6 +1,7 @@
const errors = {
request: {
invalid_input: 'Input is invalid. {{details}}', // UNTRANSLATED
general: 'Request error occurred.', // UNTRANSLATED
},
auth: {
authorization_header_missing: 'Authorization 请求头缺失。',

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
enum SignInMethodState {
Primary = 'primary',

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {

View file

@ -2,7 +2,7 @@ import { isSameArray } from '@silverhand/essentials';
import type { DatabaseTransactionConnection } from 'slonik';
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
enum DeprecatedSignUpIdentifier {
Email = 'email',

View file

@ -1,6 +1,6 @@
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
const alteration: AlterationScript = {
up: async (pool) => {

View file

@ -1,7 +1,7 @@
import type { DatabaseTransactionConnection } from 'slonik';
import { sql } from 'slonik';
import type { AlterationScript } from '../lib/types/alteration.js';
import type { AlterationScript } from '../lib/src/types/alteration.js';
type DeprecatedTermsOfUse = {
enabled: boolean;

View file

@ -1,7 +1,6 @@
{
"name": "@logto/schemas",
"version": "1.0.0-beta.16",
"main": "lib/index.js",
"author": "Silverhand Inc. <contact@silverhand.io>",
"license": "MPL-2.0",
"type": "module",
@ -11,6 +10,13 @@
"alterations-js",
"tables"
],
"main": "./lib/src/index.js",
"exports": {
".": "./lib/src/index.js",
"./lib/*": "./lib/src/*",
"./models": "./lib/src-models/index.js",
"./package.json": "./package.json"
},
"publishConfig": {
"access": "public"
},
@ -55,7 +61,9 @@
"rules": {
"@typescript-eslint/ban-types": "off"
},
"ignorePatterns": ["src/db-entries/"],
"ignorePatterns": [
"src/db-entries/"
],
"overrides": [
{
"files": [
@ -74,6 +82,8 @@
"@logto/language-kit": "workspace:*",
"@logto/phrases": "workspace:*",
"@logto/phrases-ui": "workspace:*",
"@withtyped/server": "^0.3.0",
"nanoid": "^4.0.0",
"zod": "^3.20.2"
}
}

View file

@ -2,4 +2,4 @@ export * from './foundations/index.js';
export * from './db-entries/index.js';
export * from './types/index.js';
export * from './api/index.js';
export * as seeds from './seeds/index.js';
export * from './seeds/index.js';

View file

@ -1,5 +1,5 @@
{
"extends": "./tsconfig",
"include": ["src"],
"include": ["src", "src-models"],
"exclude": ["src/gen"]
}

View file

@ -8,6 +8,7 @@
},
"include": [
"src",
"src-models",
"alterations"
]
}

View file

@ -1,7 +0,0 @@
import { customAlphabet } from 'nanoid';
export const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
export const buildIdGenerator = (size: number) => customAlphabet(alphabet, size);
export const buildApplicationSecret = buildIdGenerator(21);

View file

@ -1,3 +1,2 @@
export * from './id.js';
export * from './function.js';
export { default as findPackage } from './find-package.js';

View file

@ -1,4 +1,4 @@
import { buildIdGenerator, alphabet } from './id.js';
import { buildIdGenerator } from './id.js';
describe('id generator', () => {
it('should match the input length', () => {
@ -12,12 +12,4 @@ describe('id generator', () => {
expect(id_1).not.toEqual(id_2);
});
it('should only contains provided alphabets', () => {
const id = buildIdGenerator(20)();
for (const char of id) {
expect(alphabet.includes(char)).toBeTruthy();
}
});
});

View file

@ -0,0 +1,6 @@
import { customAlphabet } from 'nanoid';
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
export const buildIdGenerator = (size: number) => customAlphabet(alphabet, size);
export const generateStandardId = buildIdGenerator(21);

View file

@ -1,4 +1,4 @@
export * from './color.js';
export * from './string.js';
export * from './id.js';
export * from './zod.js';
export * from './url.js';

View file

@ -1,15 +0,0 @@
import { generateRandomString } from './string.js';
describe('generateRandomString', () => {
it('should return a random string with specified length', () => {
const randomString = generateRandomString(32);
expect(randomString).toHaveLength(32);
});
it('should contain only 0-9, A-Z and a-z by default', () => {
const randomString = generateRandomString(32);
expect(() => {
/[\dA-Za-z]/.test(randomString);
}).toBeTruthy();
});
});

View file

@ -1,6 +0,0 @@
import { customAlphabet } from 'nanoid';
export const generateRandomString = (
size: number,
alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
): string => customAlphabet(alphabet, size)();