Skip to content

Commit

Permalink
Update structures
Browse files Browse the repository at this point in the history
  • Loading branch information
j3lte committed Apr 12, 2023
1 parent 2e2ba10 commit 4cd64ae
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 96 deletions.
2 changes: 1 addition & 1 deletion src/Field.ts
Original file line number Diff line number Diff line change
@@ -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 =>
Expand Down
11 changes: 9 additions & 2 deletions src/Query.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/Select.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/SelectImpl.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 4 additions & 1 deletion src/Where.ts
Original file line number Diff line number Diff line change
@@ -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<SupportTypeElement, null | undefined | boolean>;

Expand Down
35 changes: 0 additions & 35 deletions src/enums.ts

This file was deleted.

48 changes: 0 additions & 48 deletions src/interfaces.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/mod.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
85 changes: 84 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -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<T> = {
name: string;
Expand Down
5 changes: 4 additions & 1 deletion test/Field.test.ts
Original file line number Diff line number Diff line change
@@ -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<DataType.Checkbox> = {
Expand Down
3 changes: 2 additions & 1 deletion test/Query.test.ts
Original file line number Diff line number Diff line change
@@ -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 = <T>(authOpts?: AuthOpts) =>
createQueryWithDataset<T>("test.example.com", "test", authOpts);
Expand Down
3 changes: 2 additions & 1 deletion test/Select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <T>(type: T, name = "test"): Field<T> =>
({
Expand Down

0 comments on commit 4cd64ae

Please sign in to comment.