Compare commits

..

No commits in common. "develop" and "master" have entirely different histories.

19 changed files with 212 additions and 19372 deletions

View File

@ -1,13 +0,0 @@
name: Build/Publish
on:
push:
branches:
- master
- develop
- develop-*
jobs:
main:
uses: lumeweb/github-node-deploy-workflow/.github/workflows/main.yml@master
secrets: inherit

View File

@ -1,5 +0,0 @@
{
"preset": [
"@lumeweb/node-library-preset"
]
}

View File

@ -1,8 +0,0 @@
# [0.1.0-develop.1](https://git.lumeweb.com/LumeWeb/libresolver/compare/v0.0.2-develop.1...v0.1.0-develop.1) (2023-07-15)
### Features
* add ready method to AbstractResolverModule ([8be5af2](https://git.lumeweb.com/LumeWeb/libresolver/commit/8be5af2f45087d10ae1ccf4d77c20a7a04d586ed))
## [0.0.2-develop.1](https://git.lumeweb.com/LumeWeb/libresolver/compare/v0.0.1...v0.0.2-develop.1) (2023-07-05)

4
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
export * from "./types.js";
export * from "./util.js";
export * from "./resolverModule.js";
//# sourceMappingURL=index.d.ts.map

1
dist/index.d.ts.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC"}

3
dist/index.js vendored Normal file
View File

@ -0,0 +1,3 @@
export * from "./types.js";
export * from "./util.js";
export * from "./resolverModule.js";

40
dist/resolverModule.d.ts vendored Normal file
View File

@ -0,0 +1,40 @@
import type { DNSResult, ResolverOptions } from "./types.js";
declare class ResolverRegistry {
get resolvers(): Set<ResolverModule> | Promise<Set<ResolverModule>>;
resolve(
domain: string,
options?: ResolverOptions,
bypassCache?: boolean
): Promise<DNSResult>;
register(resolver: ResolverModule): void;
clear(): void;
}
export interface ResolverModule {
get resolver(): ResolverRegistry;
set resolver(value: ResolverRegistry);
resolve(
domain: string,
options: ResolverOptions,
bypassCache: boolean
): Promise<DNSResult>;
getSupportedTlds(): string[];
getSupportedTlds(): Promise<string[]>;
getSupportedTlds(): any;
}
export declare abstract class AbstractResolverModule {
constructor(resolver?: ResolverRegistry);
private _resolver?;
get resolver(): ResolverRegistry;
set resolver(value: ResolverRegistry);
abstract resolve(
domain: string,
options: ResolverOptions,
bypassCache: boolean
): Promise<DNSResult>;
getSupportedTlds(): string[];
getSupportedTlds(): Promise<string[]>;
isTldSupported(domain: string): Promise<boolean>;
isTldSupported(domain: string): boolean;
}
export {};
//# sourceMappingURL=resolverModule.d.ts.map

1
dist/resolverModule.d.ts.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"resolverModule.d.ts","sourceRoot":"","sources":["../src/resolverModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG7D,OAAO,OAAO,gBAAgB;IAC5B,IAAI,SAAS,IAAI,GAAG,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC;IACpE,OAAO,CACL,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,eAAe,EACzB,WAAW,CAAC,EAAE,OAAO,GACpB,OAAO,CAAC,SAAS,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IACxC,KAAK,IAAI,IAAI;CACd;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,QAAQ,IAAI,gBAAgB,CAAC;IACjC,IAAI,QAAQ,CAAC,KAAK,EAAE,gBAAgB,EAAE;IACtC,OAAO,CACL,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,SAAS,CAAC,CAAC;IAEtB,gBAAgB,IAAI,MAAM,EAAE,CAAC;IAC7B,gBAAgB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACtC,gBAAgB,IAAI,GAAG,CAAC;CACzB;AAGD,8BAAsB,sBAAsB;gBAC9B,QAAQ,CAAC,EAAE,gBAAgB;IAIvC,OAAO,CAAC,SAAS,CAAC,CAAmB;IAErC,IAAI,QAAQ,IAAI,gBAAgB,CAE/B;IAED,IAAI,QAAQ,CAAC,KAAK,EAAE,gBAAgB,EAEnC;IAED,QAAQ,CAAC,OAAO,CACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,eAAe,EACxB,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,SAAS,CAAC;IAErB,gBAAgB,IAAI,MAAM,EAAE;IAC5B,gBAAgB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKrC,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAChD,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;CAWxC"}

26
dist/resolverModule.js vendored Normal file
View File

@ -0,0 +1,26 @@
import { getTld, isPromise } from "./util.js";
// ts-ignore
export class AbstractResolverModule {
constructor(resolver) {
this._resolver = resolver;
}
_resolver;
get resolver() {
return this._resolver;
}
set resolver(value) {
this._resolver = value;
}
getSupportedTlds() {
return [];
}
isTldSupported(domain) {
let supported = this.getSupportedTlds();
if (isPromise(supported)) {
return supported.then((supported) => {
return supported.includes(getTld(domain));
});
}
return supported.includes(getTld(domain));
}
}

25
dist/types.d.ts vendored Normal file
View File

@ -0,0 +1,25 @@
export interface ResolverOptions {
type: string;
customType?: string;
options?: any;
}
export interface DNSResult {
records: DNSRecord[];
error?: Error;
}
export interface DNSRecord {
type: string;
customType?: string;
value: string;
}
declare const DNS_RECORD_TYPE: {
A: string;
CNAME: string;
NS: string;
CONTENT: string;
TEXT: string;
ALL: string;
CUSTOM: string;
};
export { DNS_RECORD_TYPE };
//# sourceMappingURL=types.d.ts.map

1
dist/types.d.ts.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AACD,QAAA,MAAM,eAAe;;;;;;;;CAQpB,CAAC;AAIF,OAAO,EAAE,eAAe,EAAE,CAAC"}

11
dist/types.js vendored Normal file
View File

@ -0,0 +1,11 @@
const DNS_RECORD_TYPE = {
A: "A",
CNAME: "CNAME",
NS: "NS",
CONTENT: "CONTENT",
TEXT: "TEXT",
ALL: "ALL",
CUSTOM: "CUSTOM",
};
Object.freeze(DNS_RECORD_TYPE);
export { DNS_RECORD_TYPE };

12
dist/util.d.ts vendored Normal file
View File

@ -0,0 +1,12 @@
import { DNSRecord, DNSResult } from "./types.js";
export declare function getTld(domain: string): string;
export declare function getSld(domain: string): string;
export declare function isIp(ip: string): boolean;
export declare function isDomain(domain: string): boolean;
export declare function resolverEmptyResponse(): DNSResult;
export declare function resolverError(e: Error | string): DNSResult;
export declare function resolveSuccess(records: DNSRecord[]): DNSResult;
export declare function normalizeDomain(domain: string): string;
export declare function isPromise(obj: Promise<any>): boolean;
export declare function ensureUniqueRecords(records: DNSRecord[]): any[];
//# sourceMappingURL=util.d.ts.map

1
dist/util.d.ts.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAElD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAM7C;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAS7C;AAED,wBAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,WAI9B;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,WAItC;AACD,wBAAgB,qBAAqB,IAAI,SAAS,CAIjD;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,CAQ1D;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,SAAS,CAI9D;AACD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtD;AACD,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,WAM1C;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,EAAE,SAIvD"}

53
dist/util.js vendored Normal file
View File

@ -0,0 +1,53 @@
export function getTld(domain) {
if (domain.includes(".")) {
domain = domain.split(".")[domain.split(".").length - 1];
}
return domain;
}
export function getSld(domain) {
if (domain.includes(".")) {
domain = domain
.split(".")
.slice(0, domain.split(".").length - 1)
.join(".");
}
return domain;
}
export function isIp(ip) {
return /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ip);
}
export function isDomain(domain) {
return /(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]/.test(domain);
}
export function resolverEmptyResponse() {
return {
records: [],
};
}
export function resolverError(e) {
if (!(e instanceof Error)) {
e = new Error(e);
}
return {
records: [],
error: e,
};
}
export function resolveSuccess(records) {
return {
records,
};
}
export function normalizeDomain(domain) {
return domain.replace(/^\.+|\.+$/g, "").replace(/^\/+|\/+$/g, "");
}
export function isPromise(obj) {
return (!!obj &&
(typeof obj === "object" || typeof obj === "function") &&
typeof obj.then === "function");
}
export function ensureUniqueRecords(records) {
return [
...new Set(records.map((item) => JSON.stringify(item))),
].map((item) => JSON.parse(item));
}

19314
npm-shrinkwrap.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,14 @@
{ {
"name": "@lumeweb/libresolver", "name": "@lumeweb/libresolver",
"version": "0.1.0-develop.1", "version": "0.1.0",
"description": "Common code and interfaces for the DNS resolver modules", "description": "Common code and interfaces for the DNS resolver modules",
"main": "lib/index.js", "main": "dist/index.js",
"repository": {
"type": "git",
"url": "gitea@git.lumeweb.com:LumeWeb/libresolver.git"
},
"type": "module", "type": "module",
"devDependencies": { "devDependencies": {
"@lumeweb/node-library-preset": "^0.2.7", "@lumeweb/cfg": "git+https://git.lumeweb.com/LumeWeb/cfg.git",
"presetter": "*" "@lumeweb/relay-types": "git+https://git.lumeweb.com/LumeWeb/relay-types.git",
}, "@types/node": "^18.14.0",
"readme": "ERROR: No README data found!", "node-cache": "^5.1.2",
"scripts": { "typescript": "^4.9.5"
"prepare": "presetter bootstrap",
"build": "run build",
"semantic-release": "semantic-release"
},
"files": [
"lib"
],
"publishConfig": {
"access": "public"
} }
} }

View File

@ -3,33 +3,26 @@ import { getTld, isPromise } from "./util.js";
declare class ResolverRegistry { declare class ResolverRegistry {
get resolvers(): Set<ResolverModule> | Promise<Set<ResolverModule>>; get resolvers(): Set<ResolverModule> | Promise<Set<ResolverModule>>;
resolve( resolve(
domain: string, domain: string,
options?: ResolverOptions, options?: ResolverOptions,
bypassCache?: boolean, bypassCache?: boolean
): Promise<DNSResult>; ): Promise<DNSResult>;
register(resolver: ResolverModule): void; register(resolver: ResolverModule): void;
clear(): void; clear(): void;
} }
export interface ResolverModule { export interface ResolverModule {
get resolver(): ResolverRegistry; get resolver(): ResolverRegistry;
set resolver(value: ResolverRegistry); set resolver(value: ResolverRegistry);
resolve( resolve(
domain: string, domain: string,
options: ResolverOptions, options: ResolverOptions,
bypassCache: boolean, bypassCache: boolean
): Promise<DNSResult>; ): Promise<DNSResult>;
getSupportedTlds(): string[]; getSupportedTlds(): string[];
getSupportedTlds(): Promise<string[]>; getSupportedTlds(): Promise<string[]>;
getSupportedTlds(): any; getSupportedTlds(): any;
} }
@ -52,7 +45,7 @@ export abstract class AbstractResolverModule {
abstract resolve( abstract resolve(
domain: string, domain: string,
options: ResolverOptions, options: ResolverOptions,
bypassCache: boolean, bypassCache: boolean
): Promise<DNSResult>; ): Promise<DNSResult>;
getSupportedTlds(): string[]; getSupportedTlds(): string[];
@ -73,6 +66,4 @@ export abstract class AbstractResolverModule {
return (supported as string[]).includes(getTld(domain)); return (supported as string[]).includes(getTld(domain));
} }
abstract ready(): Promise<void>;
} }

24
tsconfig.json Normal file
View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"declaration": true,
"strict": true,
"module": "esnext",
"target": "esnext",
"esModuleInterop": true,
"sourceMap": false,
"rootDir": "src",
"outDir": "dist",
"typeRoots": [
"node_modules/@types"
],
"moduleResolution": "node",
"declarationMap": true,
"declarationDir": "dist",
"emitDeclarationOnly": false,
"allowJs": true,
"noImplicitAny": false
},
"include": [
"src"
]
}