From 4cd64ae55a69746357c2d92f7d245860a2fe03db Mon Sep 17 00:00:00 2001 From: j3lte Date: Thu, 13 Apr 2023 01:00:25 +0200 Subject: [PATCH] Update structures --- src/Field.ts | 2 +- src/Query.ts | 11 ++++-- src/Select.ts | 2 +- src/SelectImpl.ts | 2 +- src/Where.ts | 5 ++- src/enums.ts | 35 ------------------- src/interfaces.ts | 48 ------------------------- src/mod.ts | 5 ++- src/types.ts | 85 ++++++++++++++++++++++++++++++++++++++++++++- test/Field.test.ts | 5 ++- test/Query.test.ts | 3 +- test/Select.test.ts | 3 +- 12 files changed, 110 insertions(+), 96 deletions(-) delete mode 100644 src/enums.ts delete mode 100644 src/interfaces.ts diff --git a/src/Field.ts b/src/Field.ts index e4d1d7b..ab4bdb4 100644 --- a/src/Field.ts +++ b/src/Field.ts @@ -1,4 +1,4 @@ -import { DataType } from "./enums.ts"; +import { DataType } from "./types.ts"; import type { Field, FieldImpl } from "./types.ts"; export const testFieldImpl = (field: FieldImpl | null, ...types: DataType[]): boolean => diff --git a/src/Query.ts b/src/Query.ts index c3c27f0..0801e7f 100644 --- a/src/Query.ts +++ b/src/Query.ts @@ -1,5 +1,12 @@ -import type { AuthOpts, ExtraDataFields, Options, RequesOpts } from "./interfaces.ts"; -import type { DataResponse, FieldImpl, QueryObj } from "./types.ts"; +import type { + AuthOpts, + DataResponse, + ExtraDataFields, + FieldImpl, + Options, + QueryObj, + RequesOpts, +} from "./types.ts"; import { Where } from "./Where.ts"; import { toQS } from "./utils/qs.ts"; diff --git a/src/Select.ts b/src/Select.ts index aa31609..25ef973 100644 --- a/src/Select.ts +++ b/src/Select.ts @@ -1,5 +1,5 @@ import type { Field, FieldImpl } from "./types.ts"; -import { DataType } from "./enums.ts"; +import { DataType } from "./types.ts"; import { getFieldName, testFieldImpl } from "./Field.ts"; import { SelectFunction, SelectImpl } from "./SelectImpl.ts"; diff --git a/src/SelectImpl.ts b/src/SelectImpl.ts index b5d78e9..db1f369 100644 --- a/src/SelectImpl.ts +++ b/src/SelectImpl.ts @@ -1,6 +1,6 @@ import type { FieldImpl } from "./types.ts"; import { testFieldImpl } from "./Field.ts"; -import { DataType } from "./enums.ts"; +import { DataType } from "./types.ts"; export enum SelectFunction { Abs = "abs", diff --git a/src/Where.ts b/src/Where.ts index 65b390e..5682e4b 100644 --- a/src/Where.ts +++ b/src/Where.ts @@ -1,8 +1,11 @@ // TODO(@j3lte) - Fix the 'any' types in this file // deno-lint-ignore-file no-explicit-any +import type { Field, FieldImpl } from "./types.ts"; + import { replaceParams, SupportTypeElement } from "./utils/param.ts"; -import { DataType, Field, FieldImpl, getFieldName } from "./Field.ts"; +import { getFieldName } from "./Field.ts"; +import { DataType } from "./types.ts"; type BasicType = Exclude; diff --git a/src/enums.ts b/src/enums.ts deleted file mode 100644 index 4c0dd21..0000000 --- a/src/enums.ts +++ /dev/null @@ -1,35 +0,0 @@ -/** - * The different types of data that can be used in a field - */ -export enum DataType { - /** Type: **Checkbox**, available in 2.0 and 2.1 */ - Checkbox = "checkbox", - /** Type: **Fixed Timestamp**, available in 2.0 and 2.1 */ - FixedTimestamp = "fixed_timestamp", - /** Type: **Floating Timestamp**, available in 2.0 and 2.1 */ - FloatingTimestamp = "floating_timestamp", - /** Type: **Line**, available in 2.1 */ - Line = "line", - /** Type: **Location**, available in 2.0 and 2.1 */ - Location = "location", - /** Type: **MultiLine**, available in 2.1 */ - MultiLine = "multiline", - /** Type: **MultiPoint**, available in 2.1 */ - MultiPoint = "multipoint", - /** Type: **MultiPolygon**, available in 2.1 */ - MultiPolygon = "multipolygon", - /** Type: **Number**, available in 2.0 and 2.1 */ - Number = "number", - /** Type: **Point**, available in 2.1 */ - Point = "point", - /** Type: **Polygon**, available in 2.1 */ - Polygon = "polygon", - /** Type: **Text**, available in 2.0 and 2.1 */ - Text = "text", - /** Type: **URL**, available in 2.0 and 2.1 */ - URL = "url", - /** Type: **ROW Identifier**, special tag that is only used when retrieving IDs. Don't use */ - RowIdentifier = "row_identifier", - /** Type: **Unknown** */ - _Unknown = "_unknown", -} diff --git a/src/interfaces.ts b/src/interfaces.ts deleted file mode 100644 index 7d43685..0000000 --- a/src/interfaces.ts +++ /dev/null @@ -1,48 +0,0 @@ -export interface Options { - /** Strict mode. If enabled, this prevents the Query from changing the dataset ID after it has been set once */ - strict?: boolean; -} - -export interface RequesOpts { - method?: string; -} - -export interface ExtraDataFields { - /** System field */ - ":id"?: string; - /** System field */ - ":created_at"?: string; - /** System field */ - ":updated_at"?: string; -} - -export interface AuthOpts { - /** - * API token - * - * The Socrata Open Data API uses application tokens for two purposes: - * Using an application token allows us to throttle by application, rather than via IP address, which gives you a higher throttling limit - * Authentication using OAuth - * - * Docs: https://dev.socrata.com/docs/app-tokens.html - */ - apiToken?: string; - /** - * Username (needs password) for Basic HTTP Auth - * - * Docs: https://dev.socrata.com/docs/authentication.html#authenticating-using-http-basic-authentication - */ - username?: string; - /** - * Password (needs username) for Basic HTTP Auth - * - * Docs: https://dev.socrata.com/docs/authentication.html#authenticating-using-http-basic-authentication - */ - password?: string; - /** - * OAuth Access Token - * - * Docs: https://dev.socrata.com/docs/authentication.html#using-an-oauth-20-access-token - */ - accessToken?: string; -} diff --git a/src/mod.ts b/src/mod.ts index 0b933a9..cc95ad0 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -1,6 +1,5 @@ -export type { DataResponse, Field, FieldImpl, QueryObj } from "./types.ts"; -export type { AuthOpts, Options } from "./interfaces.ts"; -export { DataType } from "./enums.ts"; +export type { AuthOpts, DataResponse, Field, FieldImpl, Options, QueryObj } from "./types.ts"; +export { DataType } from "./types.ts"; export { createQueryWithDataset, SodaQuery } from "./Query.ts"; diff --git a/src/types.ts b/src/types.ts index 01934ef..4099f8b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,87 @@ -import { DataType } from "./enums.ts"; +/** + * The different types of data that can be used in a field + */ +export enum DataType { + /** Type: **Checkbox**, available in 2.0 and 2.1 */ + Checkbox = "checkbox", + /** Type: **Fixed Timestamp**, available in 2.0 and 2.1 */ + FixedTimestamp = "fixed_timestamp", + /** Type: **Floating Timestamp**, available in 2.0 and 2.1 */ + FloatingTimestamp = "floating_timestamp", + /** Type: **Line**, available in 2.1 */ + Line = "line", + /** Type: **Location**, available in 2.0 and 2.1 */ + Location = "location", + /** Type: **MultiLine**, available in 2.1 */ + MultiLine = "multiline", + /** Type: **MultiPoint**, available in 2.1 */ + MultiPoint = "multipoint", + /** Type: **MultiPolygon**, available in 2.1 */ + MultiPolygon = "multipolygon", + /** Type: **Number**, available in 2.0 and 2.1 */ + Number = "number", + /** Type: **Point**, available in 2.1 */ + Point = "point", + /** Type: **Polygon**, available in 2.1 */ + Polygon = "polygon", + /** Type: **Text**, available in 2.0 and 2.1 */ + Text = "text", + /** Type: **URL**, available in 2.0 and 2.1 */ + URL = "url", + /** Type: **ROW Identifier**, special tag that is only used when retrieving IDs. Don't use */ + RowIdentifier = "row_identifier", + /** Type: **Unknown** */ + _Unknown = "_unknown", +} + +export interface Options { + /** Strict mode. If enabled, this prevents the Query from changing the dataset ID after it has been set once */ + strict?: boolean; +} + +export interface RequesOpts { + method?: string; +} + +export interface ExtraDataFields { + /** System field */ + ":id"?: string; + /** System field */ + ":created_at"?: string; + /** System field */ + ":updated_at"?: string; +} + +export interface AuthOpts { + /** + * API token + * + * The Socrata Open Data API uses application tokens for two purposes: + * Using an application token allows us to throttle by application, rather than via IP address, which gives you a higher throttling limit + * Authentication using OAuth + * + * Docs: https://dev.socrata.com/docs/app-tokens.html + */ + apiToken?: string; + /** + * Username (needs password) for Basic HTTP Auth + * + * Docs: https://dev.socrata.com/docs/authentication.html#authenticating-using-http-basic-authentication + */ + username?: string; + /** + * Password (needs username) for Basic HTTP Auth + * + * Docs: https://dev.socrata.com/docs/authentication.html#authenticating-using-http-basic-authentication + */ + password?: string; + /** + * OAuth Access Token + * + * Docs: https://dev.socrata.com/docs/authentication.html#using-an-oauth-20-access-token + */ + accessToken?: string; +} export type Field = { name: string; diff --git a/test/Field.test.ts b/test/Field.test.ts index 838b9cf..ccdb42e 100644 --- a/test/Field.test.ts +++ b/test/Field.test.ts @@ -1,5 +1,8 @@ +import type { Field } from "../src/types.ts"; + import { assertEquals } from "../dev_deps.ts"; -import { DataType, Field, getFieldName, testFieldImpl } from "../src/Field.ts"; +import { getFieldName, testFieldImpl } from "../src/Field.ts"; +import { DataType } from "../src/types.ts"; Deno.test("(Field.)testFieldImpl", () => { const field: Field = { diff --git a/test/Query.test.ts b/test/Query.test.ts index efcad6c..e7b0127 100644 --- a/test/Query.test.ts +++ b/test/Query.test.ts @@ -1,8 +1,9 @@ import { assertEquals, assertNotEquals, assertThrows } from "../dev_deps.ts"; import { mockFetch, unMockFetch } from "./util.ts"; -import { AuthOpts, createQueryWithDataset, SodaQuery } from "../src/Query.ts"; +import { createQueryWithDataset, SodaQuery } from "../src/Query.ts"; import { Order } from "../src/Order.ts"; import { Where } from "../src/Where.ts"; +import type { AuthOpts } from "../src/types.ts"; const createSampleQuery = (authOpts?: AuthOpts) => createQueryWithDataset("test.example.com", "test", authOpts); diff --git a/test/Select.test.ts b/test/Select.test.ts index 736bcf9..18f3edf 100644 --- a/test/Select.test.ts +++ b/test/Select.test.ts @@ -8,7 +8,8 @@ import { SelectRegrR2, SelectRegrSlope, } from "../src/Select.ts"; -import { DataType, Field } from "../src/Field.ts"; +import { DataType } from "../src/types.ts"; +import type { Field } from "../src/types.ts"; const createField = (type: T, name = "test"): Field => ({