Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/form encoded #469

Merged
merged 9 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ updates:
# Prefix all commit messages with "npm"
prefix: "auto dependabot"

- package-ecosystem: npm
directory: "/packages/serialization/form"
schedule:
interval: daily
open-pull-requests-limit: 10
commit-message:
# Prefix all commit messages with "npm"
prefix: "auto dependabot"

- package-ecosystem: npm
directory: "/packages/serialization/json"
schedule:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build_test_validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
name: dist folders
path: |
packages/abstractions/dist
packages/serialization/form/dist
packages/serialization/json/dist
packages/serialization/text/dist
packages/http/fetch/dist
Expand Down
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"packages/test",
"packages/abstractions",
"packages/http/*",
"packages/serialization/form/",
"packages/serialization/json/",
"packages/serialization/text/",
"packages/authentication/*"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"packages/test/",
"packages/abstractions",
"packages/http/*",
"packages/serialization/form/",
"packages/serialization/json/",
"packages/serialization/text/",
"packages/authentication/*"
Expand Down
2 changes: 1 addition & 1 deletion packages/abstractions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/kiota-abstractions",
"version": "1.0.0-preview.9",
"version": "1.0.0-preview.10",
"description": "Core abstractions for kiota generated libraries in TypeScript and JavaScript",
"main": "dist/cjs/src/index.js",
"files": [
Expand Down
59 changes: 23 additions & 36 deletions packages/abstractions/src/dateOnly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,13 @@ export class DateOnly implements DateOnlyInterface {
month = 1,
day = 1,
}: Partial<DateOnlyInterface>) {
this.date = new Date(year, month - 1, day);
}
private date: Date;
public get year(): number {
return this.date.getFullYear();
}
public set year(value: number) {
this.date.setFullYear(value);
}
public get month(): number {
return this.date.getMonth() + 1;
}
public set month(value: number) {
this.date.setMonth(value - 1);
}
public get day(): number {
return this.date.getDate();
}
public set day(value: number) {
this.date.setDate(value);
this.day = day;
this.month = month;
this.year = year;
}
public year: number;
public month: number;
public day: number;
/**
* Creates a new DateOnly from the given date.
* @param date The date
Expand All @@ -45,8 +31,11 @@ export class DateOnly implements DateOnlyInterface {
if (!date) {
throw new Error("Date cannot be undefined");
}
const result = new DateOnly({});
result.date = new Date(date);
const result = new DateOnly({
year: date.getFullYear(),
month: date.getMonth() + 1,
day: date.getDate(),
});
return result;
}
/**
Expand All @@ -59,24 +48,22 @@ export class DateOnly implements DateOnlyInterface {
if (!value || value.length === 0) {
return undefined;
}
const exec =
/^(?<year>\d{4,})-(?<month>0[1-9]|1[012])-(?<day>0[1-9]|[12]\d|3[01])$/gi.exec(
value
);
if (exec) {
const year = parseInt(exec.groups?.year ?? "", 10);
const month = parseInt(exec.groups?.month ?? "", 10);
const day = parseInt(exec.groups?.day ?? "", 10);
return new DateOnly({ year, month, day });
}
const ticks = Date.parse(value);
if (isNaN(ticks)) {
const exec =
/^(?<year>\d{4,})-(?<month>0[1-9]|1[012])-(?<day>0[1-9]|[12]\d|3[01])$/gi.exec(
value
);
if (exec) {
const year = parseInt(exec.groups?.year ?? "");
const month = parseInt(exec.groups?.month ?? "");
const day = parseInt(exec.groups?.day ?? "");
return new DateOnly({ year, month, day });
} else {
throw new Error("Value is not a valid date-only representation");
}
} else {
if (!isNaN(ticks)) {
const date = new Date(ticks);
return this.fromDate(date);
}
throw new Error(`Value is not a valid date-only representation: ${value}`);
}
/**
* Returns a string representation of the date in the format YYYY-MM-DD
Expand Down
14 changes: 7 additions & 7 deletions packages/abstractions/src/serialization/parseNode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ParsableFactory } from ".";
import { DateOnly } from "../dateOnly";
import { Duration } from "../duration";
import { TimeOnly } from "../timeOnly";
import { ParsableFactory } from ".";
import { Parsable } from "./parsable";

/**
Expand All @@ -12,33 +12,33 @@ export interface ParseNode {
* Gets the string value of the node.
* @return the string value of the node.
*/
getStringValue(): string;
getStringValue(): string | undefined;
/**
* Gets a new parse node for the given identifier.
* @param identifier the identifier of the current node property.
* @return a new parse node for the given identifier.
*/
getChildNode(identifier: string): ParseNode;
getChildNode(identifier: string): ParseNode | undefined;
/**
* Gets the boolean value of the node.
* @return the boolean value of the node.
*/
getBooleanValue(): boolean;
getBooleanValue(): boolean | undefined;
/**
* Gets the Number value of the node.
* @return the Number value of the node.
*/
getNumberValue(): number;
getNumberValue(): number | undefined;
/**
* Gets the Guid value of the node.
* @return the Guid value of the node.
*/
getGuidValue(): string; //TODO https://www.npmjs.com/package/guid-typescript
getGuidValue(): string | undefined; //TODO https://www.npmjs.com/package/guid-typescript
/**
* Gets the Date value of the node.
* @return the Date value of the node.
*/
getDateValue(): Date;
getDateValue(): Date | undefined;
/**
* Gets the Duration value of the node.
* @return the Duration value of the node.
Expand Down
12 changes: 12 additions & 0 deletions packages/abstractions/test/common/dateOnly.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { assert } from "chai";

import { DateOnly } from "../../src/dateOnly";

describe("DateOnly", () => {
it("parses date only", () => {
const result = DateOnly.parse("2017-09-04");
assert.equal(result?.year, 2017);
assert.equal(result?.month, 9);
assert.equal(result?.day, 4);
});
});
4 changes: 2 additions & 2 deletions packages/authentication/azure/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/kiota-authentication-azure",
"version": "1.0.0-preview.7",
"version": "1.0.0-preview.8",
"description": "Authentication provider for Kiota using Azure Identity",
"main": "dist/cjs/src/index.js",
"module": "dist/es/src/index.js",
Expand Down Expand Up @@ -34,7 +34,7 @@
"homepage": "https://github.com/microsoft/kiota-typescript#readme",
"dependencies": {
"@azure/core-auth": "^1.3.2",
"@microsoft/kiota-abstractions": "^1.0.0-preview.9",
"@microsoft/kiota-abstractions": "^1.0.0-preview.10",
"@opentelemetry/api": "^1.2.0",
"tslib": "^2.3.1"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/authentication/spfx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/kiota-authentication-spfx",
"version": "1.0.0-preview.3",
"version": "1.0.0-preview.4",
"description": "Authentication provider for using Kiota in SPFx solutions",
"main": "dist/cjs/src/index.js",
"module": "dist/es/src/index.js",
Expand Down Expand Up @@ -43,7 +43,7 @@
},
"homepage": "https://github.com/microsoft/kiota-typescript#readme",
"dependencies": {
"@microsoft/kiota-abstractions": "^1.0.0-preview.9",
"@microsoft/kiota-abstractions": "^1.0.0-preview.10",
"@microsoft/sp-http": "^1.15.2",
"@opentelemetry/api": "^1.2.0",
"tslib": "^2.3.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/http/fetch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/kiota-http-fetchlibrary",
"version": "1.0.0-preview.10",
"version": "1.0.0-preview.11",
"description": "Kiota request adapter implementation with fetch",
"keywords": [
"Kiota",
Expand Down Expand Up @@ -43,7 +43,7 @@
"test:cjs": "mocha 'dist/cjs/test/common/**/*.js' && mocha 'dist/cjs/test/node/**/*.js'"
},
"dependencies": {
"@microsoft/kiota-abstractions": "^1.0.0-preview.9",
"@microsoft/kiota-abstractions": "^1.0.0-preview.10",
"@opentelemetry/api": "^1.2.0",
"node-fetch": "^2.6.5",
"tslib": "^2.3.1"
Expand Down
7 changes: 7 additions & 0 deletions packages/serialization/form/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.js
*.js.map
*.d.ts

node_modules
lib
spec/development
Loading